//PCS 5th example of if statements used to control how a ball travels - release code //Instructions: read the code and make sure you understand how to control which direction //the ball is traveling //TODO: add an "if" test for when the ball reaches the left side of the screen // then add a velocity in y (change vy = 2) // and add "if" tests on the ball's y position to make it bounce off the floor and ceiling // you can also change the ball's color after it hits each wall as well //variables we will use to control the ball's position and velocity int px = 200; int py = 200; int vx = 1; int vy = 0; int scaleX = 40; int scaleY = 40; color ballColor; void setup() { size(400, 400); smooth(); ballColor = color(41, 193, 179); strokeWeight(2); } void draw() { background(128); stroke(255); fill(ballColor); ellipse(px, py, scaleX, scaleY); //update the position using velocity px = px + vx; py = py + vy; println("position in X: " + px + " velocity in X " + vx); if (px > width-20-scaleX/2.0) { vx = -1*vx; ballColor = color(155, 22, 117); } //TODO add more if cases here to control the ball //draw the walls noStroke(); fill(22, 34, 155); rect(0, 0, 20, height); rect(width-20, 0, 20, height); rect(0, 0, width, 20); rect(0, height-20, width, 20); }