Project Writeup
The purpose of the Crayon class that would modify the forward function so that the pictures drawn would look like they were drawn in Crayon. First I created a Crayon class that was a child a of parent class "AggreagateBase" created by Professor Maxwell. This means that we get all of the code in the AggregateBase class for use in the Crayon class. The Crayon class holds two methods, the first being the __init__ constructor method, and the second being a setWidth method. The constructor function takes two points as an argument, calculates the midpoint between them, perturbes the starting, middle, and end points by random values, and then creates lines connecting these randomly perturbed values. These lines are stored in a list contained within a self.shapes field.
After creating the constructor method, a setWidth method is created. The setWidth method takes all of the lines stored in the self.shapes fields, and sets them to a random width to enhance the crayon effect. The reason that the setWidth method has to be overwritten in the Crayon class is that we need a method that set random widths (I used a random.choice method to select a random value between 1 and twice the value that was inputed by the user.
Thus the crayon class takes what would otherwise be a perfectly straight line, splits it into parts that are pointing in random directions with varying widths. It looks like a crayon drawing for the obvious reason that a crayon cannot draw a perfectly straight line with a specific width.
To implement the crayon class, the forward method in the ZTurtle class is modified. First a self.icrayon field is created in the __init__ method, and the default value is set to false, meaning that the ZTurtle will draw straight lines with no "crayon effect." Inside the forward method a conditional if statment is created that tests whether the self.icrayon field has been set to true. If it has, then the two new points (which compromise the x and y-values of the endpoint) calculated from a formula that incorporates the distance parameter (entered as the parameter for the forward method), and passes these two points into the crayon class, which will create the line with the crayon effect. If the crayon class is set equal to false, then a regular line is drawn. If I were to have another class that created a paintbrush effect, I could have easily implemented this into the conditional statement in the forward method. All I would have had to do is create another field in the __init__ method for the paintbrush, set the default equal to false, and add an "elif" statement that states if "self.ipaintbrush" is equal to true, create a forward line that draws a line with a paintbrush effect (calls the paintbrush class). This is why the concept of inhertance is so powerful. While a large amount of code is written once, by calling it a method has access to a lot of actions, with only a few lines of additional code.
The Crayon class also benefits from the concept of inheritance by having access to methods such as draw, undraw, setFill, etc., without having to re-write the code multiple times. For example, any other class (paintbrush, spraypaint, marker, etc.) would require these common methods in the AggregateBase file that were implemented in the Crayon class. By creating the parent class with methods and code that has algorithms common to many possible classes, code duplication can be avoided. This saves time, and makes debugging easier.
My final image creates two trees with the crayon drawing effects. The first is a two-rule l-system
which I got from the algorithmic beauty of plants (right side of the screen). The second is a
stochasitic l-system which has one replacement symbol, but two possible replacement rules which are
randomly selected. It had the following attributes: