-
let paints = []; let numPaints = 5000; let gravity; function setup() { createCanvas(windowWidth, windowHeight); for (let i = 0; i < numPaints; i++) { paints.push(new Paint()); } gravity = createVector(0, random(-.1, .1)); } function draw() { background = color(random(100, 256), random(100, 256), random(100, 256)); for (let i = 0; i < paints.length; i++) { let p = paints[i]; p.applyForce(gravity); p.update(); p.show(); p.fade(); if (p.isOffScreen()) { paints[i] = new Paint(); } } } class Paint { constructor() { this.position = createVector(random(width * 5), random(height * 5)); this.velocity = createVector(random(-1, 1), random(1, 1)); this.acceleration = createVector(0); this.color = color(random(100, 256), random(100, 256), random(100, 256)); this.opacity = random(0,1); } applyForce(force) { this.acceleration.add(force); } update() { this.velocity.add(this.acceleration); this.position.add(this.velocity); this.acceleration.mult(.01); } show() { stroke(this.color, this.opacity); strokeWeight(random(5, 10)); point(this.position.x, this.position.y); } fade() { this.opacity -= 1; } isOffScreen() { return ( this.position.x < 0 || this.position.x > width || this.position.y < 0 || this.position.y > height ); } }