xxxxxxxxxx
38
function createBall() {
var ball = {
position: createVector(random(100), random(100)),
velocity: createVector(random(10), random(10)),
diameter: random(30, 80),
r: random(0,256),
b: random(0,256),
display: function() {
noStroke();
fill(this.r, 150, this.b);
ellipse(this.position.x, this.position.y, this.diameter, this.diameter);
// eyes
fill(0);
ellipse(this.position.x + 10, this.position.y, 5,8);
ellipse(this.position.x - 10, this.position.y, 5,8);
ellipse(this.position.x, this.position.y+10, 8, 5);
}, // end display method
move: function() {
this.position.add(this.velocity);
if ((this.position.x > width) || (this.position.x < 0)) {
this.velocity.x = this.velocity.x * -1;
}
if ((this.position.y > height) || (this.position.y < 0)) {
this.velocity.y = this.velocity.y * -1;
}
}
} // end ball
return ball;
}