The task this week was to use classes along with L-systems to make a new scene. However, a new class was to be created in order to enable the turtle to draw like a crayon. This new class was to have an init and setWidth methods. The init method was created to calculate the midpoints of the lines as well as to perturb the points that the lines were to drawn from. This created the crayon drawing effect which now makes perturbed lines instead of just completely straight and continuous looking lines. This effect gives the scene an interesting effect and makes the scene look a little less computerized. The setWidth method used a random value to set the width of the object. The next part of the task was to modify the ZTurtle class. A new field had to be created and the class needed to be told to use the crayon that was created instead of just a line in the foward method. A new method also had to be created to set the self.icrayon field to the given value. The new crayon drawing method was to be tested using the L-system trees.
In order to permit a third drawing option, like a paintbrush, a new field would have to be created in the __init__ method. For example, it could be self.ipaintbrush == False. Then the forward method would have to be modified to make a paintbrush object if the ipaintbrush field is true. If, elif, and else statements would be used to do this because now the user would be able to have just lines, crayon objects, or paintbrush objects to be drawn. Finally, a new method would have to be created in the ZTurtle class in order to set the field, self.ipaintbrush, to the given value.
Inheritance is useful because it permits code in a child class to overwrite code from a parent class. Thus, with Crayon as the child class, it can overwrite methods and code of AggregateBase, its parent class. This is beneficial because this allows lines to be drawn from perturbed points and these lines can now be different widths.
My final image was my final image from last week, but it is now drawn in crayon. It creates L-system objects,sets the crayon to be true, and then sets the L-systems. Then the scene is drawn with the crayon effect. The final image was created by mysceneP11.py and can be seen below.
For my extensions I first incorporated my diamond tree from week five's project into my new city scene and then drew it in crayon also. I did this by modifying the lsystem method within the ZTurtle class in order for a 'j' to be read and interpreted in an L-system string. Thus, instead of having leaves on the tree there are randomly colored diamonds instead. I also used a for loop to re-create my bamboo shoots in this new scene. This first extension scene was created by mysceneP112.py and can be seen below.
My other extensions include using more L-systems to create a little neighborhood to the left of my big city. I used for loops to create tall trees to set as the background of this neighborhood and then I also used a for loop to draw the buildings and then I used a final for loop to create a border to small trees that are randomly placed along the frontsides of the buildings. I also added leaves to my bamboo shoots and created a sun to be drawn in the scene. My sun uses a for loop that iterates 30 times, goes 12 units forward and turns left 20 degrees each time. However, I drew the sun in crayon so it is not a perfect circle outline and thus gives it the crayon effect. This final extension scene was created by mysceneP113.py and can be seen below.