# Pages CS 151 Computational Thinking Fall 2012 Assignment 7(Philip Prosapio)

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Version 1

Philip Prosapio
Spring 2010 CS151

Note- The code for this lab is in pwprosap in the academic server

Summary

The first task asked me to use the functions that we had created in Lab that were in our lsystem.py and interpreter.py files to make a simple picture with two figures. The second task asked us to make a block of nine trees, in which going from right to left the L-system trees had more iterations and going from top to bottom the angle for the trees increased from 22.5 to 45 to 60. And the final task asked us to make a simple outdoor scene that involved L-system trees and fractals, with at least one of those L-systems being new.

Description of Solution

1) For the first task in which we needed to make just two L-system objects, I took the two objects systemA.txt and systemB.txt that we used in lab. I made it so the first object could be altered at the command line but I hard-wired the second object into the function like this:

filename2 = 'systemB.txt'
iterations2 = 3
distance2 = 10
angle2 = 22.5

The picture of this task is attached and named picture1lab7.png .

2) The second task asked me to make the block of trees. To expedite the process I added in a "for" loop to make all of the nine trees with less iterations.

for i in range (3):
if i == 0:
anglei = 22.5
elif i == 1:
anglei = 45
elif i == 2:
anglei = 60
goto(-200, 100-150*i)
interpreter.drawString(string1, distance, anglei)
goto(-50, 100-150*i)
interpreter.drawString(string2, distance, anglei)
goto(100, 100-150*i)
interpreter.drawString(string3, distance, anglei)

I added in the "if" and "elif" statements to make it so it would draw the trees with the correct angle as it went down a row. The picture of this task is attached and titled picture2lab7.png .

3) The final task was for me to make a outdoor scene that implemented L-systems. I made a scene of a forest and two people standing in awe of a crop circle that had appeared in their tiny corn field. The special part of this code was the use of the random function that made it so the forest looked dense.

for i in range(100):
turtle.color('saddle brown')
goto(random.randint(-75, 300), random.randint(-300, 145))
interpreter.drawString(random.choice(string), random.choice(distances), angle)
turtle.color('black')

By doing this, the trees will go to random locations and make brown trees that will have randomly chosen how many iterations and size for themselves. The picture for the final task is attached and named picture3lab7.png .

Extension

For this lab I did all three of the extensions.

Extension 1- The first extension that I completed fulfilled the extension that required me to make my very own L-system and make it. For this extension I made a weird shaped box. Here is the base and the rule that I used.

base F-F+F+FF+FF+F
rule F F+F-F

The picture is attached and labeled picture4lab7.png and in the bottom corner I also showed what the figure looks like after zero iterations.

Extension 2- For the second extension, I fulfilled the extension that required me to take a picture from lab 2 or 3 and add in some L-system objects. I took a picture from my third lab and added in a L-system plant and L-system fractal. The picture for this extension is attached and labeled picture5lab7.png

Extension 3- For the third extension I completed the extension that required me to add berries and leaves to my L-system trees. I had to go back to my interpreter file to make this happen as well as changing my rule slightly. Here is the code in my interpreter file that allowed berries and leaves to be made.

if c == 'L':

1. go forward by distance and be colored green
turtle.color('green')
turtle.forward(distance/2)
turtle.color('black')
if c == 'B':
2. make a red berry
turtle.color('red')
turtle.begin_fill()
turtle.circle(2.5)
turtle.end_fill()
turtle.color('black')

By using this, my trees gained leaves and berries. The picture for this final extension is attached and labeled picture6lab7.png .

What I learned
I feel like a have a logical mind and I like puzzles, so for this lab, I think the most interesting thing I learned had to do with L-system rules. To figure out how to make interesting pictures and shapes with rules was a fun thing to spend my time doing.

Attached Photos
picture1lab7.png

picture2lab7.png

picture3lab7.png

picture4lab7.png

picture5lab7.png

picture6lab7.png

Labels
• No labels