xxxxxxxxxx
36
let ball1;
function setup() {
createCanvas(600, 600);
ball1 =new Ball();
}
function draw() {
background(220);
ball1.move();
ball1.display()
}
class Ball{
constructor(){
this.x =100;
this.y =100;
this.Xspeed =2;
this.Yspeed =2;
}
move(){
this.x=this.x +this.Xspeed ;
this.y =this.y+this.Yspeed ;
if(this.x>=600){
this.Xspeed =this.Xspeed *(-1)
}
if(this.y>=600){
this.Yspeed =this.Yspeed *(-1)
}
}
display() {
fill('red');
ellipse(this.x, this.y, 20, 20);
}
}