Ticker Tape Turtles
The purpose of this project is to give you more practice in designing and writing an algorithm. The focus of the assignment is to integrate user input with the string interpreter from last week.
The first part of this project is to write a program that lets the user repeatedly send strings to the turtle to execute in real time. The second part is to write a program that generates a string and then passes it on to the processString() function for interpretation.
- Create a new directory for this week's project. Copy your turtleUtils.py, linear.py, and username_shapes.py file to the new directory. Rename linear.py to follow.py. Open the file follow.py.
- Modify your processString function so that it does not move the turtle at all anywhere in the function. The only thing this function should do now is iterate over the characters in the string and call drawShape with each character in turn.
Modify the drawShape function so that the characters listed below have
the specified meaning. You should also leave three characters to
represent your shapes. You may need to change the characters for your
shapes so they don't conflict with the list below. Once you are done
with that, try passing a string like 'fffllfffrrff' into the
processingString function in your main function and see what happens.
'u' is up()
'd' is down()
'f' is forward(10)
'b' is backward(10)
'r' is right(30)
'l' is left(30)
- Modify your main function so that after calling turtleSetup() it goes into a while loop forever (while True:). Within the while loop print out a quick reminder of the characters and their meanings and ask for a string. Grab the string using raw_input() and store the resulting string in a variable. If the length of the string is zero, break out of the loop. Otherwise, send the string to process string. Finally, remove the turtleWait() call at the end of the main function. You don't need it for this program.
Give the user the ability to save their work to a file. The basic
algorithm here is:
- Open a file in which to save the user's commands prior to the interactive loop.
- Each time through the loop, save their command string to the file.
- When the user decides to quit, close the file.
- Create an image by typing strings into the terminal interface using your follow.py program. Hand this in as sceneA. Include in your writeup the string that created sceneA.
Copy follow.py to linearC.py. Modify the main function in linearC.py
so it does the following:
- Asks the user for a filename
- Opens the file
- Reads in the first line of the file and stores the string
- Sends the string to the processString function
- Calls turtleWait()
- Put a string into a file and run it with linearC.py. Call this image sceneB. Include in your writeup the string that created sceneB.
Create a new python file in your editor called koch.py. Import the string module.
from string import *
In koch.py, you will need only a main() function. The function should
do the following.
- Assign a variable with the name base the value 'frrrrfrrrrfrrrr'
- Assign a variable with the name symbol the value 'f'
- Assign a variable with the name rule the value 'fllfrrrrfllf'
- Assign a variable with the name complexity the value 3
- Iterate over range(complexity)
- Within each iteration, call the replace() function defined by the string package with the arguments base, symbol, and rule, in that order. Assign the output of the function back to the base variable. The replace function finds every occurrance of the string symbol in the string base and replaces it with the string in rule.
- Write the resulting string, which ends up in the variable base to a file.
- Use linearC.py to run the string generated by koch.py. Call it sceneC. What happens if you change the number of iterations and make it smaller? If you make it bigger, first change your forward command in drawShapes() to be forward(5) intead of forward(10).
The remaining steps are optional and qualify as an extension for the project (but it's really cool).
Below are some suggested extensions. Focus your extensions on the use of conditionals and iteration to make the results more interesting.
- Give the user of the interactive program the ability to read in a file with a command string so they can start where they left off last time.
- Use string manipulation to create other patterns.
- Create an interesting scene by building a long string in a file.
- Let your symbols like 'f', 'r', and 'l' take arguments (numbers) after them in the string. So a string like 'f10r90f10r90f10r90f10r90' would draw a square 10 pixels on a side.
- Generate random strings that use appropriate characters.
Create a web page for your writeup. Your writeup should include the following.
- A brief description of the task (in your own words).
- Describe your user interface and explain how your programs work.
- Include at least your two required scenes.
- A description of and pictures for any extensions you did.
When your writeup is ready for viewing and linked to your index page, send me an email.
To hand in your python code, place it on the Academics fileserver in the private folder. Do not post it on the web. You may include snippets from your code in your writeup to demonstrate how certain aspects of the function work, but please do not include the whole thing.
To place the code on the fileserver, go to the server fileserver1 and select the Academics volume. Within that there ought to be a CS151 folder, and within that there should be a folder with your username, and within that ought to be a folder labeled private. You can read and write files to the private directory and I can read them, but no one else can access them. Put your python files in that directory to hand them in.