In this project, I implemented six more drawing styles by adding other cases to the if/elif statement in the forward method of the TurtleInterpreter class. In this way, I made use of different styles to enhance my scenes from the last project so that they look more like real paintings. Specifically, I made use of a Gaussian distribution to draw jittered lines. I also practiced creating parameterized stochastic L-systems involving parsing that is to analyze data to extract specific information. Parameterized strings, an approach to put a modifier in parentheses, enables me to add a particular value to a command to draw more complicated shapes like an isosceles triangle.
2. Task 1
For the first task, I created a "jitter3" method in the TurtleInterpreter class that draws a line segment as three jittered lines, and called the method in an elif case that I added in the forward method, as shown below.
In the jitter3 method, I made a for loop, in which I regenerated (jx, jy) and (kx, ky)--the initial and final positions of the turtle when it draws a line segment--from a Gaussian distribution for three times, so that each time the turtle starts and ends at three slightly different positions.
3. Task 2
For the second task, I created a 'dotted' style that draws a series of circles separated by spaces. In a for loop, I first divided a line segment into 7 shorter segments by making the turtle move forward distance/7 pixels to determine the initial and final positions. In one small segment, the turtle draws one dot, so a line is composed of 8 dots. To draw a dot, I made the turtle to draw a colored circle of a radius equal to dotSize. And the randomly chosen pen width also affects the size of a dot. By iterating the commands for 7 times, I could have the turtle draw a dotted line.
4. Task 3
(required image 1)
For the sun, I drew a hexacontakaihexagon(a 66-sided polygon) in a 'jitter' style.
1) Use user input.
I implemented a user input in the colorGradient function of demo_line_styles.py.
By entering the number of sides that I want in the Terminal, I could draw polygons without changing the value of n in my code.
2) Add other drawing styles.
a. Add a 'jitter' style to the semicircle method.
I added a 'jitter' style to the semicircle method in the TurtleInterpreter class, which I have explained in Task 4.
b. Add a 'parallel' style to make a color gradient.
I created a 'parallel' style that simulates a 3-d effect by drawing many parallel lines. Also, the color between the different lines varies slightly.
Finally, to draw shapes, I set the color tuple to be (0.9, 0.9, 0.9) and set the style to 'gradient' in my colorGradient function in demo_line_styles.py,
c. Add a pen-and-ink style to draw a series of straight lines at an angle to the direction of the actual line.
Now comes the difficult part. The pen-and-ink style required an extremely elaborate design.
The final result looks like this:
3) Modify drawString so that when drawing a tree the branches droop down like gravity is pulling at them. This involves determining the turtle's current angle. If the current heading is in the first or fourth quadrant, then gravity will make a right turn angle larger. If the current heading is in second or third quadrant, then gravity will make a right turn angle smaller.
(I used test10-4.py and sysTree2.txt to test.)
4) Create a sequence of images to build an animation.
I made two animated scenes--one in demo_myLsystem.py, the other in home.py--where the trees grow.
5) Make more shape classes that do interesting things.
Aside from the IsoscelesTriangle and Rectangle classes that include parameterized strings, I also made a Strip class where the strings are the result of executing a function. I have explained above.
This project taught me to create non-realistic drawings by implementing different drawing styles that simulate different kinds of brushstrokes. By designing an L-system, I understood more about symbols, parametrized strings, stochastic choices, and multiple rules. I also got more familiar with classes. The most important thing that I learned was to think carefully and rigorously, as it was hard to find the problems if I neglected some details, especially for complicated designs.