In Class: Week 4


Create a week04 subdirectory in your cs21/class directory:

      % cd 
      % cd cs21/class
      % pwd
        /home/your_user_name/cs21/class

      % mkdir week04        
	
Then, from within your week04 subdirectory copy over some python files from my public directory:
    % cd week04
    % pwd
      /home/your_user_name/cs21/class/week04

    % cp ~newhall/public/cs21/week04/* .
    % ls
      animate.py  bullseye.py  squares.py  test_graphics.py
	

The graphics library

To use the graphics library, first import it at the top of your program:
  import from graphics *
Next create a new graphics window object, and then create gui objects to draw into this window:
   win = GraphWin("My GUI Program", 500, 500)   # creates new GraphWin object, 500x500 pixels in size

   circ = Circle(Point(50,50), 20)    # creates a new Circle object centered at 50,50 with a radius of 20 pixels
   circ.setFill("red")                # invoke the setFill method of the Circle object referred to by circ        
   circ.draw(win)                     # draw the Circle object refered to by circ in GraphWin win

We are going to do some of the following together in class:
  1. open test_graphics.py in vim. It contains some example code that draws different type objects to one of two graph windows. Let's try changing some things.

  2. open bullseye.py. Together we are going to write a program that draws a bullseye to the graphics window. It should consist of 4 concentric circles, of two or more colors, that are drawn centered in the graphics window.

  3. open squares.py. Together we are going to write a program that draws a large blue square to the graphics window that is centered on the point indicated by the user's mouse click.

  4. open animate.py. Let's look at this program together. Once we figure out what it is doing, lets copy it to a file named nested_animate.py, and then we are going to open nested_animate.py:
       $ cp animate.py nested_animate.py
       $ vim nested_animate.py
    	
    We are going to add code so that the animation will be repeated 3 times, each end point will be determined by the user's mouse click.