This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*------------------------------ | |
ADD GSAP | |
------------------------------*/ | |
const script = document.createElement('script') | |
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js' | |
script.onload = () => { | |
console.log('GSAP loaded') | |
} | |
document.head.appendChild(script) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect } from 'react' | |
import { useThree } from '@react-three/fiber' | |
import { MathUtils } from 'three' | |
const isPercentage = (num) => typeof num === 'string' && num.includes('%') | |
const calculatePosition = (side, value, size, viewport, length) => { | |
const { mapLinear } = MathUtils | |
const inverse = side === 'right' || side === 'top' ? -1 : 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useGLTF, Instances, Instance } from '@react-three/drei' | |
import { MathUtils } from 'three' | |
const InstancedMesh = () => { | |
const { nodes } = useGLTF('./model.glb') | |
const randomVector = (r) => | |
Array(3) | |
.fill() | |
.map(() => MathUtils.randFloatSpread(r)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uniform sampler2D textureMap; //image | |
uniform float amount; //amount of twirl | |
void main() { | |
vec2 uv = gl_TexCoord[0].st-0.5; | |
float angle = atan2(uv.y,uv.x); | |
float radius = length(uv); | |
angle+= radius*amount; | |
vec2 shifted = radius*vec2(cos(angle), sin(angle)); | |
gl_FragColor = texture(textureMap, (shifted+0.5)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Vertex shader */ | |
vNormal = normalize(vec3(world * vec4(normal, 0.0))); // Normal in model | |
/* Fragment shader */ | |
// Move normal to view space | |
highp vec2 muv = vec2(view * vec4(normalize(vNormal), 0))*0.5+vec2(0.5,0.5); | |
// read texture inverting Y value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { mergeUniforms } from 'three/src/renderers/shaders/UniformsUtils.js' | |
import { UniformsLib } from 'three/src/renderers/shaders/UniformsLib.js' | |
export default { | |
uniforms: mergeUniforms([ | |
UniformsLib.lights, | |
UniformsLib.fog, | |
]), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*------------------------------ | |
Extract first frame from video | |
------------------------------*/ | |
ffmpeg -i input.mov -vf "select=eq(n\,0)" -q:v 3 output.jpg | |
/*------------------------------ | |
Convert video optimized for web | |
------------------------------*/ | |
ffmpeg -i input.mov -c:v libx264 -preset veryslow -pix_fmt yuv420p output.mp4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*------------------------------ | |
Background Cover UV | |
-------------------------------- | |
u = basic UV | |
s = screensize | |
i = image size | |
------------------------------*/ | |
vec2 CoverUV(vec2 u, vec2 s, vec2 i) { | |
float rs = s.x / s.y; // Aspect screen size | |
float ri = i.x / i.y; // Aspect image size |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getClosestDiffInArray = (length, curr, next) => { | |
const inside = curr > next ? -(curr - next) : next - curr | |
const outside = curr > next ? length - curr + next : -(length - next + curr) | |
return Math.abs(inside) < Math.abs(outside) ? inside : outside | |
} | |
console.log('return', getClosestDiffInArray(12, 11, 2)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MyComponent = ({ items }) => { | |
const $items = useRef(items.map(createRef)) | |
useEffect(() => { | |
console.log($items.current[0].current) | |
}, []) | |
return ( | |
{items.map((item, index) => ( | |
<div |
NewerOlder