Source of: Neon Flowfield Odyssey, by Gemini 3.6 Flash
72 lines, no comments ยท 2,992 tokens, written in 12 seconds for $0.011
1 let particles = [];
2 const numParticles = 700;
3 let noiseScale = 0.005;
4
5 function setup() {
6 createCanvas(windowWidth, windowHeight);
7 colorMode(HSB, 360, 100, 100, 1);
8 background(240, 40, 10);
9 for (let i = 0; i < numParticles; i++) {
10 particles.push(new Particle());
11 }
12 }
13
14 function draw() {
15 colorMode(RGB, 255);
16 background(10, 10, 20, 25);
17 colorMode(HSB, 360, 100, 100, 1);
18
19 for (let p of particles) {
20 p.update();
21 p.show();
22 }
23 }
24
25 class Particle {
26 constructor() {
27 this.pos = createVector(random(width), random(height));
28 this.vel = createVector(0, 0);
29 this.acc = createVector(0, 0);
30 this.maxSpeed = random(1.5, 3.5);
31 this.prevPos = this.pos.copy();
32 this.hue = random(180, 320);
33 }
34
35 update() {
36 this.prevPos.set(this.pos);
37 let angle = noise(this.pos.x * noiseScale, this.pos.y * noiseScale, frameCount * 0.002) * TWO_PI * 4;
38 let force = p5.Vector.fromAngle(angle);
39 force.setMag(0.15);
40
41 let d = dist(this.pos.x, this.pos.y, mouseX, mouseY);
42 if (d < 150) {
43 let push = p5.Vector.sub(this.pos, createVector(mouseX, mouseY));
44 push.setMag(map(d, 0, 150, 1.5, 0));
45 force.add(push);
46 }
47
48 this.acc.add(force);
49 this.vel.add(this.acc);
50 this.vel.limit(this.maxSpeed);
51 this.pos.add(this.vel);
52 this.acc.mult(0);
53
54 if (this.pos.x > width || this.pos.x < 0 || this.pos.y > height || this.pos.y < 0) {
55 this.pos.set(random(width), random(height));
56 this.prevPos.set(this.pos);
57 }
58 }
59
60 show() {
61 let h = (this.hue + frameCount * 0.2) % 360;
62 stroke(h, 80, 100, 0.5);
63 strokeWeight(1.5);
64 line(this.pos.x, this.pos.y, this.prevPos.x, this.prevPos.y);
65 }
66 }
67
68 function windowResized() {
69 resizeCanvas(windowWidth, windowHeight);
70 colorMode(RGB, 255);
71 background(10, 10, 20);
72 }