1 lines, no comments ยท 3,393 tokens, written in 21 seconds for $0.013


1  let particles = []; const numParticles = 800; let colorOffset = 0; function setup() { createCanvas(windowWidth, windowHeight); colorMode(HSB, 360, 100, 100, 100); background(230, 40, 8); for (let i = 0; i < numParticles; i++) { particles.push(new Particle()); } } function draw() { blendMode(BLEND); background(230, 40, 8, 8); colorOffset += 0.25; for (let i = 0; i < particles.length; i++) { particles[i].update(); particles[i].show(); } } class Particle { constructor() { this.reset(); } reset() { this.pos = createVector(random(width), random(height)); this.prev = this.pos.copy(); this.vel = createVector(0, 0); this.maxSpeed = random(2, 4.5); this.life = random(100, 300); this.age = 0; this.seed = random(1000); this.hueOffset = random(60); } update() { this.prev.set(this.pos); let angle = noise(this.pos.x * 0.003, this.pos.y * 0.003, frameCount * 0.002 + this.seed * 0.01) * TWO_PI * 4; let flowForce = p5.Vector.fromAngle(angle).mult(0.6); this.vel.add(flowForce); let mouse = createVector(mouseX, mouseY); let d = p5.Vector.dist(this.pos, mouse); if (d < 200 && d > 5) { let push = p5.Vector.sub(this.pos, mouse); push.normalize(); push.mult(map(d, 0, 200, 2, 0)); this.vel.add(push); } this.vel.limit(this.maxSpeed); this.pos.add(this.vel); this.age++; if (this.age > this.life || this.pos.x < 0 || this.pos.x > width || this.pos.y < 0 || this.pos.y > height) { this.reset(); } } show() { let speed = this.vel.mag(); let h = (colorOffset + this.hueOffset + map(speed, 0, this.maxSpeed, 0, 60)) % 360; let alpha = map(sin(map(this.age, 0, this.life, 0, PI)), 0, 1, 0, 70); let weight = map(speed, 0, this.maxSpeed, 1, 2.5); stroke(h, 85, 95, alpha); strokeWeight(weight); line(this.prev.x, this.prev.y, this.pos.x, this.pos.y); } } function windowResized() { resizeCanvas(windowWidth, windowHeight); background(230, 40, 8); } function mousePressed() { for (let i = 0; i < particles.length; i++) { let d = dist(mouseX, mouseY, particles[i].pos.x, particles[i].pos.y); if (d < 300) { let force = p5.Vector.sub(particles[i].pos, createVector(mouseX, mouseY)); force.setMag(map(d, 0, 300, 15, 2)); particles[i].vel.add(force); } } }