The goal of this assignment is to practice creating and using functions. You will use the graphics library to construct a program that creates, jumps, and spins aliens. For each function, follow the guidelines provided for the input parameters and the return value. Once you have these functions working you will create an animation using several aliens of different sizes.
A skeleton version of the program aliens.py will appear
in your cs21/lab/05/ directory when you run update21
in a terminal window. The program handin21 will only submit
files in this directory.
Open the file aliens.py and write a function createAlien(window, center, radius) that creates and then draws an alien in the given window at a specific location with a specific scale. Your alien must be comprised of only circles, but how many circles, their color, and their relative position is up to you. The createAlien function has the following parameters:
In the main function, create several different sample aliens
using your createAlien function. They should be created at
different locations with different scales, such as in the example below.
Write a function jumpAlien(alien, dx, dy) that jumps an alien the specified amounts in the x and y directions. The jumpAlien function has the following parameters:
Once you have written this function, update main to test your new function by jumping your sample aliens to new locations.
Write a function spinAlien(alien, degrees) that spins an alien a specified number of degrees about its center. NOTE: this spin is not animated. This function should simply rotate all of the features of the alien a fixed angle. The parameters for spinAlien are:
The alien should be rotated around the center of the first Circle object in the list alien (at index 0). To rotate one of the alien's parts with a center (x,y) by an angle t around the main center point (xc, yc), you must move the part's center point (x,y) by an amount mx, my defined as folows:
mx = dx * (cos(t)-1) - dy * sin(t) my = dx * sin(t) + dy * (cos(t)-1)where
dx = x - xc dy = y - yc
The python math functions sin and cos expect the angle to be in radians. You can use the python math function radians to convert the angle from degrees to radians.
Once you have completed this function, test it in main. For example, you should now be able to have aliens at different orientations, as shown below.
Once all of the functions described above are working correctly, use them to create an interesting animation in main. Feel free to write additional functions as needed. Your main should satisfy the following requirements:
Once you are satisfied with your program, hand it in by typing handin21 in a terminal window.