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

Function render

src/content/Components/DecayCard/DecayCard.jsx:50–91  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

lerpFunction · 0.70
mapFunction · 0.70
distanceFunction · 0.70

Tested by

no test coverage detected