For Project 10, the main goal was to draw using styles that simulated art styles/tools such as painting and dotting. Up until now, telling the turtle to go forward meant drawing a straight line, but with this project, it could mean all kinds of things.
Task 1 was to make a style called "jitter 3"; it would do what jitter does (a style that makes broken-up, disoriented lines) but with 3 lines instead. This means that the line would be thicker. Like jitter, the code required telling the turtle to store the start point and the end point of the turtle going forward, then calculate points a random (but small) distance away from each, then make the turtle go to those places instead, producing the rotated, misplaced look of the jittered lines.
Task 2 was to create a "dotted" line style. Basically, we want a circle at every other point of the "line" area, so the turtle must check if the loop variable going over the distance (which in this case is distance divided by the size of the circle, giving us how many circles could potentially fit in if none were skipped), then draw a circle there. It also needs to move forward by twice the distance of one circle, meaning 4 times the radius (the dot size in this case). The code for this is shown below:
Task 3 was to showcase all four of the styles we created using a shape we made in Project 9. This was simple; I just called a trapezoid object to be created from my shapes class, set its style, then drew it at the given location. We also needed to show a version of the shape within that style that had a parameter changed; as one can see, the dot size is different for dotted, the jitter is different for jitter and jitter 3, and the thickness is different for the normal style.
Task 4 was even simpler; it was to draw the indoor scene from last week but with the styles implemented so it looked even a bit more hand-drawn. This meant playing around with the shapes by calling the setters of the objects to choose a style (e.g. jitter, dotted, etc.) then possibly adjusting the lines even further (e.g. through setJitter or setWidth). The picture is shown below.
Task 5 was to create a new L system. In my case, I based it off of the sysTree L system (called "systask5.txt"). The two are shown below, with the original on the left.
For my edit, I adjusted the colors, angles, pen thickness, and forward lengths, as well as added another place to go forward in the tree. This was done through the use of parameters in the L system. For example, (3)! would change the thickness of the brush to 3, as ! was used as a turtle-interpreter symbol to mean "change line thickness to whatever was in the parentheses right before it". This concept requires the the turtle either carries out the code interpreted by the text or stores it as a way to adjust what it actually carries out later on. While in the parentheses, the parameters are collected, and then the symbol that comes after is executed with the parameters in mind. Using this idea, I was able to find places in the tree L system that allowed for parameters and adjusted them. I also changed rule Q so it would just draw a straight line.
I did extension 2 for this project; this involved making more drawing styles. I made a brush one and a angled-to-actual-line-lines style. The two are shown below:
For the angled lines, I first determined, like with the dotted line before, if the turtle was on every other distance (of distance divided by curve width, or the amount of lines that would be able to fit in). If it was, I put the turtle down, rotated it, went forward, then went back the same way and undid the rotating, then moved to the side of the line to prepare to draw the next one. The process is very similar to the dotted line style's. The code is shown below:
The painting style involved drawing several parallel lines (determined by the width) and changing the color for each of them. Logically, the paint in real life is thinner farther away from the center, so to make that happen, I retrieved the current color, then made the lines in the first and last quarters slightly lighter. The placement of the lines was just a matter of going back from the drawn line, turning, picking up, moving forward, turning again, then going down. The repeated drawing of lines was done through a for loop.
Extension 3 was to make drawstring draw the trees slightly droopy. I just put a parameter into the method (boolean) that could either be on or off (True or False). I had to trace the parameter and put it in all the way to my main code telling the shape to be drawn, but in the end, it looked like this:
The method involved first seeing if the droop effect should be on, then determining the current angle of the turtle (heading), and depending on in which range the angle was, setting the angle to now be more or less right. The code is shown below:
Through this project, I learned how to use modifications on forward to implement different drawing styles. I learned how to pass in information (through many files that would need the information in order for it to properly draw) about the turtle's current color and orientation and to use that to change those things later. I also learned how to parameters in L systems to adjust parts of the systems at a time instead of all at once.