xxxxxxxxxx
40
const baelle = [];
function setup() {
createCanvas(600, 300);
background(220);
}
function draw() {
background(220);
for (let ball of baelle) {
ball.aktualisiere();
ball.zeichne();
}
}
function mousePressed() {
const neuerBall = new Ball(mouseX, mouseY);
baelle.push(neuerBall);
}
class Ball {
constructor(x, y) {
this.x = x;
this.y = y;
this.radius = 20;
this.farbe = random(255);
}
aktualisiere() {
if (this.y < height-this.radius) {
this.y += 1;
}
}
zeichne() {
fill(this.farbe);
ellipse(this.x, this.y, this.radius*2);
}
}