67 lines, no comments ยท 4,838 tokens, written in 58 seconds for $0.030


 1  let particles = [];
 2  function setup() {
 3    createCanvas(windowWidth, windowHeight);
 4    colorMode(HSB, 360, 100, 100, 100);
 5    for (let i = 0; i < 300; i++) {
 6      particles.push(new Particle());
 7    }
 8    background(0);
 9  }
10  function draw() {
11    fill(0, 0, 0, 6);
12    noStroke();
13    rect(0, 0, width, height);
14    for (let p of particles) {
15      p.update();
16      p.show();
17    }
18  }
19  function windowResized() {
20    resizeCanvas(windowWidth, windowHeight);
21  }
22  class Particle {
23    constructor() {
24      this.pos = createVector(random(width), random(height));
25      this.vel = p5.Vector.random2D();
26      this.vel.setMag(random(0.5, 2));
27      this.acc = createVector(0, 0);
28      this.maxSpeed = 4;
29      this.h = random(360);
30      this.prev = this.pos.copy();
31    }
32    update() {
33      let n = noise(this.pos.x * 0.004, this.pos.y * 0.004, frameCount * 0.002);
34      let a = n * TWO_PI * 4;
35      this.acc = p5.Vector.fromAngle(a);
36      this.acc.setMag(0.2);
37      this.vel.add(this.acc);
38      this.vel.limit(this.maxSpeed);
39      this.pos.add(this.vel);
40      this.wrap();
41      this.h = (this.h + 0.5) % 360;
42    }
43    wrap() {
44      if (this.pos.x > width + 10) {
45        this.pos.x = -10;
46        this.prev.x = -10;
47      }
48      if (this.pos.x < -10) {
49        this.pos.x = width + 10;
50        this.prev.x = width + 10;
51      }
52      if (this.pos.y > height + 10) {
53        this.pos.y = -10;
54        this.prev.y = -10;
55      }
56      if (this.pos.y < -10) {
57        this.pos.y = height + 10;
58        this.prev.y = height + 10;
59      }
60    }
61    show() {
62      stroke(this.h, 80, 100, 30);
63      strokeWeight(2);
64      line(this.prev.x, this.prev.y, this.pos.x, this.pos.y);
65      this.prev = this.pos.copy();
66    }
67  }