xxxxxxxxxx
38
let WID = 400;
let HIG = 400;
let ball1, ball2, ball3;
function setup() {
createCanvas(WID,HIG);
ball1 = new ball(100);
ball2 = new ball(200);
print(ball1.x, ball1.y);
}
function draw() {
// background(220);
ball1.show();
ball1.move();
ball2.show();
ball2.move();
}
class ball {
constructor(shade){
this.x = WID/2;
this.y = WID/2;
this.d = 23;
this.s = shade;
}
move() {
this.x = this.x + random(-2,2);
this.y = this.y + random(-2,2)
}
show() {
stroke(0);
strokeWeight(2);
fill(this.s);
ellipse(this.x, this.y, this.d);
}
}