CS110: Spring 2020

Intro to Computer Programming with Python

CS110: Spring 2020

Assignments > HW4: Animations & Landscapes

Due on Tue, 05/05 @ 11:59PM. 8 Points.

Homework Starter Files

One of our peer mentors, Katherine, has also created a get started video to get you oriented with the assignment.

LEARNING OBJECTIVES:

  1. Practice working with loops
  2. Practice working with if statements
  3. Practice working with the random module

Part 1: Landscapes

In landscapes.py, replace the code on lines 23-32 (which is repetitive) with a loop (any kind of loop you want) that makes 1,000 stars that fill the entire canvas. Hints:

  1. Use a loop
  2. Use the random module, and in particular the random.uniform function to give each star (or bubble if you choose) a random (x, y) position (given the dimensions of the screen) and a random width (so that it renders stars of different sizes).

Optional enhancements

  1. Draw a constellation (Orion’s Belt, Big Dipper, etc.)
  2. Make your stars twinkle
  3. Animate your bubbles

Part 2: Animation

Please open the cars.py file and make the following changes:

  1. Animate the car so that it moves across the screen.
  2. If the car gets to the end of the screen, it should seamlessly be moved to the beginning of the screen.
  3. Create a second car using the helpers.make_car function. Be sure to give your new car a unique tag.
  4. Make the second car move in the opposite direction, and also loop back around when it gets to the end of the screen (see the animated gif).

Optional enhancements

The more you practice, the better you’ll get!

  1. Make the cars accelerate over time (start off slow and gradually move faster)
  2. Add your creature to your animation:
    • Inside helpers.py:
      • Add your make_creature function definition (adapt from Homework 3).
      • Modify your make_creature function so that each constituent shape of your creature gets assigned a tag (study the make_car function and do the same thing).
    • In cars.py: animate your creature
  3. Use loops and the random module to make many moving cars.

What to Submit

When you’re done with the assignment, please submit a zip file called hw04.zip that contains the files below named exactly as they appear:

  1. helpers.py
  2. cars.py
  3. landscape.py

IMPORTANT: YOU MUST TURN IN THE FILES — BOTH THE ZIP FILE AND THE PYTHON FILES — NAMED EXACTLY AS SPECIFIED ABOVE. OTHERWISE, OUR GRADING SCRIPTS WILL NOT WORK.