xxxxxxxxxx
51
let sistem = [];
function setup() {
createCanvas(200, 300);
}
function draw() {
background(0);
for (let i = 0; i < 5; i++) {
let c = new Cestica();
sistem.push(c);
}
for (let i = sistem.length - 1; i >= 0; i--) {
sistem[i].azuriraj();
sistem[i].nacrtaj();
if (sistem[i].kraj()) {
// remove this particle
sistem.splice(i, 1);
}
}
}
class Cestica {
constructor() {
this.x = 100;
this.y = 280;
this.vx = random(-1, 1);
this.vy = random(-5, -1);
this.r = random(5, 20);
this.providnost = random(0, 255);
this.zelena = random(50, 150);
}
kraj() {
return this.providnost < 0;
}
azuriraj() {
this.x += this.vx;
this.y += this.vy;
this.providnost -= 3.5;
}
nacrtaj() {
noStroke();
fill(220, this.zelena, 40, this.providnost);
ellipse(this.x, this.y, this.r);
}
}