56 lines, no comments ยท 4,726 tokens, written in 59 seconds for $0.029


 1  let particles = [];
 2  
 3  function setup() {
 4    createCanvas(800, 600);
 5    colorMode(HSB, 360, 100, 100, 100);
 6    background(0);
 7    for (let i = 0; i < 350; i++) {
 8      particles.push(new Particle());
 9    }
10  }
11  
12  function draw() {
13    fill(0, 0, 0, 6);
14    noStroke();
15    rect(0, 0, width, height);
16    for (let p of particles) {
17      p.update();
18      p.show();
19    }
20  }
21  
22  class Particle {
23    constructor() {
24      this.pos = createVector(random(width), random(height));
25      this.prevPos = this.pos.copy();
26      this.vel = p5.Vector.random2D().mult(random(0.4, 1.8));
27      this.hue = random(360);
28    }
29  
30    update() {
31      let n = noise(this.pos.x * 0.0035, this.pos.y * 0.0035, frameCount * 0.002);
32      let angle = n * TWO_PI * 3;
33      let acc = p5.Vector.fromAngle(angle);
34      acc.setMag(0.08);
35      this.vel.add(acc);
36      this.vel.limit(2.2);
37      this.prevPos.set(this.pos);
38      this.pos.add(this.vel);
39      this.wrap();
40    }
41  
42    wrap() {
43      if (this.pos.x > width) this.pos.x = 0;
44      if (this.pos.x < 0) this.pos.x = width;
45      if (this.pos.y > height) this.pos.y = 0;
46      if (this.pos.y < 0) this.pos.y = height;
47    }
48  
49    show() {
50      if (dist(this.prevPos.x, this.prevPos.y, this.pos.x, this.pos.y) < 6) {
51        stroke(this.hue, 65, 92, 45);
52        strokeWeight(1.2);
53        line(this.prevPos.x, this.prevPos.y, this.pos.x, this.pos.y);
54      }
55    }
56  }