xxxxxxxxxx
53
// concentric circles with 'planets' following the path
let Circle = function(x,y,r,c,e_r,inc) {
this.x = x;
this.y = y;
this.r = r;
this.c = c;
this.e_r = e_r;
this.theta = random() * TWO_PI;
this.inc = inc;
this.draw = function() {
if (this.c)
fill(this.c);
else
noFill();
strokeWeight(1);
stroke(255);
if (this.e_r) {
push();
translate(width/2,height/2);
let _x = this.r * cos(this.theta);
let _y = this.r * sin(this.theta);
ellipse(_x,_y,this.e_r*2,this.e_r*2);
this.theta+=this.inc;
pop();
} else {
ellipse(this.x,this.y,this.r*2,this.r*2);
}
}
}
let circles = [];
function setup() {
createCanvas(400, 400);
// paths
for (let i = 0; i < 10; i++) {
circles.push(new Circle(width/2,height/2,20+i*20,null,null));
circles.push(new Circle(width/2,height/2,20+i*20,color(0,255,0),10,random(-0.01,0.01)));
}
// spheres
}
function draw() {
background(0);
circles.forEach(elem => elem.draw());
}