xxxxxxxxxx
40
var apples = [];
function setup() {
createCanvas(700, 700);
}
function draw() {
background(220);
for (var i = 0; i < apples.length; i++) {
apples[i].display();
apples[i].float();
}
}
function mousePressed() {
var myApple = new Apple(mouseX-50, mouseY-50, random(60,120));
apples.push(myApple);
}
class Apple {
constructor(x, y, r) {
this.x = x;
this.y = y;
this.radius = r;
}
display() {
image(apple, this.x, this.y, this.radius, this.radius);
}
float() {
this.x = this.x + random(-1, 1);
this.y = this.y + random(-1, 1);
}
}
function preload() {
apple = loadImage("Apple.png");
}