Skip to end of metadata
Go to start of metadata

$Ibrahim Riaz Project 8


Project 8 is a a step up from project 7. We demonstrate our understanding of classes and create L-systems and complicated shape without entering turtle commands directly. Although the setup takes a significant amount of time(Lab8+), this results in the ability to create extremely complex shapes by manipulating a string of alphabets. The L systems have their own grammar and start with a string such "F" which is a base. It then modifies "F" influenced by the rules we set e.g F ->FF creating a new string such as FFFFFFFF. All this sounds complicated but its essentially like a loop where instead of adding numbers to our iterations, we modify strings using conditionals.

This week we work with various trees, demonstrate growth over time, use lists and make interesting arrangements all of which is incredibly fun ! We use our understanding of classes to access a bunch of different files and even create an interpreter which converts our strings into actionable turtle commands.


Task 1: Add features to the TurtleInterpreter

In my turtle interpreter, I added a series of new features to add complexity to my codes. 

We edit the drawstring function to add more symbols and options. We create an empty list / colorstack to manipulate color in our images. “<“ is used to append current state of the turtle color to the stack, and “>” sets the pen color to the previous saved color by popping the last color on the stack. Using G, Y, R we can set colors to green, red and yellow. Additionally I added two extra shapes

  1. Leaves which are denoted by L-use of semi circle
  2. Berries which are denoted by B-use of circle

We further add:

A hold() function which holds the screen open until a click.

A place() function which puts the turtle in a certain position with certain heading angle;

An orient()function which sets the turtle’s heading

A goto()function that sets its position on x,y

A setColor()function that sets a color

A setWidth() function that can change turtle width


Task 2: Create a Scene that is an Arrangement of L - Systems 


In order to create an arrangement such as the one shown on the project page, I had to create a function similar to class test but different in some ways. So I hard code the systems that can be called in my assignment.py file. Upon running the file in terminal - the user need not give any command line arguments and will have a straight line of the following systems in random colors.

L -> R

  1. System CL Single Rule lsystem
  2.  System GL Multi Rule lsystem
  3. System FL Multi Rule lsystem
  4. System EL Multi Rule lsystem

Upon randomization of distance we get:

Task 3 - Create your own L-system inspired by "Art Forms in Nature"

For this task , I had to come up with my own L system. Now this was extremely hard for me. I to create a simple l-system that simply branches. Then I decided to extend the rule to a point whereby the new turtle commands would overlap therefore create something akin to Ernsts Flagellata page.

I ended up creating an L systems that essentially branches out with a berry on top just like a mistletoe or the wildberry bushels in my school growing up. Ernst Haeckl however would probably see this as generative growth in an organism.

base F
rule F FF[-F+F-F][+F-FB+FB]

The file should be IBRAL.txt

Iterations shown are 2, 3 and 4 .



Extension 1:

Created 2 additional new L Systems

Titled IBRALext.txt and IBRALext1.txt

I realized most of my images were vertical and linear, and nature especially moss was more curvy, so I decided to make another L-system that curves all around like a nest or moss. I therefore created a new multi rule L system to achieve this effect by utilizing angles and brackets.

I wondered if I could achieve the same effect with a single rule system and so I tried to create another system-IBRALext1.txt that works but only for small iterations.

Extension 2:

Modified given L-systems EL, CL, FL and GL added variations in terms of colors-shapes and strings.

These are the arrangements shown above with modified L strings. I experimented with parameters such as limiting growth to one side, alternating berries and leaves and imagining layers which works extremely well for system GL, FL and CL. EL was more underwhelming to be honest.

Extension 3:

As you can probably notice, all my pictures have leaves and branches of different colors. This is randomized through the creation of a list in the assignment.py file. Not only do I incorporate different colors in my graphics but I also add berries which are a small red circle and little leaves. which fulfills the requirement of adding additional parameters to drawstring function.

Extension 4:

Create a new Scene/Arrangement using rotate allowing users to utilize command line arguments to see growth or different iterations in a cool rotational arrangement.

The use chooses the file and enters on command line. They then specify the range of iterations they want to see by entering start, stop and step respectively. The result is absolutely wonderful. I tried watch the iterations between 1 and 7 for gledit.

Command line in action.



  1. What is a class?
    A class is a blueprint or template for object creation.It outlines the attributes, methods of objects within that class.
  2. What is an object?
    Object is a function table for a specific instance of the class. It has both the data in terms of attributes and the methods that can manipulate said data.
  3. What is the role of self in a class method?
    Self represents an instance of the class. By using self we know which object we are referring to, performing methods on or recording attributes for.
  4. Given an object x how do you call its method y?
  5. Which Ernst Haeckel print did you choose as inspiration? Why?
    Flagellata, I like the geometric replication present in the design.


This project was extremely hard to complete because it took some time getting used to L,systems and imagining how to control growth especially when in many cases it seemed to be exponential. That said, I really enjoyed working on this project because it shows how far i've come from making a star or a circle to creating somewhat detailed replications of the natural world. I also really enjoy the amount of power systems give us but must confess, still feel like I can get away without using them in real life by making more complex functions. Perhaps I'm wrong but i'll keep digging to figure that one out.



A list of people you worked with, including TAs and professors. Include in that list anyone whose code you may have seen, such as those of friends who have taken the course in a previous semester.

A list of any resources that you used.  This includes textbooks, lecture notes, python documentation, library documentation or forums.  If you used a specific website, please link to it.

Put the label cs151s20project# on your wiki page.

  • No labels