Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions src/ts-default/Backgrounds/AcidSquares/AcidSquares.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@ const AcidSquares: React.FC<AcidSquaresProps> = ({
const pu = postProgram.uniforms as Record<string, { value: any }>;
const mu = program.uniforms as Record<string, { value: any }>;

let rtA: InstanceType<typeof RenderTarget> | null = null;
let rtB: InstanceType<typeof RenderTarget> | null = null;
const ensureTargets = () => {
if (!rtA) {
let rtA: InstanceType<typeof RenderTarget> | undefined;
let rtB: InstanceType<typeof RenderTarget> | undefined;
const ensureTargets = (): void => {
if (!rtA || !rtB) {
const bw = gl.drawingBufferWidth;
const bh = gl.drawingBufferHeight;
rtA = new RenderTarget(gl, { width: bw, height: bh, depth: false });
Expand All @@ -294,15 +294,18 @@ const AcidSquares: React.FC<AcidSquaresProps> = ({
postProgram.uniforms.uGrainIntensity.value = grainAmt;
if (blurRef.current > 0) {
ensureTargets();
const targetA = rtA;
const targetB = rtB;
if (!targetA || !targetB) return;
mu.uGrain.value = 0.0;
renderer.render({ scene: mesh, target: rtA });
renderer.render({ scene: mesh, target: targetA });
pu.uRadius.value = blurRef.current * 14.0;
pu.tMap.value = rtA!.texture;
pu.tMap.value = targetA.texture;
pu.uDirection.value[0] = 1;
pu.uDirection.value[1] = 0;
pu.uGrain.value = 0.0;
renderer.render({ scene: postMesh, target: rtB });
pu.tMap.value = rtB!.texture;
renderer.render({ scene: postMesh, target: targetB });
pu.tMap.value = targetB.texture;
pu.uDirection.value[0] = 0;
pu.uDirection.value[1] = 1;
pu.uGrain.value = grainOn;
Expand Down Expand Up @@ -330,7 +333,9 @@ const AcidSquares: React.FC<AcidSquaresProps> = ({
pres[1] = bh;
if (rtA) {
rtA.setSize(bw, bh);
rtB!.setSize(bw, bh);
}
if (rtB) {
rtB.setSize(bw, bh);
}
renderFrame();
};
Expand Down Expand Up @@ -415,9 +420,11 @@ const AcidSquares: React.FC<AcidSquaresProps> = ({
ctxMap.delete(container);
if (rtA) {
gl.deleteFramebuffer(rtA.buffer);
gl.deleteFramebuffer(rtB!.buffer);
rtA.textures.forEach(tex => gl.deleteTexture(tex.texture));
rtB!.textures.forEach(tex => gl.deleteTexture(tex.texture));
}
if (rtB) {
gl.deleteFramebuffer(rtB.buffer);
rtB.textures.forEach(tex => gl.deleteTexture(tex.texture));
}
try {
container.removeChild(canvas);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ const SpecularButton = ({

idleAngle += p.speed * dt;
const steer = p.followMouse && pointerAngle != null && (!p.autoAnimate || proximityT > 0);
const target = steer ? pointerAngle : idleAngle;
const target = steer && pointerAngle !== null ? pointerAngle : idleAngle;
const diff = ((target - angle + Math.PI * 3) % (Math.PI * 2)) - Math.PI;
angle += diff * (1 - Math.exp(-dt * 7));

Expand Down
9 changes: 6 additions & 3 deletions src/ts-default/TextAnimations/SplitText/SplitText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ const SplitText: React.FC<SplitTextProps> = ({
tag = 'p',
onLetterAnimationComplete
}) => {
const ref = useRef<HTMLParagraphElement>(null);
const ref = useRef<HTMLElement>(null);
const setRef = React.useCallback((node: HTMLElement | null) => {
ref.current = node;
}, []);
const animationCompletedRef = useRef(false);
const onCompleteRef = useRef(onLetterAnimationComplete);
const [fontsLoaded, setFontsLoaded] = useState<boolean>(false);
Expand Down Expand Up @@ -165,10 +168,10 @@ const SplitText: React.FC<SplitTextProps> = ({
willChange: 'transform, opacity'
};
const classes = `split-parent ${className}`;
const Tag = (tag || 'p') as React.ElementType;
const Tag = tag || 'p';

return (
<Tag ref={ref} style={style} className={classes}>
<Tag ref={setRef} style={style} className={classes}>
{text}
</Tag>
);
Expand Down
29 changes: 18 additions & 11 deletions src/ts-tailwind/Backgrounds/AcidSquares/AcidSquares.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ const AcidSquares: React.FC<AcidSquaresProps> = ({
const pu = postProgram.uniforms as Record<string, { value: any }>;
const mu = program.uniforms as Record<string, { value: any }>;

let rtA: InstanceType<typeof RenderTarget> | null = null;
let rtB: InstanceType<typeof RenderTarget> | null = null;
const ensureTargets = () => {
if (!rtA) {
let rtA: InstanceType<typeof RenderTarget> | undefined;
let rtB: InstanceType<typeof RenderTarget> | undefined;
const ensureTargets = (): void => {
if (!rtA || !rtB) {
const bw = gl.drawingBufferWidth;
const bh = gl.drawingBufferHeight;
rtA = new RenderTarget(gl, { width: bw, height: bh, depth: false });
Expand All @@ -293,15 +293,18 @@ const AcidSquares: React.FC<AcidSquaresProps> = ({
postProgram.uniforms.uGrainIntensity.value = grainAmt;
if (blurRef.current > 0) {
ensureTargets();
const targetA = rtA;
const targetB = rtB;
if (!targetA || !targetB) return;
mu.uGrain.value = 0.0;
renderer.render({ scene: mesh, target: rtA });
renderer.render({ scene: mesh, target: targetA });
pu.uRadius.value = blurRef.current * 14.0;
pu.tMap.value = rtA!.texture;
pu.tMap.value = targetA.texture;
pu.uDirection.value[0] = 1;
pu.uDirection.value[1] = 0;
pu.uGrain.value = 0.0;
renderer.render({ scene: postMesh, target: rtB });
pu.tMap.value = rtB!.texture;
renderer.render({ scene: postMesh, target: targetB });
pu.tMap.value = targetB.texture;
pu.uDirection.value[0] = 0;
pu.uDirection.value[1] = 1;
pu.uGrain.value = grainOn;
Expand Down Expand Up @@ -329,7 +332,9 @@ const AcidSquares: React.FC<AcidSquaresProps> = ({
pres[1] = bh;
if (rtA) {
rtA.setSize(bw, bh);
rtB!.setSize(bw, bh);
}
if (rtB) {
rtB.setSize(bw, bh);
}
renderFrame();
};
Expand Down Expand Up @@ -414,9 +419,11 @@ const AcidSquares: React.FC<AcidSquaresProps> = ({
ctxMap.delete(container);
if (rtA) {
gl.deleteFramebuffer(rtA.buffer);
gl.deleteFramebuffer(rtB!.buffer);
rtA.textures.forEach(tex => gl.deleteTexture(tex.texture));
rtB!.textures.forEach(tex => gl.deleteTexture(tex.texture));
}
if (rtB) {
gl.deleteFramebuffer(rtB.buffer);
rtB.textures.forEach(tex => gl.deleteTexture(tex.texture));
}
try {
container.removeChild(canvas);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ const SpecularButton = ({

idleAngle += p.speed * dt;
const steer = p.followMouse && pointerAngle != null && (!p.autoAnimate || proximityT > 0);
const target = steer ? pointerAngle : idleAngle;
const target = steer && pointerAngle !== null ? pointerAngle : idleAngle;
const diff = ((target - angle + Math.PI * 3) % (Math.PI * 2)) - Math.PI;
angle += diff * (1 - Math.exp(-dt * 7));

Expand Down
9 changes: 6 additions & 3 deletions src/ts-tailwind/TextAnimations/SplitText/SplitText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ const SplitText: React.FC<SplitTextProps> = ({
textAlign = 'center',
onLetterAnimationComplete
}) => {
const ref = useRef<HTMLParagraphElement>(null);
const ref = useRef<HTMLElement>(null);
const setRef = React.useCallback((node: HTMLElement | null) => {
ref.current = node;
}, []);
const animationCompletedRef = useRef(false);
const onCompleteRef = useRef(onLetterAnimationComplete);
const [fontsLoaded, setFontsLoaded] = useState<boolean>(false);
Expand Down Expand Up @@ -162,10 +165,10 @@ const SplitText: React.FC<SplitTextProps> = ({
willChange: 'transform, opacity'
};
const classes = `split-parent overflow-hidden inline-block whitespace-normal ${className}`;
const Tag = (tag || 'p') as React.ElementType;
const Tag = tag || 'p';

return (
<Tag ref={ref} style={style} className={classes}>
<Tag ref={setRef} style={style} className={classes}>
{text}
</Tag>
);
Expand Down