Project 2.6: Orbit
Make a circle that follows the mouse on the screen


  • Orbital Motion

    • The ball should start at a random position anywhere on the screen

    • Your ball should try to follow the mouse by changing its speed when it is going the wrong way

      • It should accelerate at a rate of 1 pixel per frame

    • The ball should have a maximum speed of 25 pixels per frame.

    • The ball should change color each frame.

      • This can be totally random or within a limited but still random color set.

  • User Interface

    • The program should be in full screen mode and have a background color set.

    • Left clicking should wipe the screen, setting it to your background color

    • The 's' key should save a screenshot to your project folder

      • Your program should work for both capital 'S' and lowercase 's'

    • The 1, 2, and 3 keys should change the size of the ball.

      • 1 --> Small (15 pixels)

      • 2 --> Medium (30 pixels) <--- Starting size

      • 3 --> Large (60 pixels)

FAQ / Tips

Progression Advice

    1. First - Make Your Physics

      • Set up your variables

      • Draw a stationary ball on the screen

      • Have it follow the mouse in the x dimension only

      • Have it follow the mouse in the y dimension also

      • Only speed up the ball if it is under the maximum speed

        • Try this one direction at a time!

        • Remember that going left and up means your speed is negative

    2. Second - Make It Fancy

      • Make your ball a change color randomly

      • Set a starting background and reset it on left click

      • Change circle size with '1', '2', and '3' keys

      • Save a screenshot using 's' or 'S' keys

I'm a little confused on negative maximum speeds

    • So if we're going to the right, that means xSpeed is positive. So maxSpeed must be positive. We then ask:

if(ySpeed < maxSpeed)

    • But if we're going to the left, xSpeed is negative. It's always going to be under maxSpeed. So we need to instead ask:

if(ySpeed > -maxSpeed)

  • Why does my orbit look square-ish if I leave it stationary?

    • This is okay! We're using some simple math, treating x and y speed independently. It isn't actually a proper circle. You'll need to use more advanced math for that.

    • You're welcome to do so, or ask a math / physics teacher for help, but it's beyond the scope of our requirements.


Click here to download a running version of the program.