xxxxxxxxxx
100
let rounds=[] // array to store rotating circles
function setup() {
createCanvas(400, 400);
// these for loops create rotating circles consisting of 20
// circles in each rotation, varies by position
for (let i = 0; i < 20; i++) {
rounds.push(new roundy(0,0,10));
}
for (let i = 0; i < 20; i++) {
rounds.push(new roundy(100,100,10));
}
for (let i = 0; i < 20; i++) {
rounds.push(new roundy(200,200,10));
}
for (let i = 0; i < 20; i++) {
rounds.push(new roundy(300,300,10));
}
for (let i = 0; i < 20; i++) {
rounds.push(new roundy(390,390,10));
}
for (let i = 0; i < 20; i++) {
rounds.push(new roundy(0,0,10));
}
for (let i = 0; i < 20; i++) {
rounds.push(new roundy(100,100,10));
}
for (let i = 0; i < 20; i++) {
rounds.push(new roundy(50,50,20));
}
for (let i = 0; i < 20; i++) {
rounds.push(new roundy(150,150,20));
}
for (let i = 0; i < 20; i++) {
rounds.push(new roundy(250,250,20));
}
for (let i = 0; i < 20; i++) {
rounds.push(new roundy(350,350,20));
}
for (let i = 0; i < 20; i++) {
rounds.push(new roundy(390,390,20));
}
}
function draw() {
background(0);
fill(random(0,255),random(0,255), random(0,255))
// this iteration runs or pops the circles out of the array
for (let i = 0; i < rounds.length; i++) {
rounds[i].run();
}
}
// using angle and scalar variable to position the circles in a round way
var angle = 0;
var scalar = 1;
class roundy {
//constructor takes x,y position, and s is the radius or size
constructor(_x,_y,_s) {
this.x=_x;
this.y=_y;
this.s=_s;
}
update(){
// update changes or updates the position based on angle and scalar
this.newx = this.x+ scalar * cos(angle);
this.newy = this.y + scalar * sin(angle);
angle+=1; // it changes by 0.01 to keep the circles in a round way
scalar += 0.01 // this increases by 1 which creates a rotating pattern
// the position of circles changes as well so they move around the screen more
this.x+=1
this.y+=1
}
display() {
//displays the circles
ellipse(this.newx, this.newy, this.s, this.s);
}
run(){
this.update();
this.display();
}
}