← back to Model Arena
data/artifacts/0cb3fc06b069/hf-qwen-coder-32b.html
105 lines
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Particle Text</title>
<style>
body { margin: 0; overflow: hidden; background-color: #000; display: flex; justify-content: center; align-items: center; height: 100vh; }
canvas { display: block; }
</style>
</head>
<body>
<canvas id="c"></canvas>
<script>
const canvas = document.getElementById('c');
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
const text = "HELLO";
const fontSize = 50;
ctx.font = `${fontSize}px Arial`;
const textWidth = ctx.measureText(text).width;
const particles = [];
class Particle {
constructor(x, y) {
this.x = x;
this.y = y;
this.size = Math.random() * 2 + 1;
this.baseX = x;
this.baseY = y;
this.density = (Math.random() * 40) + 5;
}
draw() {
ctx.fillStyle = 'white';
ctx.beginPath();
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
ctx.closePath();
ctx.fill();
}
update(mouse) {
const dx = mouse.x - this.x;
const dy = mouse.y - this.y;
const distance = Math.sqrt(dx * dx + dy * dy);
let forceDirectionX = dx / distance;
let forceDirectionY = dy / distance;
const maxDistance = 100;
const force = (maxDistance - distance) / maxDistance;
const directionX = forceDirectionX * force * this.density;
const directionY = forceDirectionY * force * this.density;
if (distance < maxDistance) {
this.x -= directionX;
this.y -= directionY;
} else {
if (this.x !== this.baseX) {
let dx = this.x - this.baseX;
this.x -= dx / 10;
}
if (this.y !== this.baseY) {
let dy = this.y - this.baseY;
this.y -= dy / 10;
}
}
}
}
function init() {
particles.length = 0;
ctx.font = `${fontSize}px Arial`;
const textWidth = ctx.measureText(text).width;
ctx.fillText(text, canvas.width/2 - textWidth/2, canvas.height/2);
const data = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
for (let y = 0; y < canvas.height; y++) {
for (let x = 0; x < canvas.width; x++) {
if (data[(y * 4 * canvas.width) + (x * 4) + 3] > 128) {
particles.push(new Particle(x, y));
}
}
}
}
function animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (let i = 0; i < particles.length; i++) {
particles[i].draw();
particles[i].update(mouse);
}
requestAnimationFrame(animate);
}
const mouse = { x: undefined, y: undefined };
window.addEventListener('mousemove', function(e) {
mouse.x = e.x;
mouse.y = e.y;
});
init();
animate();
window.onresize = () => {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
init();
};
</script>
</body>
</html>