Pixelated Canvas
- Source
- Aceternity UI ↗
- Author
- Aceternity UI
- Licence
- Aceternity UI licence (free component)
Loading…
An image redrawn as dots that swirl and jitter around the pointer.
Code
"use client";
import { useEffect, useRef, useState } from "react";
import { PixelatedCanvas } from "@/lab/aceternity/ui/pixelated-canvas";
export default function PixelatedCanvasDemo() {
const boxRef = useRef<HTMLDivElement>(null);
const [size, setSize] = useState<{ width: number; height: number } | null>(null);
useEffect(() => {
const el = boxRef.current;
if (!el) return;
const ro = new ResizeObserver(([entry]) => {
const { width: cw, height: ch } = entry.contentRect;
// Original is 400×500 (4:5). Fit it inside the stage, snapped to 10px to avoid thrashing.
let height = Math.min(ch * 0.88, 500);
let width = height * 0.8;
if (width > cw * 0.9) {
width = cw * 0.9;
height = width / 0.8;
}
const next = { width: Math.max(80, Math.round(width / 10) * 10), height: Math.max(100, Math.round(height / 10) * 10) };
setSize((prev) => (prev && prev.width === next.width && prev.height === next.height ? prev : next));
});
ro.observe(el);
return () => ro.disconnect();
}, []);
return (
<div ref={boxRef} className="relative flex h-full w-full items-center justify-center overflow-hidden bg-neutral-950">
{size && (
<PixelatedCanvas
src="https://assets.aceternity.com/manu-red.png"
width={size.width}
height={size.height}
cellSize={3}
dotScale={0.9}
shape="square"
backgroundColor="#000000"
dropoutStrength={0.4}
interactive
distortionStrength={3}
distortionRadius={80}
distortionMode="swirl"
followSpeed={0.2}
jitterStrength={4}
jitterSpeed={4}
sampleAverage
tintColor="#FFFFFF"
tintStrength={0.2}
className="rounded-xl border border-neutral-800 shadow-lg"
/>
)}
</div>
);
}
Prompt
Build "Pixelated Canvas", a canvas animation. What it does: An image redrawn as dots that swirl and jitter around the pointer. Write it as a single self-contained React component in TypeScript that fills its parent (w-full h-full), styled with Tailwind CSS. Technique: an HTML canvas, a requestAnimationFrame loop, pointer tracking. It sits on a dark background, in a 16:10 frame. Respect prefers-reduced-motion with a still state, pause work when the element is off screen, and keep it accessible. Original: https://ui.aceternity.com/components/pixelated-canvas (Aceternity UI, Aceternity UI licence (free component)).