Project Writeup
The task for this project was to first create functions for a bunch of shapes that
would be very small (fit in a 20 x 20 pixel area). This file was named radaley_shapes.py.
After this we were to create a new file, named linear.py that would have a function
call the shapes that were described in the radaley_shapes.py file. The function was
conditional function that consisted of "if" statements. An if statement controls
whether a single block of code is executed or not. The computer evaluates the statement
as true or false, and if the statement is false then the computer moves on to the
next block of code in the function. For conditional functions with more than to blocks,
the code takes on the form of an if-elif-else. If the first if statement if false,
the function moves to the first elif statement. If the first elif statement if false,
then the computer moves on to the second elif statements. If the computer evaluates
all elif statements to be false, then the computer executes the final else statement.
The function was named drawShapes(), and below is the code that was included:
def drawShape(action):
After creating the drawShape function, I created a variable that was a string.
The string consisted of the characters that were defined in the drawShape function.
The first objective was to create a linear horizontal pattern of shapes. The object
was to draw one shape, move the turtle 20 pixels forward, and then draw the next shape.
Therefore, my string consisted of the pattern I wanted to be drawn. I defined the varible
linear, and assinged the following string:
unit = "hufdtufdsufd"
After creating the variable "unit", I created another varibale "linear" to be equal to
a multiplication of the "unit" variable, so that a greater number of shapes would
be drawn. Finally, I created a function processString used a for loop to call the
drawShape function on every character in a string. In other words, the for loop took
each character of the "hufdtufdsufd..." string created in the variable "linear," and
in each character called the drawShape function, which calls the shapes defined in the
radaley_shapes.py file, which ends up commanding the turtle graphic.
The image below is of sceneA, a picture created using the linear.py described above. It includes a string of seven hexagons, triangles, and squares.
The next portion of the task was making a grid with our shapes. In other words, while the linear.py file created a horizontal line of shapes, the goal of the grid.py file is to make the same horizontal line of shapes, but change the loop in the processString function so that the horizontal lines are stacked vertically into a grid. The method I used was a nested loop, which consists of a for loop inside of an "outer" for loop. The means that for every time the outer loop completes one loop, the inner loop carries out its entire loop. I made the inner loop exactly what it had been in the previous task, which created the horizontal line of shapes in linear.py. However, the outer loop moved the turtle to the start of the horizontal line of shapes, and then twenty pixels down from its previous level. This required defining the starting postion of the turtle in terms of x0 and y0, and then modifiying the y0 cooridinate for everytime the outer loop completes one round. The variable used in the for loop was "i", which took on a different number each time the outer loop completed one round. Therefore, using the goto() command, I made the y-cooridinate of the starting position of the turtle "y0 - (20*i)". With the nested loop inside the modified processString function (the drawShapes and main function from linear.py remained exactly the same) I was able to create the image of a grid below.
The final piece of the homework included finding a partner, taking some of the
shapes she created, and implenting them into an image that was similar to the one
created in the linear.py file. My partner was Brittany Thomas, and we worked
together on modifying the processString loop as well as creating the code for the
grid.py file. Using some of the shapes she created, I made the image below.
Even though the extension for this project looks complicated, it actually did not require much modification of the grid.py code. I made two major changes. The first is that I made a function that assigned and filled a random color into the shapes. The second is that I modified the outer loop of the processString nested loop function. I changed the starting position (x0, y0) to the center of the string, and after each completion of the outer loop, I had the turtle turn right 22.5 degrees. I also had the outer loop complete 16 times in order to complete the circle (360 divided by 16 is equal to 22.5). I thought that the image could perhaps be interpreted as either a mosaic sun or a flower.
Next Assignment: Ticker Tape Turtles