xxxxxxxxxx
33
let cirkel1;
function setup() {
createCanvas(400, 400);
fill("blue");
strokeWeight(3);
stroke("yellow");
cirkel1 = new Cirkel(3, 3);
}
function draw() {
background(220);
cirkel1.move();
cirkel1.bounce();
}
class Cirkel {
constructor(x, speed) {
this.x = x;
this.xSpeed = speed;
}
move() {
this.x = this.x + this.xSpeed;
circle(this.x, 100, 30);
}
bounce() {
if (this.x < 0 || this.x > 400) {
this.xSpeed = -1 * this.xSpeed;
}
}
}