In this project, students of CS151 were asked to use computer science to disguise our projects as computer-drawn. By creating different styles of drawing, the user can now decide how messy or natural they want the drawing to look.
The first task was to create a ‘jitter3’ style that draws 3 crossed and jittered lines instead of just one. To do this, I added an additional Elif statement to the <forward> method of the TurleInterpreter class. I began this method the same way the regular jitter began, which was storing the correct beginning and ending points in variables, but then made a For Loop that runs three times. In this loop, I use the <gauss> method of the random package to get random values to the jitter the lines with, and then draw the lines with the goto command of turtle between the jittered points. Here is a picture of the code:
The next challenge was to create a ‘dotted’ style to draw lines with small circles instead of continuous lines. I began this with another Elif statement and getting the default start and end points, but then made a For Loop that runs itself based on the number of circles that can fit in the distance. This involved dividing the distance by the radius times 4 (I have included this in the snippet below).
Next, I shift the turtle “below” the default line with turtle commands, so that when the circles are drawn, they center on the default. After drawing the circle, I move the turtle back to the default to keep the line straight. Here is the code:
The third task was to simply display these new styles in the shapes that we made in the last project. To do this, I created a file <demo_line_styles.py>, which has a function <main>, that creates a Parallelogram object, and then draws it with many different styles and variations. To do this, I had to create mutator methods in the Shape and TurtleInterpreter classes. These simply set the fields to the variable passed to the method.
Here are my different styles in action, but not in one picture because it was difficult to see all the pictures in one screen.
Here is jitter, with the jitterSigma value of 8 on the left and 2 on the right:
Here is jitter3, with the jitterSigma value of 8 on the left and 2 on the right
here is the normal style with a width of 8 on the left and 2 on the right:
here is the dotted style, with a size of 3 on the left and 6 on the right:
Task four asked us to demonstrate our new drawing styles in the indoor scene that we created for last week’s project. This was not too difficult, but just ensured that we added mutator methods to the Shape class. Without these methods, the styles of the shapes cannot be altered. Once these were created, however, I merely had to call the <setStyle> method of each Shape before I called the <draw> method. Here is the code:
Aside from making the trees in my painting more realistic with jittering, I also made the sculptures of the museum drawn with the dotted style-- this made the museum look much more modern, with sculptures made of floating balls. The future is now!
The final task asked us to create our own lsystem that takes in parameters and has multiple rules. We had the option of using the code from ABOP, but I decided that they were too mainstream. Therefore, I made my own with a trident as the base image, and then replacing each line with the same drawing. At the end of each line, is a leaf. However, with an additional rule, I replace this with two shorter lines that each have a leaf on them. When run with 3 iterations, it looks somewhat like a peacock’s tail. Here is that image:
Thus, I made a scene with my new styles and shapes from previous projects. In the file <newScene.py>, I make functions that create the shape objects, and then draw them at the correct location. They are also scalable and mobile-- I can place bigger and smaller ones wherever I want with no problems.
Here is the scene:
First, I created additional drawing styles. I felt that the jitter and dotted styles were cool, but still very caged. Therefore, I created two additional Elif statements for the styles ‘crooked’ and ‘skewed’. By using a For Loop to draw three lines (like jitter3) and then having the turtle go to a point halfway to the destination, but offset from the default line more than normal, the shapes are still slightly recognizable, but abstract. Here is the code:
Here is ‘skewed’:
And here is ‘crooked’:
Next, I tackled the challenge of making a ‘brush’ style. This was challenging. I began this with an Elif Statement, and then getting the data for the default beginning and ending points. Then I wrote a For Loop that runs 30 times, and created random offset values with the <gauss> method of the random package.
Next I got the minimum and maximum x values for the range between the beginning and ending values by using the <min> and <max> methods on the range. This is necessary in the event that the shape is drawn where the ending value is smaller than the beginning value, thus crashing the range operation.
Then, I found the slope of the line to be drawn with the simple slope equation, stored a random x value on the line in the variable <xnew>. With this, I make the ynew value. Here is the code:
The <ynew> value is created so that it cannot be too far away from the default line. The random value is multiplied by the slope to get the correct placement, then the jitter is applied by the <ky> variable, and then the vertical change is accounted for by adding the <y0> variable (this essentially accounts for the ‘y intercept’ of each line). Here is a picture of the brush method on a parallelogram.
After these values are created, I use the <goto> method of the turtle package to go to the point, and then draw a short line (that is one tenth of the distance).
The next extension I did was to make an animation. When looking at the jitter3 style, I thought it would cool to slow down the drawing and make it look as if someone was drawing it. Therefore, I added two more characters ( ? And : ) to my drawString method to turn the turtle tracing on and off (respectively). With the tracing off, animation is impossible. These characters are added in the form of more Elif statements.
Then I imported the time package to the turtle_interpreter.py file, and called the <sleep> method with 0.1 as the argument after the drawing of jitter3 occurs. This slows down the drawing (when the tracing is turned on in the string), and makes a cool animation (which I have attached).
WHAT I LEARNED
Creating the brush style (and the other styles) showed me how to apply mathematical equations to Python, which can produce some very cool images. Also, I got more comfortable with the coordinate system of Python by creating new styles.
WHO I WORKED WITH
I worked with the Sunday and Tuesday night TAs as well as Jackie Hang (who I just compared solutions with).