xxxxxxxxxx
59
/*Bouncing Chamber: A ball bounces up and down. Player controls
the height of the chamber by clicking and dragging the floor.
the smaller the chamber, faster the ball bounces.*/
let floor;
let floorHeight =0;
let y = 0;
let ballSpeed=5;
function setup() {
createCanvas(400, 400);
//floorHeight = mouseY;
}
function draw() {
background(220);
//Floor starting parameters - NO Interaction
//floor = rect(0, height/2 -1, width -1, floorHeight
//Floor animation
//floorHeight = floorHeight -4
//fill(floorHeight,floorHeight,floorHeight,floorHeight);
//floor= floor *2;
//Floor starting parameters - With Mouse Interaction
fill(255,200,30);
floor = rect(0, mouseY, width, 30);
//Ball
fill(random(255),0,random(255));
ellipse (width/2,y,20,20);
y = y + ballSpeed;
//ballSpeed = ballSpeed;
if (y > mouseY-10 || y > mouseY) {
ballSpeed = - ballSpeed;
print(ballSpeed);
}
if (y<0) {
ballSpeed = - ballSpeed;
}
if (y>mouseY-5) {
textSize(15);
fill(0);
text("You are overloading the system, please stop that!",20,20)
}
}