xxxxxxxxxx
58
bugs = []; // array of Jitter objects
function setup() {
createCanvas(400, 400);
// Create objects
for (let i = 0; i < 100; i++) {
bugs.push(new Jitter());
}
}
function draw() {
background(50, 89, 100);
noStroke();
for (let i = 0; i < bugs.length; i++) {
bugs[i].move();
bugs[i].display();
}
}
// Jitter class
class Jitter {
constructor() {
this.x = random(width);
this.y = random(height);
this.diameter = random(40, 80);
this.speedX = random(1,3);
this.speedY = random(1,3);
this.color = color(random(0,255), 0, 0, random(128,255));
}
move() {
this.x += this.speedX;
this.y += this.speedY;
if(this.x > width){
this.speedX = -this.speedX;
}
if(this.x < 0){
this.speedX = -this.speedX;
}
if(this.y > height){
this.speedY = -this.speedY;
}
if(this.y < 0){
this.speedY = -this.speedY;
}
}
display() {
fill(this.color);
//stroke(this.color);
ellipse(this.x, this.y, this.diameter, this.diameter);
}
}