xxxxxxxxxx
let bugs = [];
function setup() {
createCanvas(windowWidth, windowHeight);
background(0);
stroke(255);
}
function mousePressed() {
//I create a new instance of the class Drop
let newBug = new Bug(mouseX, mouseY);
//put it at the end of the array
bugs.push(newBug);
}
function draw() {
//accessing them in the array
for (let i = 0; i < bugs.length; i++) {
//call the update method of each drop
bugs[i].update();
}
}
// Drop class
class Bug {
constructor(px, py) {
this.x = px;
this.y = py;
}
update() {
this.px = this.x;
this.py = this.y
this.x += random(-10, 10);
this.y += random(-10, 10);
line(this.x, this.y, this.px, this.py);
}
}