Lab 5: Animation and Strings

Goals

After the lab, you should be proficient at

  1. using objects and APIs
  2. solving problems with a graphics API
  3. solving basic string problems
  4. creating basic web pages to display images

Linux

Objective: Programming in Python

Reference Material for Graphics Programming

We'll practice writing several Python programs, each in their own text file. Name the files lab5.1.py through lab5.5.py.

Your programs will be graded on correctness, style, efficiency, and how well you tested them. Make sure you adhere to the good development and testing practices we discussed in class. Your code should be readable and your output should be useful and well-formatted.

After you've developed a correct solution to each program, restart IDLE or close and reopen the IDLE "shell" by running the program again (using F5), demonstrate that the program works using several good test cases, and save the output to a file named lab5.x.out, where x is the problem number.

  1. (10) Using the graphics module, draw a yellow circle with radius 30 and a red square of width 50 in a window that is 400x200 with the name "Practice". Position the circle in the upper-left quadrant of the canvas and the square in the lower-right quadrant. There will be no IDLE output for this program.
  2. (10) Using the graphics module, draw the beginning of a snow-person. Create a canvas with the title "Snow Person". Draw a white circle of radius 50. Clone the circle and move the cloned circle above the first circle (so that the circle appears to be sitting on top of the original circle). Repeat with a third cloned circle. Draw two black, filled-in circles for eyes in the top circle. Note that you should draw one eye, then clone the eye and move it to the appropriate place. There will be no IDLE output for this program.
  3. (30) Create a program that draws "something significant", such as a scene, a house, or a face, using the graphics library. Here are some guidelines to follow:

    Screen Capture:

    You've saved the image!

    Some previously created images to inspire you:

    Images From Winter 2009

    Images From Winter 2008

    Images From Fall 2007

  4. (15) Add some sort of animation to the picture you created above. For example, you could make an entire face move around the window or you could have a feature of a face move (such as a blinking eye). Note: this is not simply the click and move we did before we did animation. You can allow a user to click to move things, but you must animate that movement.

    If you want to animate a group of objects, moving together, you can use the GraphObjectGroup class. There is an example of using the GraphObjectGroup class in the example.py file in the /home/courses/cs111/handouts/lab5 directory.

  5. (10 pts) Write a program that takes as input 3 strings and prints out the alphabetically first word of the 3 strings. Example output:

    Enter the first word: zebra
    Enter the second word: monkey
    Enter the third word: pig
    The alphabetically first word is monkey
    
    Enter the first word: dog
    Enter the second word: black cat
    Enter the third word: 13
    The alphabetically first word is 13
    
    Enter the first word: black
    Enter the second word: black cat
    Enter the third word: blacky
    The alphabetically first word is black
    
  6. (15 pts) Write a program that takes as input a string and displays that string without any spaces in it.

    Since strings are immutable and given our current knowledge, you'll have to create a new string that contains all the characters except spaces from the original string. For full credit, only go through the string removing spaces if the string contains at least one space. Do not use a method to solve this problem.

    Example output:

    What is your string? The Beatles
    Your string without spaces is TheBeatles
    What is your string? Help!
    Your string without spaces is Help! 

Objective: Creating a New Web Page

It's time to revisit our web pages. (You knew we'd get back to this sooner or later!)
  1. Go into your public_html directory.
  2. Copy your index.html file into a file called lab5.html (in the public_html directory).
  3. Copy the screen capture image from your lab into your public_html directory.
  4. Open lab5.html in jEdit.
  5. Modify the Lab 5 web page to have an appropriate, title, header, and information.
  6. Modify your Lab 5 web page to display the image you created.
  7. Modify your index.html page to link to your Lab 5 web page.

Finishing up: What to turn in for this lab

  1. IDLE and jEdit may create backup files with the "~" extension. Delete these files from your lab directory to save paper when you print.
  2. Copy your lab5 directory into the turnin directory. (Review the UNIX handout if you don't remember how to do that.)
  3. Before printing, move the graphics.py, graphics.pyc (actually, this one can be deleted rather than moved), and your screenshot out of your labs/lab5 directory; otherwise, the print out will be long and screwed up. You can move those files back into your lab5 directory after you've printed. In other words, you should only have the .py files you wrote and the .out files you created in your directory when you print.
  4. Turn in your printed lab assignment, using the printLab.sh command. You should probably print from the labs directory.

    Before you print, view the file to make sure it's not too long or has weird characters in it from the .pyc file. One command to view the file is gv lab5.ps

    Print the file using the lpr command introduced in the first lab.

Labs are due at the beginning of Friday's class. You should hand in the printed copy at the beginning of class, and the electronic version should be in the turnin directory before 1:20 p.m. on Friday.

Ask well before the deadline if you need help turning in your assignment!

Grading (100 pts)