xxxxxxxxxx
let off = 0.005;
let maxlife = 100;
let particles = [];
let img;
function preload() {
img = loadImage('monalisa.png');
}
function setup() {
createCanvas(600, 600);
background(0);
for(let i=0; i<6000; i++) {
let x = random(width);
let y = random(height);
let c = img.get(x, y);
particles.push(new Particle(x, y, c));
}
}
function draw() {
// background(0);
for(let p of particles) {
p.update();
p.show();
if(p.isdone()) particles.splice(particles.indexOf(p), 1);
}
}
class Particle {
constructor(x, y, c) {
this.x = x;
this.y = y;
this.c = c;
this.life = maxlife;
}
update() {
let nr = map(noise(this.x*off, this.y*off), 0, 1, 0, TAU*1.5);
let nx = cos(nr);
let ny = sin(nr);
this.x += nx;
this.y += ny;
this.life --;
}
show() {
fill(this.c);
noStroke();
ellipse(this.x, this.y, 1);
}
isdone() {
return (this.life<0)? true : false;
}
}