62 lines, no comments ยท 661 tokens, written in 2 seconds for $0.0017


 1  let particles = [];
 2  
 3  function setup() {
 4    createCanvas(windowWidth, windowHeight);
 5    background(10);
 6    for (let i = 0; i < 75; i++) {
 7      particles.push(new Particle());
 8    }
 9  }
10  
11  function draw() {
12    background(10, 25);
13    
14    for (let i = 0; i < particles.length; i++) {
15      particles[i].update();
16      particles[i].display();
17      
18      for (let j = i + 1; j < particles.length; j++) {
19        let d = dist(particles[i].x, particles[i].y, particles[j].x, particles[j].y);
20        if (d < 120) {
21          stroke(100, 200, 255, map(d, 0, 120, 200, 0));
22          strokeWeight(0.8);
23          line(particles[i].x, particles[i].y, particles[j].x, particles[j].y);
24        }
25      }
26      
27      let mouseDist = dist(particles[i].x, particles[i].y, mouseX, mouseY);
28      if (mouseDist < 150) {
29        stroke(255, 100, 200, map(mouseDist, 0, 150, 255, 0));
30        strokeWeight(1);
31        line(particles[i].x, particles[i].y, mouseX, mouseY);
32      }
33    }
34  }
35  
36  class Particle {
37    constructor() {
38      this.x = random(width);
39      this.y = random(height);
40      this.vx = random(-1, 1);
41      this.vy = random(-1, 1);
42      this.r = random(2, 5);
43    }
44    
45    update() {
46      this.x += this.vx;
47      this.y += this.vy;
48      
49      if (this.x < 0 || this.x > width) this.vx *= -1;
50      if (this.y < 0 || this.y > height) this.vy *= -1;
51    }
52    
53    display() {
54      noStroke();
55      fill(255, 200);
56      ellipse(this.x, this.y, this.r * 2);
57    }
58  }
59  
60  function windowResized() {
61    resizeCanvas(windowWidth, windowHeight);
62  }