xxxxxxxxxx
59
let circleArray = [];
let number_of_circles = 100;
function setup() {
background(0,0,0);
frameRate(50);
createCanvas(400, 400);
for (let i = 0; i < number_of_circles; i++) {
circleArray.push(new Circle(random(width), random(height), random(10, 50)));
}
}
function draw() {
background(0,0,0);
for (let i = 0; i < circleArray.length; i++) {
circleArray[i].display();
circleArray[i].update();
}
}
class Circle {
constructor(x, y, diameter) {
this.x = x;
this.y = y;
this.diameter = diameter;
this.speed = 10;
}
display() {
noStroke();
fill(random(255), random(255), random(255));
ellipse(this.x, this.y, this.diameter, this.diameter);
}
update() {
this.x += random(-this.speed, this.speed);
this.y += random(-this.speed, this.speed);
}
// change_speed()
// {
// this.speed = 0;
// }
}
// function mousePressed()
// {
// for (let i = 0; i < circleArray.length; i++) {
// circleArray[i].change_speed();
// }
// }
// function mouseReleased()
// {
// for (let i = 0; i < circleArray.length; i++) {
// circleArray[i].change_speed();
// }
// }