Screen Saver
Back before modern flat LCD displays, computers used Cathode Ray Tube, CRT, displays. Besides being big and heavy, the displays suffered from burn-in. If the same image was left on the display too long, a ghost of it would become permanent. So, if a computer was not used for a short duration, it would play an animation to save the screen from burn-in. We don't need screen savers anymore, but computer still come with them because they are fun to look at.
Details
Create a python program that uses the graphics module to draw lots of ovals of random sizes in random locations. The ovals can be any size, but random locations must be limited to and fill the dimensions of the window.
Example

-
Use a for loop and the graphics
module's
draw_oval
function to draw many ovals. -
Use the random module's
randrange
function to generate a random x-coordinate, y-coordinate, width, and height for each oval. -
Use the graphics modules
window_width
andwindow_height
functions to limit the range of the x and y coordinates.
Challenge
After awhile the screen is all black, not a very interesting animation. In order for the amimation to continue longer, it should have lots of colors. Make each oval drawn a random color.

Animate
Creating an animation on a computer screen is fairly comparable to the way that flip-book animations work. In a flip book, you draw your image in one location, and on the following page you draw your image in a new, updated location. The analogue to flipping the page using the graphics module is clearing the screen. We then just need some mechanism to continually update the position of the image that we are drawing between screen clears.
Details
Create a python program that defines the function
move_image(image_name, start_x, end_x, y_location)
.
The function should animate an image moving horizontally across
the screen from the specified start_x location on the
screen to the end_x location along the
specified y_location.
Example
graphics.window_size(320, 240) move_image("blinky.gif", 0, 340, 180)
You can use any gif image you want. Do
an image search for
something you like. Include filetype:gif
as one of
the search terms to only find gif images.
-
The
draw_image
function in the graphics module draws an image centered at a specified location. Your image needs to be stored in the same directory as your program. To achieve the motion required here, we just need to change the x coordinate the image every time it is drawn. - You will either need to use an accumulator, or use the loop variable as the updated value of the x coordinate for the drawn image.
Challenge
Modify your program so that you move not along a horizontal line, but you can move between any two arbitrary (x, y) coordinates.
Orrery
An Orrery is a mechanical model of the solar system that was first made in the 1700s. A sun was placed in the center of the model, and the orbits of the planets were fixed to a circle surrounding the star. Mimicking the motion that was created with this mechanical device requires using some trigonometry to compute the new x and y positions.
Details
Create a Python with the function
def animate_planet(orbit_radius, planet_radius, sun_radius, revolutions)
, which animates a planet
orbiting around a star in the center of the screen. To compute
the position of the planet, use the following equations to
convert an angle, in radians, to the x and y coordinates of a
point on a circle centered on the origin:
x=radius×math.cos(radians)y=radius×math.sin(radians)
Example
graphics.window_size(320, 240) animate_planet(100, 10, 25, 3)
Create a for loop that iterates over the angular
position of the planet. For each iteration, use the provided
equations to convert the angle to x and y coordinates. Don't
forget to clear
the screen and wait
to slow the animation.
The only mathematical issue you may run into is the fact that
the trigonometric functions expect their input in radians
instead of degrees. You can use the math.radians
function to convert from degrees to radians.
Challenge
A real orrery doesn't just have one planet. It usually has many planets, all orbiting at different distances and speeds. Modify your program so that it can animate at least 2 separate planets, at different radii and at different speeds.