← back to Model Arena

data/artifacts/097db196034e/qwen25-7b.html

140 lines

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI Constellation</title>
    <style>
        body {
            margin: 0;
            overflow: hidden;
            background-color: black;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        canvas {
            width: 100vw;
            height: 100vh;
        }
    </style>
</head>
<body>
    <canvas id="constellation"></canvas>
    <script>
        const canvas = document.getElementById('constellation');
        const ctx = canvas.getContext('2d');

        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;

        class Node {
            constructor(x, y) {
                this.x = x;
                this.y = y;
                this.vx = Math.random() * 1 - 0.5;
                this.vy = Math.random() * 1 - 0.5;
                this.radius = 8;
                this.color = 'cyan';
            }
            update() {
                this.x += this.vx;
                this.y += this.vy;

                if (this.x < this.radius) { this.x = canvas.width - this.radius; this.vx *= -1; }
                if (this.x > canvas.width - this.radius) { this.x = this.radius; this.vx *= -1; }
                if (this.y < this.radius) { this.y = canvas.height - this.radius; this.vy *= -1; }
                if (this.y > canvas.height - this.radius) { this.y = this.radius; this.vy *= -1; }
            }
            draw() {
                ctx.beginPath();
                ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2);
                ctx.fillStyle = this.color;
                ctx.fill();
            }
        }

        class Edge {
            constructor(nodeA, nodeB) {
                this.nodeA = nodeA;
                this.nodeB = nodeB;
                this.thickness = 1;
                this.timer = 0;
                this.minThickness = 0.5;
            }
            update() {
                const dx = this.nodeB.x - this.nodeA.x;
                const dy = this.nodeB.y - this.nodeA.y;
                const distance = Math.sqrt(dx * dx + dy * dy);
                if (distance > 10) {
                    this.timer += 0.5;
                    this.thickness = Math.min(1, this.timer / 20);
                } else {
                    this.thickness = this.minThickness;
                }
            }
            draw() {
                ctx.beginPath();
                ctx.moveTo(this.nodeA.x, this.nodeA.y);
                ctx.lineTo(this.nodeB.x, this.nodeB.y);
                ctx.lineWidth = this.thickness;
                ctx.strokeStyle = 'cyan';
                ctx.stroke();
            }
        }

        const nodes = [];
        for (let i = 0; i < 15; i++) {
            nodes.push(new Node(Math.random() * canvas.width, Math.random() * canvas.height));
        }

        const edges = [];
        for (let nodeA of nodes) {
            for (let nodeB of nodes) {
                if (nodeA !== nodeB && Math.random() < 0.2) {
                    edges.push(new Edge(nodeA, nodeB));
                }
            }
        }

        function draw() {
            ctx.clearRect(0, 0, canvas.width, canvas.height);

            for (let node of nodes) {
                node.update();
                node.draw();

                const highlight = [];
                const hoverX = event.clientX - canvas.offsetLeft;
                const hoverY = event.clientY - canvas.offsetTop;

                if (!event) { // not a mouse event
                    continue;
                }

                ctx.beginPath();
                for (let edge of edges) {
                    if (edge.nodeA.x < hoverX && edge.nodeA.x + edge.nodeA.radius > hoverX &&
                        edge.nodeA.y < hoverY && edge.nodeA.y + edge.nodeA.radius > hoverY ||
                        edge.nodeB.x < hoverX && edge.nodeB.x + edge.nodeB.radius > hoverX &&
                        edge.nodeB.y < hoverY && edge.nodeB.y + edge.nodeB.radius > hoverY) {
                        highlight.push(edge);
                    }
                }

                for (let edge of highlight) {
                    edge.update();
                    edge.draw();
                }
            }

            requestAnimationFrame(draw);
        }

        canvas.addEventListener('mousemove', draw);

        draw();
    </script>
</body>
</html>