Source of: Drifting Flow Field, by Claude Fable 5.1
65 lines, no comments ยท 1,575 tokens, written in 22 seconds for $0.082
1 let particles = [];
2 const NUM = 1500;
3 const noiseScale = 0.0035;
4 let t = 0;
5 let zOff = 0;
6
7 function setup() {
8 createCanvas(windowWidth, windowHeight);
9 colorMode(HSB, 360, 100, 100, 100);
10 background(230, 40, 6);
11 for (let i = 0; i < NUM; i++) {
12 particles.push(makeParticle(true));
13 }
14 }
15
16 function makeParticle(randomLife) {
17 const x = random(width);
18 const y = random(height);
19 return {
20 x: x,
21 y: y,
22 px: x,
23 py: y,
24 hue: random(170, 320),
25 speed: random(0.8, 2.2),
26 life: randomLife ? random(50, 400) : random(150, 400)
27 };
28 }
29
30 function draw() {
31 noStroke();
32 fill(230, 40, 6, 4);
33 rect(0, 0, width, height);
34 t += 0.0015;
35 strokeWeight(1.1);
36 for (let p of particles) {
37 const n = noise(p.x * noiseScale, p.y * noiseScale, t + zOff);
38 const angle = n * TWO_PI * 3;
39 p.px = p.x;
40 p.py = p.y;
41 p.x += cos(angle) * p.speed;
42 p.y += sin(angle) * p.speed;
43 p.life--;
44 const h = (p.hue + n * 60 + frameCount * 0.05) % 360;
45 const alpha = map(min(p.life, 60), 0, 60, 0, 55);
46 stroke(h, 65, 100, alpha);
47 line(p.px, p.py, p.x, p.y);
48 if (p.x < -5 || p.x > width + 5 || p.y < -5 || p.y > height + 5 || p.life <= 0) {
49 Object.assign(p, makeParticle(false));
50 }
51 }
52 }
53
54 function mousePressed() {
55 zOff += 10;
56 background(230, 40, 6);
57 for (let p of particles) {
58 Object.assign(p, makeParticle(true));
59 }
60 }
61
62 function windowResized() {
63 resizeCanvas(windowWidth, windowHeight);
64 background(230, 40, 6);
65 }