The first task was to use the linear.py file from last week and modify it to allow users to enter in strings that act as commands for the turtle. For example, if the user enters the string, 'fafc' then the turtle will move forward, then draw a rectangle, then move forward, and then draw a circle. This works because we modified the processString () function and added a while loop to the main() function. Now instead of having a hard coded string, the user can enter in their own string of any length, however if the length of the string is zero, then the program breaks out of the loop. Also, the added bonus to this new follow.py file is that each time the user runs the file he/she can enter in a name to save the file as and then enter as many strings as they would like to be written to the file. This task is used to create sceneA.
This program first creates a turtle window and then says hello to the user and prompts them to enter a file name to save their strings to. They then enter as many strings as they would like, but if the characters in the string are not any that are coded for, they get an error message, and if the length of the string is zero then the while loop breaks out and the program is ended. The strings the user enters are sent through a while loop and into an if statement that then sends the string to the processString () function which iterates over each element in the string with a for loop. Once the string is entered and the shapes are drawn the file is written and then closed.
The next task was to use the follow.py file created in task one to create a new file, linearC.py. In this file the user was asked to enter in a previously created filename to read a string from. This string would then be inserted into the processString () function and the turtle would follow the commands in the string that was read from the file. This task is used to create sceneB.
This program first creates a turtle window and then says hello to the user and prompts them to enter a file name to open. They then enter a file to open and the first string from that file is read into the program and sent to the processString () function which iterates over each element of the string with a for loop. However, if the length of the string is zero, the while loop in the main() function breaks and the program is ended.
The cool extension task was to create a koch.py file that uses only a main () function to create patterns through iteration. The string package was imported and the replace () function was used in order to create repeating patterns depending upon the number of iterations. If the number of iterations was made smaller, the pattern is repeated fewer times, but if the number of iterations is made bigger, then the pattern is repeated over many times.
This program first imports the string package. Then a main() function is used in conjunction with a for loop and the replace() function from the string package to create a file. Then linearC.py, from the second task is used to read this file and repeating patterns are created.
My other extension included using string manipulation to create other patterns. I based my code off of the koch.py file that I created in the cool extension. I named it mine.py and changed the commands to code for a different pattern.
This program works the same as the cool extension program except that it creates a different file to be read by linearC.py and therefore, a different pattern is created.