Lesson 1 - Using a string of characters to represent a plant
(scroll down for directions)
We can use a string of characters to represent a plant. For example,
in the applet above, in the white space at the top, type in the string
of characters I[L]I(L)IF (be sure to use capital letters and no
spaces between the characters). Then click on Draw Plant.
This shows one
representation of the string I[L]I(L)IF.
We assign to each character a geometric object. To get this plant:
to the letter "I" we assign Internode (or line segment); to the letter "L"
we assign Leaf; to "F" we assign flower; a pair of brackets [,] means
"enclose a branch to the left" and a pair of parentheses (,) means "enclose a
branch to the right". Then we start at the leftmost character in the string
(which will correspond to the root of the plant) and traverse the string,
one character at a time, from left to right. Try this with a pencil and
paper. We start out at a point (x,y) and a variable angle = 90 degrees from
the horizontal.
The first character is "I", so draw a line segment at an angle of 90 degrees.
The next
character is "[" so we are going to turn left, say 40 degrees, the "L"
tells us to draw a leaf at the new angle. The "]" tells us to return
to the point where we branched
left, and set the angle back to our original angle (90 degrees). the next "I"
says draw another line segment; the "(" says turn right 40 degrees; the "L"
says draw a leaf at the new angle; the ")" says go back to where we branched
and set a the angle back to the original angle; the "I" says draw another line
segment and the "F" says draw a flower.
We start with an alphabet, a set of symbols. Our first alphabet will
be simple. It will be the set {I,L,F,[,[,),)} and the geometric objects
assigned to each character will be as described above. We can model plants
with branches off of other branches by using nested brackets or parentheses.
Try the following string in the applet (try it first using pencil and paper):
I(I(I(IF)[IF])IF)I[L](L)IF
You can see that this becomes tedious and difficult making sure you have
matching parentheses; the next lesson will explain how to generate
long character strings from short ones. But first try designing a
few of your own plants on paper using these characters, and test them out
using the applet.
Hint: Once you have a string that works, you can insert characters in it;
for example you could insert something like [I[L]IF] into an existing
string and you would see a branch to the left at the point where you
insert it.
Lesson 2 /
Lesson 3 /
Back to my home page