xxxxxxxxxx
44
let ball;
function setup() {
createCanvas(400, 400);
ball = new Ball();
print(ball);
}
function draw() {
stroke(200);
ball.show();
ball.move();
ball.changeSize();
ball.changeColour();
}
class Ball {
constructor() {
this.x = 200;
this.y = 200;
this.size = 10;
this.colour = 255;
}
move() {
if (this.x > 0 && this.x < 400 && this.y > 0 && this.y < 400) {
this.x += random(-15, 15);
this.y += random(-15, 15);
} else {
this.x = 200;
this.y = 200;
}
}
show() {
fill(this.colour)
circle(this.x, this.y, this.size);
}
changeSize() {
this.size += random(-5, 5);
}
changeColour() {
this.colour = color(random(0, 255));
}
}