class ball{
constructor(X,Y,D,Tspeedx,Tspeedy)
{
this.ballx=X
this.bally=Y
this.d=D
this.ballspeedx=Tspeedx
this.ballspeedy=Tspeedy
this.angle=(0)
}
translating(){
push()
if(this.ballx>width-this.d/2||this.ballx<this.d/2){
this.ballspeedx=-this.ballspeedx;
}
else if(this.bally>height-this.d/2||this.bally<this.d/2){
this.ballspeedy=-this.ballspeedy;
}
translate(this.ballx,this.bally)
this.ballx +=random(-this.ballspeedx,this.ballspeedy)
this.bally +=random(-this.ballspeedx,this.ballspeedy)
}
drawing(){
fill(255)
ellipse(0,0,this.d,this.d)
pop()
}
}
let ballA
function setup(){
createCanvas(600,600)
background(200)
ballA=new ball(300,300,50,50,50)
}
function draw(){
ballA.translating()
ballA.drawing()
}
console