Skip to end of metadata
Go to start of metadata

Abstract:


This week I continued to use lsystem, turtle_interpreter, shapes, and tree modules to draw more shapes and enhance my colby scene.  In the lab, I made changes to TurtleInterpreter's drawString() method so that I could use parametrized L-systems.  With parameterized L-systems, I had much more flexibility to draw shapes.

In addition, I added more drawing styles such as jitter3 and dotted to improve my drawings.  While creating and implementing new drawing styles, I needed to make sure I revise my turtle_interpreter and shapes modules so that drawing styles can be used.

Task 1:

I used for loop to implement a style 'jitter3.'  Jitter3 was essentially a for loop of jitter.

Task 2:

To created 'dotted' style, I used turtle.dot() and turtle.forward() using for loop.  I determined the number of iterations by using DotSize and the given distance. 

Task 3:

I drew four rows of my star shapes to show four different drawing styles: normal, jitter, jitter3, and dotted.  The order of the styles were from the top to the bottom.  Note that normal styles had two different pen widths; jitter and jitter3 had two different jitterSigmas; dotted had two different DotSizes.

To obtain the image above, I simply ran file, demo_line_styles.py

(Required Image 1)

Task 4:

To make enhancements to my colby scene, I added a new shape - trapezoid - in addition to using two new drawing styles such as jitter and jitter 3.  I wrote a string for trapezoid class using parameterized L-system.  Trapezoid was used as one of the blocks for Miller library.

To obtain the image below, I ran colby_scene.py with systemDL.txt on the command line.

Task 5:


For task 5, I made a variation to my own lsystem, systemDL2.txt.  I turned it into parameterized stochastic L-system.  First of all, the widths of the tree decreased as the iteration increased.  I changed the shape of leaves as well using different angles in front of case L.  To obtain the first image, I ran show.py and typed systemDL2.txt 4 10 normal on the command line.  4 is iteration number; 10 is the distance; normal is the style.  This is the image of my original L-system.  From the second image, I still ran show.py, but typed task5.txt 4 10 normal on the command line.  My 2nd, 3rd, 4th, and 5th images are all different because my new L-system is parameterized stochastic.  In other words, one of my rules has more than one replacement strings.

(Required Images 3)


Extensions:

  • Create more L-systems. Show how they differ in their design.

I made changes to systemDL2.txt and created task5.txt to obtain the images above.  I added modval values to F, +, - to show differences among the images.  One of my rules had three replacement strings as well.  

I created a new L-system named lsystem.txt. Although this one is not stochastic, it is parameterized.  With modval values, I was able to construct strings with different angles and widths.  The concept of my system was to construct polygons with fewer sides as iteration increases and more rules are added.  To obtain the image below, I ran show.py and typed lsystem.txt 4 100 dotted on the command line.  lsystem.txt is the filename, 4 is the iteration number, 100 is the distance, and dotted is the style.

  • Add other drawing styles. For example, try making one that simulates a brush by drawing many approximately parallel lines. Slight variations in color between the different lines makes the effect better. You might also try a pen-and-ink style with cross-hatching or just a series of straight lines at an angle to the direction of the actual line. Note although you are welcome to implement dashed and broken styles, they will not be counted as extensions.

I created new style 'brush'.  As the instruction says, I drew parallel lines by the number of BrushSize; I used for loop to draw those lines.  In addition, I gave slight changes to the pencolor every time the line was drawn.  The challenge with this extension was to figure out how to obtain the rgb values and then manipulate them.

My solution was to turn them into list, modify the list values, and switch the list back to the tuple values.  I ran test.py to see it my 'brush' style works.  Below is the image of test.py.

  • 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.

First of all, I added gravity attribute to TurtleInterpreter and Shapes objects to turn the gravity effect on and off.  To apply the gravity effects, I used if/elif statements and turtle.heading() to manipulate the value of angle.  To obtain the images below, I first ran show.py and typed task5_2.txt 4 10 normal on the command line.  task5_2.txt was simply my lsystem from Task 5 but without replacement rule strings.  I made this file so that I could get consistent images of L-system and observe the effect of gravity.  To obtain the second image, I ran show.py and typed task5_2.txt 4 10 normal and changed the value of tr.turnGravity() to 1 to turn on the gravity effect.  To turn off the gravity effect, simply change the turnGravity() value back to zero.  The default value is 0.

  • Be more creative with your main code. In other words, use programming structures, user input, and code to go beyond the minimal required image.

For this extension, I simply made changes to colby_scene.py and call the new file, colby_scene2.py.  The different is that users can type style on the command line and observe how the colby scene changes as the style changes.  Below are the colby scenes with different styles in following order: normal, jitter, jitter3, dotted, and brush. I ran colby_scene2.py and typed task5.txt and name of styles on the command line.  Note that the trees will be different every time because my L-system has more than one replacement rule string.


Reflection: 


It was interesting to create and implement different drawing styles to my colby scene to obtain different images like above.  Personally, the biggest lesson for me was to make changes to parent and sub classes to apply different drawing styles.  This was more than simply adding cases to drawString() method.

Sources, imported libraries, and collaborators are cited:

 
I received extensive help from professor Eaton and Skrien to solve issues within my codes and work on extensions.  I imported turtle, sys, random, and used my own modules such as turtle_interpreter, shapes, lsystem, and tree.  Nobody was referenced in this project.

Labels