← back to Model Arena

data/artifacts/0cb3fc06b069/qwen25-7b.html

99 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 {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #222;
            margin: 0;
            overflow: hidden;
        }
        canvas {
            border: 1px solid #fff;
        }
    </style>
</head>
<body>
    <canvas id="particleCanvas" width="800" height="400"></canvas>
    <script>
        const canvas = document.getElementById('particleCanvas');
        const ctx = canvas.getContext('2d');
        let particles = [];

        function Particle(x, y, dx, dy, size) {
            this.x = x;
            this.y = y;
            this.dx = dx;
            this.dy = dy;
            this.size = size;
        }

        Particle.prototype.update = function() {
            this.x += this.dx;
            this.y += this.dy;

            if (this.x < 0 || this.x > canvas.width) {
                this.dx *= -1;
            }
            if (this.y < 0 || this.y > canvas.height) {
                this.dy *= -1;
            }

            this.size -= 0.1;
        };

        Particle.prototype.draw = function() {
            ctx.beginPath();
            ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
            ctx.fillStyle = 'rgba(255, 255, 255, 0.8)';
            ctx.fill();
        };

        function initParticles(word) {
            for (let i = 0; i < word.length * 100; i++) {
                let x = Math.random() * canvas.width;
                let y = -canvas.height;
                let dx = (Math.random() - 0.5) / 20;
                let dy = (Math.random() + 1) / 2;
                let size = 3 + Math.random() * 4;
                particles.push(new Particle(x, y, dx, dy, size));
            }
        }

        function animate(word) {
            ctx.clearRect(0, 0, canvas.width, canvas.height);
            for (let i = 0; i < particles.length; i++) {
                let particle = particles[i];
                if (particle.size > 1.5 && word.includes(particle.x * 32 + Math.floor(particle.y / 32))) {
                    particle.draw();
                    particle.update();
                }
            }

            requestAnimationFrame(() => animate(word));
        }

        function onInput(event) {
            const inputWord = event.target.value.toUpperCase();
            initParticles(inputWord);
            ctx.clearRect(0, 0, canvas.width, canvas.height);
            animate(inputWord);
        }

        document.body.addEventListener('mousemove', () => {
            particles.forEach(particle => particle.dy *= -1);
        });

        document.querySelector('input').addEventListener('input', onInput);

        initParticles('HELLO');
        animate('HELLO');
    </script>
</body>
</html>