Task:
The task of this project was to create a program username_shapes.py, in which we created shapes of our choice. We then created another program linear.py into which we called username_shapes.py. The purpose of this program was for the turtle program to draw a line of shapes defined by a string saved by the user in the main() function. After this was completed, we created a third program grid.py which was similar to linear.py however, it drew a grid of shapes, ten wide and however many rows needed to fit all the shapes. The string in linear.py and grid.py consisted of letters corresponding to a shape as defined in the programs. For the final phase of the project, we were required to call in a partner's shapes into a secondary linear program linear2.py. We needed to make sure that the functions within this program were compatible and could work interchangeably.
Grid Drawing Algorithm:
The grid drawing algorithm consisted of nested loops required to properly draw a grid of shapes, ten wide and however many rows needed to fit all the shapes. In my processstring function, I had to change the way the string was read in order to properly pass the letter to the drawshapes function within the loop. If the original method was left, the same shape would be drawn repeatedly without moving on to the next shape, resulting in a grid of the same shape. I also created variables that evaluated the length of the string and properly established the loops to execute the drawing of the grid of proper dimensions.
Explanation of Algorithm:
As mentioned above, the algorithm used in drawing the grid consisted of two nested loops. Outside of the loops, the length of string was evaluated and saved as variable l. This was then used to determine how many rows were needed to draw all the shapes. I was sure to incorporate a conditional statement to account for remainders in the devision process required to determine amount of rows. This final variable value was then used as the range for the outermost loop which established columns. The second loop draws each row consisting of ten shapes each. The range of this loop is hard coded since it remains constant. Within this loop, the individual character in string was evaluated using a variable within the brackets of string[]. After each shape was drawn, the variable was increased by one until it reached a set limit defined by an conditional which used the length of the string to determine what the limit is.
Explanation of Extension:
As part of an extension, I added additional shapes to my efreeman_shapes.py program. I had a square, triangle, circle, pentagon, and trapezoid. In order to acomodate the different dimensions and/or starting points for the circle, pentagon, and trapezoid, I created a conditional evaluation in processstring in both linear.py and grid.py that placed the turtle at the correct starting position to ensure proper and uniform spacing throughout the mosaic. In addition, I added a random color assignment to each shape and filled each shape with the randomly generated color.
Captured image of linear.py
Captured image of grid.py
Captured image of linear2.py