100 lines, 13 of them comments ยท 995 tokens, written in 47 seconds for $0.082


  1  let particles = [];
  2  let numParticles = 100;
  3  
  4  function setup() {
  5    createCanvas(windowWidth, windowHeight);
  6    
  7    // Initialize particles
  8    for (let i = 0; i < numParticles; i++) {
  9      particles.push(new Particle());
 10    }
 11  }
 12  
 13  function draw() {
 14    // Semi-transparent background for trails
 15    background(20, 20, 30, 25);
 16    
 17    // Update and display particles
 18    for (let particle of particles) {
 19      particle.update();
 20      particle.display();
 21    }
 22  }
 23  
 24  class Particle {
 25    constructor() {
 26      this.x = random(width);
 27      this.y = random(height);
 28      this.vx = random(-2, 2);
 29      this.vy = random(-2, 2);
 30      this.size = random(5, 20);
 31      this.hue = random(360);
 32      this.lifespan = 255;
 33    }
 34    
 35    update() {
 36      // Add some attraction to mouse
 37      let mouseForce = createVector(mouseX - this.x, mouseY - this.y);
 38      mouseForce.mult(0.00005);
 39      
 40      this.vx += mouseForce.x;
 41      this.vy += mouseForce.y;
 42      
 43      // Add some noise-based movement
 44      this.vx += (noise(this.x * 0.005, this.y * 0.005, frameCount * 0.01) - 0.5) * 0.5;
 45      this.vy += (noise(this.y * 0.005, this.x * 0.005, frameCount * 0.01) - 0.5) * 0.5;
 46      
 47      // Limit velocity
 48      this.vx = constrain(this.vx, -5, 5);
 49      this.vy = constrain(this.vy, -5, 5);
 50      
 51      // Update position
 52      this.x += this.vx;
 53      this.y += this.vy;
 54      
 55      // Wrap around edges
 56      if (this.x < 0) this.x = width;
 57      if (this.x > width) this.x = 0;
 58      if (this.y < 0) this.y = height;
 59      if (this.y > height) this.y = 0;
 60      
 61      // Slowly change hue
 62      this.hue += 0.5;
 63      if (this.hue > 360) this.hue = 0;
 64    }
 65    
 66    display() {
 67      push();
 68      colorMode(HSB, 360, 100, 100, 255);
 69      noStroke();
 70      
 71      // Main particle
 72      fill(this.hue, 80, 100, 150);
 73      circle(this.x, this.y, this.size);
 74      
 75      // Glow effect
 76      fill(this.hue, 70, 100, 50);
 77      circle(this.x, this.y, this.size * 1.5);
 78      
 79      pop();
 80    }
 81  }
 82  
 83  function windowResized() {
 84    resizeCanvas(windowWidth, windowHeight);
 85  }
 86  
 87  function mousePressed() {
 88    // Add new particles at mouse position
 89    for (let i = 0; i < 10; i++) {
 90      let p = new Particle();
 91      p.x = mouseX + random(-20, 20);
 92      p.y = mouseY + random(-20, 20);
 93      particles.push(p);
 94    }
 95    
 96    // Limit total particles
 97    if (particles.length > 200) {
 98      particles.splice(0, 10);
 99    }
100  }