This lab assignment requires you to write three programs in Python. First, run update21. This will create the cs21/labs/05 directory and copy over any starting-point files for your programs. Next, move into your cs21/labs/05 directory and begin working on the Python programs for this lab. The pwd command helps you verify that you are in the correct sub-directory.
$ update21 $ cd cs21/labs/05 $ pwd /home/your_user_name/cs21/labs/05We will only grade files submitted by handin21 in this directory, so make sure your programs are in this directory!
As you write your first programs, start using good programming practices now:
Your program should first prompt the user to click on the corners of each rectangle. After clicking on two points, the program should draw a rectangle in the color of your choice. Repeat getting mouse clicks from the user and draw two more rectangles in different colors.
After drawing the three rectangles, draw lines across the top, bottom, left and right of all three rectangles. The horizontal and vertical lines should extend the entire way across the screen.
Prompt the user to click once more to close the window. A sample run is shown below
Note it is OK to have rectangles overlap, but the lines must be drawn after the rectangles. In some cases a line on the edge of one rectangle will pass through the middle of another rectangle as shown in the example below.
Hint: Save the mouse clicks from the rectangle drawing in a python lists using the list append() method. Loop over this list after drawing all the rectangles to draw the lines.
Write a program bounce.py that animates a bouncing ball. Start by drawing a circle in the center of the graphics window. Prompt the user to click on the screen. The distance from the click to the center of the circle will represent the velocity of the circle. Thus if the distance from the center to the click is dx and dy in the horizontal and vertical directions, respectively, you should move the circle by an amount dx,dy on each time step.
When the ball hits the vertical or horizontal boundaries of the window, reverse the corresponding velocity so the ball bounces away from the window edge. Have the ball continue bouncing along the walls until the user clicks anywhere on the window with the mouse. At that point you should close the window and end the program.
An example is shown in the video below:
If you click closer to the center of the circle, the circle moves more slowly.
Be creative (not all features should be circles!).
For symmetrical features (such as eyes or ears), you may 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.
Write a program, textBounce.py similar to the second program but have the ball leave a trail of text. The text can be a phrase that you choose or that the user types before starting the animation. The phrase should loop repeatedly as the ball continues to bounce
Remember you may run handin21 as many times as you like. Each time you run it new versions of your files will be submitted. Running handin21 after you finish a program, after any major changes are made, and at the end of the day (before you log out) is a good habit to get into.