MCPcopy Create free account
hub / github.com/DavidHDev/react-bits / render

Function render

src/tailwind/Components/DecayCard/DecayCard.jsx:42–83  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

40 };
41
42 const render = () => {
43 let targetX = lerp(imgValues.imgTransforms.x, map(cursor.current.x, 0, winsize.current.width, -120, 120), 0.1);
44 let targetY = lerp(imgValues.imgTransforms.y, map(cursor.current.y, 0, winsize.current.height, -120, 120), 0.1);
45 let targetRz = lerp(imgValues.imgTransforms.rz, map(cursor.current.x, 0, winsize.current.width, -10, 10), 0.1);
46
47 if (targetX > movementBound) targetX = movementBound + (targetX - movementBound) * 0.2;
48 if (targetX < -movementBound) targetX = -movementBound + (targetX + movementBound) * 0.2;
49 if (targetY > movementBound) targetY = movementBound + (targetY - movementBound) * 0.2;
50 if (targetY < -movementBound) targetY = -movementBound + (targetY + movementBound) * 0.2;
51
52 imgValues.imgTransforms.x = targetX;
53 imgValues.imgTransforms.y = targetY;
54 imgValues.imgTransforms.rz = targetRz;
55
56 if (svgRef.current) {
57 gsap.set(svgRef.current, {
58 x: imgValues.imgTransforms.x,
59 y: imgValues.imgTransforms.y,
60 rotateZ: imgValues.imgTransforms.rz
61 });
62 }
63
64 const cursorTravelledDistance = distance(
65 cachedCursor.current.x,
66 cursor.current.x,
67 cachedCursor.current.y,
68 cursor.current.y
69 );
70 imgValues.displacementScale = lerp(
71 imgValues.displacementScale,
72 map(cursorTravelledDistance, 0, 200, 0, maxDisplacement),
73 0.06
74 );
75
76 if (displacementMapRef.current) {
77 gsap.set(displacementMapRef.current, { attr: { scale: imgValues.displacementScale } });
78 }
79
80 cachedCursor.current = { ...cursor.current };
81
82 rafId = requestAnimationFrame(render);
83 };
84
85 let rafId = requestAnimationFrame(render);
86

Callers

nothing calls this directly

Calls 3

lerpFunction · 0.70
mapFunction · 0.70
distanceFunction · 0.70

Tested by

no test coverage detected