You should save your program for this assignment in your
cs21/homework/04 directory. A skeleton version of the
program will appear in this directory when you run update21
in a terminal window. The program handin21 will only submit
files in this directory.
Open the file busyBugs.py and write a function buildBug(center, radius, window) that draws a bug at a specific scale in a specific window at a specific location. Your bug must be drawn using only circles, but how many circles, their color, and their relative position is up to you. An example bug is shown below. The buildBug function has the following parameters:
For symmetrical features (such as eyes or ears), remember to use the clone method to make a copy of the original shape. Then draw the cloned shape in the window and move it to the desired location.
Once you have finished writing buildBug, write a main function that tests your buildBug function by creating and drawing a few bugs in a graphics window. You may want to use the setCoords method of the
GraphWin object to adjust the coordinates of the window.
Write a function animateBug(bug, dx, dy, steps, wait) that moves a bug a specified amount for a specified number of steps. The animateBug function has the following parameters:
Finally write a function rotateBug(bug, degrees) that rotates a bug a specified number of degrees about its center. NOTE: this rotation is not animated. This function should simply rotate all the features of the bug a fixed angle. The parameters for rotateBug are:
The bug should be rotated around the center of the first Circle object in the list bug. To rotate a point or circle with a center (x,y) by an angle t around a center point (xc, yc), you must move the 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 in radians. To convert from degrees to radians, use rad=deg*pi/180.
Some rotated bugs are shown below.
Once all of the required functions are working correctly, create an interesting animation with your bugs in the main function. Feel free to write additional functions as needed.
Once you are satisfied with your programs, hand them in by typing handin21 in a terminal window.