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. (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:

  2. (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.

  3. (15 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
    
  4. (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! 
  5. (15 pts) Write a program that reads in a string of text and outputs the text as follows:
    Enter the text: we love CS
    w
    we
    we 
    we l
    we lo
    we lov
    we love
    we love 
    we love C
    we love CS
    we love C
    we love 
    we love
    we lov
    we lo
    we l
    we 
    we
    w
    

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. Clean up your Lab 5 page so that it only contains the image, a link to your home page, and any appropriate text. (In other words, get rid of the stuff that should only be on your index.html page.)
  8. Modify your index.html page to link to your Lab 5 web page.

Extra Credit: Rainbow Dice (8 pts)

Simulate a game of Rainbow Dice, a Sprenkle family tradition. Note that Rainbow Dice is much simpler to implement than the Craps game. Demonstrate your program with a goal of 3, so that you don't print out too much output.

You only get one extra credit for this--either for lab4 or lab5, not both. :)

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)