Skip to content
The Chat Archive
mistral-medium-2505· Mistral AI LMArena Human Preference 140K

Build me particle game that wrapped inside a big circle and do bounce and physic stuff…

  1. User

    Build me particle game that wrapped inside a big circle and do bounce and physic stuff when I hit sides of the circle and every second a new particle pops up, the particles could be geometric shapes or alphabet characters or numbers

  2. Assistant

    Particle Game Inside a Circle

    Here's a fun particle game where geometric shapes, alphabet characters, and numbers bounce around inside a circular boundary. New particles appear every second and they all follow physics-based bouncing behavior.

    <!DOCTYPE html>
    <html>
    <head>
        <title>Particle Circle Game</title>
        <style>
            body {
                margin: 0;
                overflow: hidden;
                background-color: #f0f0f0;
                display: flex;
                justify-content: center;
                align-items: center;
                height: 100vh;
                font-family: Arial, sans-serif;
            }
            #game-container {
                position: relative;
                width: 600px;
                height: 600px;
            }
            #circle-boundary {
                position: absolute;
                border: 2px solid #333;
                border-radius: 50%;
                width: 100%;
                height: 100%;
            }
            .particle {
                position: absolute;
                cursor: pointer;
            }
            #controls {
                position: absolute;
                bottom: 20px;
                left: 50%;
                transform: translateX(-50%);
                background: rgba(255, 255, 255, 0.7);
                padding: 10px;
                border-radius: 5px;
            }
            button {
                padding: 5px 10px;
                margin: 0 5px;
                cursor: pointer;
            }
        </style>
    </head>
    <body>
        <div id="game-container">
            <div id="circle-boundary"></div>
            <div id="controls">
                <button id="add-particle">Add Particle</button>
                <button id="clear-particles">Clear All</button>
                <span id="particle-count">Particles: 0</span>
            </div>
        </div>
    
        <script>
            const container = document.getElementById('game-container');
            const boundary = document.getElementById('circle-boundary');
            const particleCountDisplay = document.getElementById('particle-count');
    
            // Game parameters
            const boundaryRadius = 300;
            const centerX = container.offsetWidth / 2;
            const centerY = container.offsetHeight / 2;
            const particleSize = 30;
            const particleTypes = ['circle', 'square', 'triangle', 'A', 'B', 'C', '1', '2', '3'];
            const colors = ['#FF5733', '#33FF57', '#3357FF', '#F3FF33', '#FF33F3', '#33FFF3'];
    
            let particles = [];
            let particleIdCounter = 0;
    
            // Initialize the game
            function init() {
                // Set up the boundary
                boundary.style.width = `${boundaryRadius * 2}px`;
                boundary.style.height = `${boundaryRadius * 2}px`;
    
                // Start adding particles every second
                setInterval(addRandomParticle, 1000);
    
                // Set up event listeners
                document.getElementById('add-particle').addEventListener('click', addRandomParticle);
                document.getElementById('clear-particles').addEventListener('click', clearAllParticles);
    
                // Start the game loop
                gameLoop();
            }
    
            // Add a random particle
            function addRandomParticle() {
                const type = particleTypes[Math.floor(Math.random() * particleTypes.length)];
                const color = colors[Math.floor(Math.random() * colors.length)];
    
                // Random position inside the boundary (but not too close to edge)
                const angle = Math.random() * Math.PI * 2;
                const distance = Math.random() * (boundaryRadius - particleSize - 20);
    
                const x = centerX + distance * Math.cos(angle);
                const y = centerY + distance * Math.sin(angle);
    
                // Random velocity
                const speed = 1 + Math.random() * 3;
                const direction = Math.random() * Math.PI * 2;
                const vx = speed * Math.cos(direction);
                const vy = speed * Math.sin(direction);
    
                addParticle(x, y, vx, vy, type, color);
            }
    
            // Add a specific particle
            function addParticle(x, y, vx, vy, type, color) {
                const particle = document.createElement('div');
                particle.className = 'particle';
                particle.id = `particle-${particleIdCounter++}`;
    
                // Set initial position
                particle.style.left = `${x - particleSize / 2}px`;
                particle.style.top = `${y - particleSize / 2}px`;
                particle.style.width = `${particleSize}px`;
                particle.style.height = `${particleSize}px`;
                particle.style.backgroundColor = color;
                particle.style.color = getContrastColor(color);
    
                // Set shape or character
                if (type === 'circle') {
                    particle.style.borderRadius = '50%';
                } else if (type === 'square') {
                    particle.style.borderRadius = '0';
                } else if (type === 'triangle') {
                    particle.style.width = '0';
                    particle.style.height = '0';
                    particle.style.borderLeft = `${particleSize / 2}px solid transparent`;
                    particle.style.borderRight = `${particleSize / 2}px solid transparent`;
                    particle.style.borderBottom = `${particleSize}px solid ${color}`;
                } else {
                    // It's a character or number
                    particle.style.borderRadius = '50%';
                    particle.style.display = 'flex';
                    particle.style.justifyContent = 'center';
                    particle.style.alignItems = 'center';
                    particle.style.fontSize = `${particleSize * 0.7}px`;
                    particle.style.fontWeight = 'bold';
                    particle.textContent = type;
                }
    
                container.appendChild(particle);
    
                particles.push({
                    element: particle,
                    x: x,
                    y: y,
                    vx: vx,
                    vy: vy,
                    size: particleSize,
                    type: type,
                    color: color
                });
    
                updateParticleCount();
            }
    
            // Clear all particles
            function clearAllParticles() {
                particles.forEach(particle => {
                    container.removeChild(particle.element);
                });
                particles = [];
                updateParticleCount();
            }
    
            // Update particle count display
            function updateParticleCount() {
                particleCountDisplay.textContent = `Particles: ${particles.length}`;
            }
    
            // Game loop
            function gameLoop() {
                // Update each particle
                particles.forEach(particle => {
                    // Update position
                    particle.x += particle.vx;
                    particle.y += particle.vy;
    
                    // Check for collision with boundary
                    const distanceFromCenter = Math.sqrt(
                        Math.pow(particle.x - centerX, 2) +
                        Math.pow(particle.y - centerY, 2)
                    );
    
                    if (distanceFromCenter > boundaryRadius - particle.size / 2) {
                        // Calculate normal vector (from center to particle)
                        const nx = (particle.x - centerX) / distanceFromCenter;
                        const ny = (particle.y - centerY) / distanceFromCenter;
    
                        // Calculate dot product of velocity and normal
                        const dotProduct = particle.vx * nx + particle.vy * ny;
    
                        // Reflect velocity
                        particle.vx = particle.vx - 2 * dotProduct * nx;
                        particle.vy = particle.vy - 2 * dotProduct * ny;
    
                        // Add some energy loss (damping)
                        particle.vx *= 0.9;
                        particle.vy *= 0.9;
    
                        // Move particle back inside boundary
                        const overlap = distanceFromCenter - (boundaryRadius - particle.size / 2);
                        particle.x -= nx * overlap * 1.1;
                        particle.y -= ny * overlap * 1.1;
                    }
    
                    // Update particle position in DOM
                    particle.element.style.left = `${particle.x - particle.size / 2}px`;
                    particle.element.style.top = `${particle.y - particle.size / 2}px`;
                });
    
                requestAnimationFrame(gameLoop);
            }
    
            // Helper function to get contrasting text color
            function getContrastColor(hexColor) {
                // Convert hex to RGB
                const r = parseInt(hexColor.substr(1, 2), 16);
                const g = parseInt(hexColor.substr(3, 2), 16);
                const b = parseInt(hexColor.substr(5, 2), 16);
    
                // Calculate luminance
                const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
    
                // Return black or white depending on luminance
                return luminance > 0.5 ? '#000000' : '#FFFFFF';
            }
    
            // Start the game
            init();
        </script>
    </body>
    </html>
    

    How to Use This Game:

    1. The game automatically starts with particles appearing every second
    2. Particles can be:
      • Geometric shapes (circles, squares, triangles)
      • Alphabet characters (A, B, C)
      • Numbers (1, 2, 3)
    3. Particles bounce realistically off the circular boundary
    4. Controls:
      • "Add Particle" button: Manually add a new random particle
      • "Clear All" button: Remove all particles
      • Particle count display shows how many particles are currently active

    Features:

    • Physics-based bouncing with proper reflection calculations
    • Energy loss (damping) on collisions for more realistic behavior
    • Random colors and shapes for visual variety
    • Automatic contrast adjustment for text visibility
    • Responsive design that works in most browser windows

    You can copy this code into an HTML file and open it in any modern browser to play the game!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.