Project 9 Matthew Willett-Jeffries
Skip to end of metadata
Go to start of metadata

Matthew Willett-Jeffries
Spring 2011
Lsystem version 3
Project 9

The goal of this project was to make use of complex classes which reference dictionary sets and other classes in order to make complex turtle commands. This was achieved by integrating the lsystem interpreter and building a base function through which drawing commands could be received.

Task 1
The goal of the first task was to make a program which references but modified your base shapes class in order to incorporate lsystems, ultimately with the idea of drawing lsystem trees. This was achieved by creating an lsystem argument within the new class, "self.lsys = ls.Lsystem()," such that the lsystem could be computed and then inputted into the shapes class function draw in place of self.string.

The end result is as follows:

Image 1.
Though the iterations of the trees were not set differently (this would be completely possible), the trees are completely scalable and place-able and thus the scale is increased for each consecutive tree in this turtle image.


Task 2
The goal of task two was to add a variety of shapes into by adding unique shape classes. I chose to write my name and surround it with various shapes as seen in the following image:

Image 2

In order to draw the isolated triangle in the "A" of my name a few new features had to be added to the interpreter, namely a mechanism for bringing the turtle tracer up and down. This was achieved simply by adding two new elif statements containing novel symbols to the interpreter build function as follows,

        " elif c == "/":
                #sets the turtle tracer to up
            elif c == "~":
                #sets the turtle tracer to down

The only down side to this new mechanism is that it radically confuses the fill function of turtle; this problem was fully realized in the next image where separate functions had to be written up in order to color the window frame which made use of this mechanism.


Task 3.

Task three called for a combination of the tree function and your shape functions in order to create an indoor scene which had a view or picture of the Tree. By making use of the new mechanism introduced to interpreter I was able to create a three dimensional image of a window sill in a room with an interesting wallpaper (of course with a tree outside the window, argv[1]). The wallpaper was achieved by making use of a for loop within a for loop which drew a repeating pattern introduced by an lsystem (this lsystem should be input as argv[2] upon running, it can be found in the same folder) as this code demonstrates,

"wallpaper = Tree(filename=argv[2])
    for i in range(10):
        for n in range(10):

It must be noted that because of this function, the wallpaper is not scale-able but the scene, window and tree, is scale-able and place-able on the background. The result was the following:

Image 3.


Task 4.
The goal of task four was to design a separate function which made use of the shapes class in order to produce an interesting tile set or mosaic. I chose to use my hexagon shape class which posed some unique problems. Unlike rectangles or squares, hexagons do not stack directly on top of each other so for each row the hexagon had to be raised by half the hexagon's height, the square root of 3 multiplied by the distance of a side, and each alternating row had to be shifted 1.5 times the distance of a side. This was achieved by using an if statement within the double for loop which determined whether the column was even or odd and modified its placement accordingly as the following code demonstrates,

"if cols%2 > 0:
                tile2.draw(x+(100*scale*3*rows)(150*scale), y(173.205081*scale*cols*.5), scale, orientation=0)
                tile2.draw(x+(100*scale*3*rows), y+(173.205081*scale*cols*.5), scale, orientation=0)"

This mosaic, however, can never be perfected because each row placement on the y vector is determined by an irrational number, the square root of 3.

Image 4.

It should also be noted here that by making use of random.uniform a speckled color affect could be achieved within the mosaic.

Three of the extensions were undertaken. First the interpreter was modified and the formation rules of the formal language were modified such that novel mechanics could be achieved, namely lifting and placing the turtle tracer. Second, many extra shape classes were designed namely complex shapes which drew out letters and even a complex window sill. Finally the mosaic was designed in a novel creative fashion such that unique methods had to be used in order for the mosaic to be scalable and place-able.

This project demanded a sharp knowledge of classes and furthered my general facility working with lsystems and complex classes.