Smoke Card
Smoke Card is a React and Tailwind CSS effect component written for NedDev and yours to ship. Copy it and paste it into your project.
NedDev
effects
What it is
Smoke Card is a React and Tailwind CSS effect component written for NedDev and yours to ship. Copy it and paste it into your project.
How to use it
Open it in the catalogue, press copy, and paste it into your project. The prompt you copy carries the code and the rules that tell your agent to reproduce it without changing anything.
Four free copies a week. No card.
No packages beyond the project baseline
Licence
This component was written for this catalogue. It is yours to ship in client work and in products you sell, under the terms of use.
Smoke Card
"use client"
import React, { useEffect, useRef } from 'react';
class Particle {
x: number;
y: number;
size: number;
speedX: number;
speedY: number;
life: number;
initialSize: number;
constructor(x: number, y: number) {
this.x = x;
this.y = y;
this.size = Math.random() * 5 + 2;
this.speedX = Math.random() * 2 - 1;
this.speedY = -Math.random() * 3 - 1;
this.life = 100;
this.initialSize = this.size;
}
update() {
this.x += this.speedX;
this.y += this.speedY;
this.life -= 1;
this.size = Math.max(0, this.initialSize * (this.life / 100));
}
}
const SmokeCard = () => {
const canvasRef = useRef<HTMLCanvasElement>(null);
const particlesRef = useRef<Particle[]>([]);
const mousePosRef = useRef({ x: 0, y: 0 });
const animationFrameRef = useRef<number>();
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas) return;
const ctx = canvas.getContext('2d');
if (!ctx) return;
const animate = () => {
ctx.clearRect(0, 0, canvas.width, canvas.height);
particlesRef.current = particlesRef.current
.filter(particle => particle.life > 0 && particle.size > 0)
.map(particle => {
particle.update();
if (particle.size > 0) {
const opacity = particle.life / 100;
ctx.fillStyle = `rgba(128, 128, 128, ${opacity})`;
ctx.beginPath();
ctx.arc(particle.x, particle.y, particle.size, 0, Math.PI * 2);
ctx.fill();
}
return particle;
});
if (mousePosRef.current.x !== 0 && mousePosRef.current.y !== 0) {
for (let i = 0; i < 2; i++) {
particlesRef.current.push(
new Particle(
mousePosRef.current.x + (Math.random() * 10 - 5),
mousePosRef.current.y + (Math.random() * 10 - 5)
)
);
}
}
animationFrameRef.current = requestAnimationFrame(animate);
};
const updateCanvasSize = () => {
const rect = canvas.getBoundingClientRect();
canvas.width = rect.width;
canvas.height = rect.height;
};
updateCanvasSize();
window.addEventListener('resize', updateCanvasSize);
animate();
return () => {
window.removeEventListener('resize', updateCanvasSize);
if (animationFrameRef.current) {
cancelAnimationFrame(animationFrameRef.current);
}
};
}, []);
const handleMouseMove = (e: React.MouseEvent<HTMLCanvasElement>) => {
const rect = canvasRef.current?.getBoundingClientRect();
if (!rect) return;
mousePosRef.current = {
x: e.clientX - rect.left,
y: e.clientY - rect.top
};
};
const handleMouseLeave = () => {
mousePosRef.current = { x: 0, y: 0 };
};
return (
<div className="w-96 h-96 relative overflow-hidden bg-black rounded-lg border border-white/10">
<canvas
ref={canvasRef}
onMouseMove={handleMouseMove}
onMouseLeave={handleMouseLeave}
className="absolute top-0 left-0 w-full h-full cursor-none"
/>
</div>
);
};
export { SmokeCard };