xxxxxxxxxx
28
let ballY = 0;
let speed = 0;
let accel = 0.2;
let bouncing=false;
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
ellipse(200,ballY,20,20);
function mousepress(){
bouncing = !bouncing;
}
if (bouncing) {
ballY=ballY+speed;
speed = speed+accel;
if (ballY > 395 || ballY< 0) {
//print("ballY hits the ground");
speed=0.95 * (speed*-1);
}
}
}