xxxxxxxxxx
32
let WID = 400; let HIG = 400;
let balls = [];
let R,G,B;
balls[0] = {
x: WID/2, y: HIG/2, d: 23,
R: 200, G:100, B: 50,
display: function() {
stroke(0); strokeWeight(4); fill(this.R,this.G,this.B);
ellipse(this.x, this.y, this.d)},
move: function() {
this.x = this.x + random(-2,2);
this.y = this.y + random(-2,2)
}
}
function setup() {
createCanvas(400, 400);
balls[1] = balls[0];
balls[1].B = 200;
balls[1].y = balls[1].y+100;
}
function draw() {
// background(220);
// ellipse(ball.x, ball.y, ball.d)
balls[0].display();
balls[0].move();
balls[1].display();
balls[1].move();
}