79 lines, no comments ยท 1,090 tokens, written in 12 seconds for $0.0076


 1  let particles = [];
 2  const COUNT = 140;
 3  
 4  function setup() {
 5    createCanvas(windowWidth, windowHeight);
 6    colorMode(HSB, 360, 100, 100, 100);
 7    for (let i = 0; i < COUNT; i++) {
 8      particles.push(new Particle(random(width), random(height), i));
 9    }
10    background(230, 40, 8);
11  }
12  
13  function draw() {
14    fill(230, 45, 6, 12);
15    noStroke();
16    rect(0, 0, width, height);
17  
18    for (let i = 0; i < particles.length; i++) {
19      const p = particles[i];
20      p.update();
21      p.draw();
22      for (let j = i + 1; j < particles.length; j++) {
23        const q = particles[j];
24        const d = dist(p.x, p.y, q.x, q.y);
25        if (d < 90) {
26          stroke(lerp(p.hue, q.hue, 0.5), 70, 100, map(d, 0, 90, 28, 0));
27          strokeWeight(1);
28          line(p.x, p.y, q.x, q.y);
29        }
30      }
31    }
32  }
33  
34  function windowResized() {
35    resizeCanvas(windowWidth, windowHeight);
36    background(230, 40, 8);
37  }
38  
39  class Particle {
40    constructor(x, y, i) {
41      this.x = x;
42      this.y = y;
43      this.i = i;
44      this.hue = (i * 17 + 190) % 360;
45      this.size = random(2.5, 6);
46      this.phase = random(TWO_PI);
47      this.speed = random(0.4, 1.1);
48      this.amp = random(18, 55);
49    }
50  
51    update() {
52      const t = frameCount * 0.008;
53      this.x += this.speed + sin(t + this.phase) * 0.35;
54      this.y += cos(t * 0.7 + this.phase * 1.3) * 0.55;
55      this.y += sin(this.x * 0.008 + t) * 0.4;
56  
57      const mx = mouseX || width / 2;
58      const my = mouseY || height / 2;
59      const d = dist(this.x, this.y, mx, my);
60      if (d < 140 && d > 0) {
61        const f = (140 - d) / 140;
62        this.x += ((this.x - mx) / d) * f * 3.2;
63        this.y += ((this.y - my) / d) * f * 3.2;
64      }
65  
66      if (this.x > width + 20) this.x = -20;
67      if (this.x < -20) this.x = width + 20;
68      if (this.y > height + 20) this.y = -20;
69      if (this.y < -20) this.y = height + 20;
70    }
71  
72    draw() {
73      noStroke();
74      fill(this.hue, 55, 100, 18);
75      circle(this.x, this.y, this.size * 5);
76      fill(this.hue, 40, 100, 90);
77      circle(this.x, this.y, this.size);
78    }
79  }