title: How do I make a ball bounce off the sides of the canvas?
body: <p><a href="https://www.khanacademy.org/computer-programming/problem-3-a-bouncy-ball/5123011626336256" rel="nofollow noreferrer">Here</a> is the link to my project so far.</p>
  
  <p>I want to make a ball(an ellipse) bounce around all four walls of the canvas and as this happens I would also like to change the colour of the ball and speed after each bounce(randomly of course). P.S I want the ball to continue bouncing around the canvas off all four walls. Thanks for the help!!</p>
  
  <p>This is the code I have tried. It gets the ball across the y-axis from top to bottom and keeps going, but I don't know how to get it to bounce off the left and right sides. I would just like the ball to bounce on all four sides in a clockwise direction(left wall, top, right wall, bottom, etc etc.)</p>
  
  <p><strong>EDITED</strong></p>
  
  <pre><code>// position of the ball
  var y = 33;
  // how far the ball moves every time
  var speed = 2;
  
  draw = function() {
  background(127, 204, 255);
  
  fill(66, 66, 66);
  ellipse(200, y, 50, 50);
  
  // move the ball
  y = y + speed;
  
  if (y &gt; 371) 
      {
          speed = -5;
      }
  
  if (y &lt; 31) 
      {
          speed = 5;
      }
  };
  </code></pre>