xxxxxxxxxx
47
let ball01, ball02
let color = 0
let ballSpeed = 3
let ballSize = 25
function setup() {
createCanvas(600, 700);
ball01 = new bouncingBall(50, 200, color, ballSpeed, ballSize)
ball02 = new bouncingBall(300, 600, color, ballSpeed, ballSize)
}
function mousePressed(){
color = color+20
ballSize = ballSize+2
ballSpeed = ballSpeed * 1.4
ball01.circSpeedX = ballSpeed
ball01.circSpeedY = ballSpeed
}
function draw() {
background(200);
ball01.move()
ball02.move()
}
class bouncingBall {
constructor (circX, circY, color, ballSpeed,ballSize){
this.circX = circX
this.circY = circY
this.circSpeedX = ballSpeed
this.circSpeedY = ballSpeed
this.color = color
this.ballSize = ballSize
}
move(){
this.circX += this.circSpeedX
this.circY += this.circSpeedY
if (this.circX > width || this.circX < 0 ) {
this.circSpeedX *= -1
}
if (this.circY > height || this.circY < 0){
this.circSpeedY *= -1
}
fill(color)
circle(this.circX, this.circY, ballSize)
}
}