This was our second project using L-systems. In this project, we made them by creating classes and methods inside of those functions. In this project, we made trees more complex by having multiple rule L systems.
The first task was creating five additional characters to help us draw a tree with colored leaves. For the first required image, I used four of the tree L-Systems. Using looping, I made it so the trees went up diagonally across the screen by looping through a list of trees. I also made each tree increase in iterations each time through the loop which means you can increase iterations by controlling how many times to loop. In addition, I made the the positioning scalable so you could place this picture wherever. (arrangement.py)
For the second task, we had to create two new L systems and place them throughout the picture with different iterations. I did something similar to the grid.py where I increased iterations each time through a loop. I looped through a list of four trees where iterations was a function of the tree index. The top two rows of trees are my L-systems. They're variations of trees from the algorithmic botany with an additional characters to change trunk color and berries attached.
1) I added characters to my turtle interpreter to add berries/fruits, trunk color, and color of branches.
2) By passing the '&' string to systemGL.txt, I made the leaves squares. I also made triangles by passing the ';' string to systemDL.txt
3) All of these came together in modifying the trees. I added variations to each tree to make it more interesting by creating strings and adding them in the Lsystems to make them a little more interesting. This extension was kind of a culmination of the first two extensions.
I learned a lot about Lsystems and how to call methods from classes.
The purpose of this project was to become more familiar with L-systems, and change aspects such as color and width without affecting other elements of the object the turtle is drawing. In order to accomplish this task we first had to modify draw string so it supported five more characters. The second task was to write a function with an arrangement of trees or flowers that make use of the color store and restore. For this task I used multi-rule systems EL and DL. I modified the code in system DL by adding a T which changed the color of the tree to brown. I also modified the code in system EL by adding an O to make oranges. In order to make sure these changes were present in my drawing I edited my turtle interpreter. To make the orange I set the fill color to orange, drew a circle, ended the fill, and lastly set the color back to green for the rest of the tree. Here is an image of what this code draws.
Required Image 1
The third task was to make two new L-systems either by editing the code from one already made or creating a new L-system. I decided to create my own L-systems which can be seen in the mylsystem files. To do this I wrote a base, a rule, and then called these systems in my growth.py file. Here is an image of the L-systems I created.
Required Image 2
I did two extensions for this project. My first extension was to create one more L-system. The code for this system is in the file extensionlsystem1.txt. This system draws a circular shape in magenta and is pictured in the center of the image below.
The second extension can be seen in the orange tree on the right of my required image 1. For this extension I added the variable o to the second rule of the systemEL file and added an elif c == "0" statement to draw string in my turtle interpreter.
To complete this project I learned how to edit my turtle interpreter so I could change one aspect of the image without changing the entire picture and how to write my own L-systems.
List of people I worked with
The purpose of this project was to become familiar with L-systems and writing code for fractal shapes. In order to do this we created a scene that consisted of elements from turtle graphic and fractal shapes. The first task was to create an abstract image using L-systems. The image included three different L-systems; I used systems A1, A2, and AB. I added color by inserting a variable in the L-system and using elif statements that assigned the pen to a specific color based on the variable. Here is a picture of my solution to task 1. (In the image the circular shape is in red, but in my code the color actually is dark blue because I changed it for my scene.)
Required Image 1
The second task was to create a 3x3 grid with nine trees. To create this grid I used the L-system saved in the systemB.txt file. The iterations of the grid increased from 1-3 starting from the left and the angles went from 22, 46, and 60 from the top to bottom. In order to this I used a double four loop as can be seen in the following code. for x in range(-300, 300, 200): for y in range(-300, 300, 200): goto(x+10*scale,y+5*scale) it.drawString( lstrings[i], 7*scale, angles[j] ) j +=1 j = 0 i+=1
for x in range(-300, 300, 200):
for y in range(-300, 300, 200):
it.drawString( lstrings[i], 7*scale, angles[j] )
j = 0
I made the angles equal to the variable j and the lstrings equal to the variable i. Here is an image of my grid.
Required Image 2
The third and final task was to create a scene using at least two L-systems, one of which we had not previously used. For this scene, I took an L-system from page 25 of ABOP and put this in a file named systemC.txt. I also used the L-system saved in the file systemA2.txt. I put these L-systems in my outdoors2 scene from project 2 to add a lake and another tree to the scene. Here is a picture of my scene.
Required Image 3
I completed my first extension in the third task where I just called one of my scenes from project 2 and added a fractal shape (the lake) and a tree to the scene. This extension can be seen in required image 3.
For my second extension I made my abstract image function take in parameters (x,y, scale) and called the function 4 different times at different x,y locations and with a different scale value. This extension can be seen in the image below.
In order to complete this project I learned how to create L-system generated objects and how to change things such as color by manipulating code within an L-system.
List of people I worked with
TA Bilal Ahmad
CS 151 Project 7
Due Date: April 7th 2015
The purpose of this project was to become familiar with L-system grammars and use them to make visual images. We created two files, lsystem.py and turtle_interpreter to read a text file with the lsystem base and rule. Once that information has been read the turtle_interpreter interprets specific letters as different commands from the turtle module. I used these files to create multiple different fractal patterns and images containing fractals.
In task 1 the goal was to create an abstract image using only fractals. I found one lsystem rule in 'The Algorithmic Beauty of Plants' to make the large pyramid shaped fractals. This fractal also conveniently had space within to contain other fractals, so I inserted two copies each of two more fractals. I varied pen width and color to make the image more aesthetically pleasing.
In task 2 we had to make a 3x3 grid containing 9 copies of the systemB lsystem rule from lab. The number of iterations increase from 1 to 3 as one moves right across the columns. The angle between the branches increases from 22 to 60 going down rows.
For task 3 we were supposed to create a nonabstract scene containing a tree lsystem and at least two fractals. I fulfilled one extension by importing fractals into my project 2 file. I replaced the sun with the Koch's snowflake fractal. I found the rule and base code at http://mathworld.wolfram.com/KochSnowflake.html. For the trees I added leaves and berries to them fulfilling another extension. I built on the systemB lsystem and merely added two new letters at the end of each bracket. This means a berry and leaf are drawn at the end of each branch. I also had to edit the turtle_interpreter file to create new rules for the new letters I added into the lystem text file. The trees also have a random offset, like the original trees I had in my project 2.
For my abstract image I added ( x, y, scale) functionality, as can be seen in the image below.
For another extension I chose to vary the color of each fractal by the column that it is located in. Column 1 is summer and green. Column 2 is fall and orange. Column 3 is brown and winter. I also enabled x, y, and scale inputs allowing me to place different sized file grids and different locations.
What I Learned
I learned how to use lsystems to create very complex patterns and images simply. Without the use of lsystems the images I made for the project would be incredibly difficult, if not impossible, to reproduce using just the knowledge I had when I did project 3. I am also becoming more and more comfortable with encapsulation.
The Algorithmic Beauty of Plants for the pyramid lsystem
http://mathworld.wolfram.com/KochSnowflake.html For the base and rule for Koch's snowflake.