Skip to content
The Chat Archive
qwen3-30b-a3b· Alibaba (Qwen) LMArena Human Preference 140K

Create a very cool and creative particle simulation!

  1. User

    Create a very cool and creative particle simulation!

  2. Assistant

    Here's a cool and creative particle simulation using HTML5 Canvas and JavaScript. It features interactive particles that respond to your mouse, leave trails, and have dynamic colors. You can copy and paste this into an .html file and open it in your browser:

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>Creative Particle Simulation</title>
      <style>
        body {
          margin: 0;
          overflow: hidden;
          background: #000;
        }
        canvas {
          display: block;
        }
      </style>
    </head>
    <body>
    <canvas id="canvas"></canvas>
    <script>
      const canvas = document.getElementById('canvas');
      const ctx = canvas.getContext('2d');
      let width, height;
    
      function resize() {
        width = canvas.width = window.innerWidth;
        height = canvas.height = window.innerHeight;
      }
      window.addEventListener('resize', resize);
      resize();
    
      class Particle {
        constructor() {
          this.x = Math.random() * width;
          this.y = Math.random() * height;
          this.radius = Math.random() * 2 + 1;
          this.speed = Math.random() * 1.5 + 0.5;
          this.angle = Math.random() * Math.PI * 2;
          this.color = `hsl(${Math.random() * 360}, 100%, 70%)`;
          this.trail = [];
        }
    
        update() {
          // Move in a circular path
          this.x += Math.cos(this.angle) * this.speed;
          this.y += Math.sin(this.angle) * this.speed;
          this.angle += 0.01;
    
          // Bounce off edges
          if (this.x < 0 || this.x > width) this.angle = Math.PI - this.angle;
          if (this.y < 0 || this.y > height) this.angle = -this.angle;
    
          // Add to trail
          this.trail.push({ x: this.x, y: this.y });
          if (this.trail.length > 10) this.trail.shift();
        }
    
        draw() {
          // Draw trail
          ctx.beginPath();
          ctx.moveTo(this.trail[0].x, this.trail[0].y);
          for (let i = 1; i < this.trail.length; i++) {
            ctx.lineTo(this.trail[i].x, this.trail[i].y);
          }
          ctx.strokeStyle = this.color;
          ctx.lineWidth = this.radius;
          ctx.stroke();
    
          // Draw main particle
          ctx.beginPath();
          ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2);
          ctx.fillStyle = this.color;
          ctx.fill();
        }
      }
    
      const particles = [];
      for (let i = 0; i < 200; i++) {
        particles.push(new Particle());
      }
    
      let mouseX = width / 2;
      let mouseY = height / 2;
    
      document.addEventListener('mousemove', (e) => {
        mouseX = e.clientX;
        mouseY = e.clientY;
      });
    
      function animate() {
        // Clear canvas with semi-transparent black to create trailing effect
        ctx.fillStyle = 'rgba(0, 0, 0, 0.2)';
        ctx.fillRect(0, 0, width, height);
    
        for (const particle of particles) {
          // Attract particles to mouse
          const dx = mouseX - particle.x;
          const dy = mouseY - particle.y;
          const distance = Math.sqrt(dx * dx + dy * dy);
          if (distance < 100) {
            particle.x += dx * 0.005;
            particle.y += dy * 0.005;
          }
    
          particle.update();
          particle.draw();
        }
    
        requestAnimationFrame(animate);
      }
    
      animate();
    </script>
    </body>
    </html>
    

    🔥 Features:

    • Interactive Trails: Particles leave glowing trails as they move.
    • Dynamic Colors: Each particle has a unique hue from the HSL color space.
    • Mouse Attraction: Particles are gently pulled toward your cursor.
    • Bouncing Behavior: Particles bounce off the edges of the screen.
    • Responsive Design: Works on any screen size.

    🧠 How It Works:

    • Particles are objects with position, velocity, and trail history.
    • Animation Loop uses requestAnimationFrame for smooth rendering.
    • Trail Effect is created by drawing lines between previous positions.
    • Mouse Interaction adds a layer of user engagement.

    🎨 Want More?

    • Add sound based on particle movement.
    • Introduce different particle types (e.g., static, explosive, or flocking).
    • Use WebGL for 3D effects.

    Let me know if you want to expand this! 🚀

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