








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The connection between recursive turtle programs and conformal iterated function systems in generating fractals. The text establishes the equivalence of these two methods and shows that the fractals generated by recursive turtle programs are independent of the base case. The document also includes two lemmas that help prove the equivalence and provides examples of sierpinski gasket generation using both methods.
Typology: Study notes
1 / 14
This page cannot be seen from the preview
Don't miss anything!









Lecture 8: Recursive Turtle Programs and Conformal Iterated Function Systems
convert, and be healed. Isaiah 6:
1. Motivating Questions
We have studied two methods for generating fractals: recursive turtle programs and iterated
function systems. We have also examined many fractal curves that can be generated by both
methods. Whenever there are two seemingly dissimilar approaches to accomplishing the same task,
questions naturally arise concerning how the two techniques are related. For fractals we ask:
The turtle commands FORWARD, MOVE, TURN, and RESIZE embody the conformal
transformations TRANSLATE, ROTATE, and SCALE. Since there exist affine transformations
such as non-uniform scaling which are not conformal, there exist fractals that can be generated by
iterated function systems that cannot be generated by recursive turtle programs. But as long as we
restrict our attention to iterated function systems consisting solely of conformal transformations,
then the answer to all three questions is yes.
The purpose of this lecture is to establish these results by investigating the connections between
recursive turtle programs and conformal iterated function systems. Using the equivalence of
recursive turtle programs and conformal iterated function systems, we shall also establish that the
fractals generated by recursive turtle programs are independent of the base case.
2. The Effect of Changing the Turtle’s Initial State
A (non-recursive) turtle program is simply a finite sequence of FORWARD, MOVE, TURN,
and RESIZE commands. In this section we are going to study the effect of changing the turtle’s
initial state on the geometry generated by a turtle program. The insights we shall develop here are
actually the keys to understanding the relationship between recursive turtle programs and conformal
iterated function systems.
The turtle knows only her state
( P , v ), where P is her position and v her direction vector.
Besides sometimes drawing a line, all that the turtle commands really do is change the state of the
turtle. Now consider two possible turtle states:
1
1 , v 1 ) and
2
2 , v 2 ). Is it always
possible for the turtle to get from one state to the other? Sure. In fact, we can see from Figure 1
that there is always a sequence of four turtle commands --
-- that maps the turtle from
1 to
2
. Similarly, there is a sequence of three conformal
transformations consisting of translation, rotation, and uniform scaling that maps
1 to
2
€
P 1
v 1
€
P 2
€
v 2
€
D
€
A
€
B
Figure 1: A pair of turtle states:
1
1 , v 1 ) and
2
2 , v 2 ). The turtle can get from
1 to
2 by executing the commands: TURN(A), MOVE(D), TURN(
− B ), RESIZE(R), where
R = length ( v 2 ) / length ( v 1 ). Similarly, executing consecutively the three conformal transformations
2
1
2
2 , R ) maps
1 to
2
Now we are going to make two key observations that will help guide us to an understanding of
the relationships between recursive turtle programs and conformal iterated function systems.
Lemma 1: Suppose that
1
2 = two turtle states
1
2 = two turtle programs that differ only by their initial states
1
2
1
2 = geometry generated by
1
2
M = conformal transformation that maps
1 to
2
Then
2
1
Proof: Clearly if we change the turtle’s initial state by, for example, a TURN( A ) command, the
turtle will still draw exactly the same shape, but rotated by A radians. Similarly, MOVE( D ) will
translate the shape and RESIZE( R ) will scale the shape. But we have just seen that we can get from
any turtle state to any other turtle state by a sequence of four such turtle commands. Thus if M is
the affine transformation corresponding to these four turtle commands and
1
2 are the geometry
generated by the turtle programs
1
2 , then
2
1
The effects of the turtle programs SHIFT, SPIN, and SCALE are examples of Lemma 1 in
action.
Let
k be the conformal transformation that maps
0 to
k -- that is,
k
0
k
Define a conformal iterated function system by setting
1
p
Condensation Set =
R
We shall show that starting with the same base case, level for level the RTP and this CIFS generate
exactly the same geometry.
Let
B be the geometry drawn in base case -- that is, the geometry drawn by
B -- and let
n be
the geometry drawn by the nth level of the recursive turtle program. The key insight is that at the
( n + 1 )
st level, every recursive call draws the geometry
n , but starting from a different initial state.
Thus by Lemma 2
0
B
n + 1
1
n
p
n
R
On the other hand, let
n be the geometry drawn by the nth iteration of the iterated function system.
If we start the iteration with the base case
B , then by the definition of an IFS with a condensation
set,
0
B
n + 1
1
n
p
n
R
Therefore, by induction, level for level the recursive turtle program and the conformal iterated
function system generate exactly the same geometry.
Corollary 1: Every fractal generated by a recursive turtle program can be generated by an
iterated function system consisting solely of conformal transformations. Moreover, the number of
conformal transformations in the CIFS is equal to the number of recursive calls in the RTP.
Proof: This result is an immediate consequence of the statement and proof of Theorem 1.
Corollary 2: The fractal drawn by a recursive turtle program is independent of the geometry
drawn in the base case.
Proof: This result follows from Theorem 1 because by the Fractal Theorem in Lecture 7, the fractal
generated by an IFS is independent of the geometry in the base case.
Theorem 2: For every iterated function system consisting solely of conformal transformations
(CIFS), there exists a recursive turtle program (RTP) such that starting with the same base case,
level for level the CIFS and the RTP generate exactly the same geometry.
Proof: Given a conformal iterated function system
1
p
Condensation Set =
R
we seek a recursive turtle program that generates, level for level, the same curves as this IFS. Fix an
initial turtle state
0 , and let
k be the turtle state into which
0 is mapped by the conformal
transformation
k
. From our observations in Section 2, we know that for every k there is a
sequence of turtle commands
k consisting of MOVE, TURN, and RESIZE commands that map
k − 1 to
k
. We will use these turtle commands to transition between recursive calls. To finish the
recursive turtle program, let
p + 1 be the turtle commands that draw the condensation set
R and
return the turtle to her initial state. For the base case of the recursive turtle program, we can choose
any turtle program
B that draws some geometry
B and returns the turtle to her initial state
0
We claim that the following recursive turtle program generates, level for level, the same geometry as
the given CIFS:
B
Turtle Commands ( T 1 ), Turtle Recursion
M
Turtle Commands ( T p ), Turtle Recursion
Turtle Commands ( T p + 1
Let
n be the geometry drawn by the nth level of this recursive turtle program. Again the key
insight is that at the
( n + 1 )
st level, the kth recursive call draws the geometry
n , but starting from
the initial state
k
. Since
k
0
k , it follows by Lemma 2 that
0
B
n + 1
1
n
p
n
R
On the other hand, let
n be the geometry drawn by the nth iteration of the conformal iterated
function system. If we start the iteration with the base case
B , then by the definition of an IFS,
0
B
n + 1
1
n
p
n
R
Therefore, by induction, level for level, the recursive turtle program and the conformal iterated
function system generate exactly the same geometry.
a.
k = product of the transformations between the
( k − 1 )
st and
k
th recursive call.
b.
1
1 = product of the transformations before the first recursive call.
c.
k
k − 1
k
d.
1
p } { p = number of recursive calls}
Example 1: Sierpinski Gasket -- Ron’s Method
Outer Triangle
Vertices =
1
2
3
Edges =
( w 1 , w 2 , w 3
Recursive Turtle Program Transformations
k ( ,^1 /^2 )
k ( ,^2 )
TRANS ( w k
2 π / 3
k + 1 ( ,^2 π^ /^3 )
Conformal Iterated Function System
1
1 ( ,^1 /^2 )
2
1
1 , 2)∗ TRANS ( w 1
2 ( ,^2 π^ /^3 ) ∗^ SCALE^ P 2 ( ,^1 /^2 )
= TRANS ( w 1
2 ( ,^2 π^ /^3 )∗^ SCALE^ P 2 ( ,^1 /^2 )
3
2
2 , 2 ) ∗ TRANS ( w 2
3 ( ,^2 π^ /^3 )∗^ SCALE^ P 3 ( ,^1 /^2 )
= TRANS ( w 1
2 ( ,^2 π^ /^3 )∗^ TRANS ( w 2
3 ( ,^2 π^ /^3 ) ∗^ SCALE^ P 3 ( ,^1 /^2 )
Notice that in Ron’s algorithm, the transformations depend on the turtle’s current state. Thus
Ron’s algorithm has the annoying property that it must keep track of the turtle’s state after each
turtle command. For the Sierpinski gasket, keeping track of the turtle’s state is easy, but for many
other fractals it is not so straightforward to keep track of the turtle’s state.
Tao’s algorithm takes a turtle-centric point of view, a perspective from inside the turtle’s
domain. From the turtle’s viewpoint, the turtle is always at the center of the universe (the origin)
facing in the direction of the x -axis ( ivec ), so there is no need to keep track of the turtle’s state.
Therefore, viewed from inside the turtle, the turtle commands correspond to the following conformal
transformations:
FORWARD D ↔ TRANS (^) ( ivec ∗ SCALE ( D ))
MOVE D ↔ TRANS (^) ( ivec ∗ SCALE ( D ))
TURN A ↔ ROT ( Origin , A ) = ROT ( A )
RESIZE s ↔ SCALE ( Origin , s ) = SCALE ( s ).
There is one novel detail here. When we apply transformation matrices to compute the new
coordinates of a point or vector, we multiply on the right:
new
old ∗ M. But when we apply
these transformations to change the state of the turtle -- the turtle’s local coordinate system -- then
we must multiply on the left. For suppose that the turtle is in the state
S = ( P , v ). Then
v new = v
⇔ v new
⊥ = v
⊥
new = P + D v
v new
v new
⊥
new
v
v
⊥
RESIZE s
v new = s v
⇔ v new
⊥ = s v
⊥
new
v new
v new
⊥
new
s 0 0
0 s 0
v
v
⊥
v new = cos( A ) v + sin( A ) v
⊥
⇔ v new
⊥ = − sin( A ) v + cos( A ) v
⊥
new
v new
v new
⊥
new
cos( A ) sin( A ) 0
−sin( A ) cos( A ) 0
v
v
⊥
These observations lead to the following result.
Proposition: If
1
n are the transformation matrices corresponding to the turtle commands
1
n , then
n
1 is the transformation matrix corresponding to the turtle program
1
n
Proof: Let
k denote the state of the turtle after executing the command
k
. Since
k
k − 1
k
it follows that
0
n
1
0
n
5. Bump Fractals
The easiest way to describe a bump is with a turtle program. When we studied bump fractals,
we observed that we could generate the recursive turtle program for a bump fractal directly from the
turtle program for the bump. We would like to do the same for iterated function systems: that is,
we would like to extract the IFS for the bump fractal directly from a simple turtle description of the
bump. Since we know how to get from a turtle description of a bump to a recursive turtle program
for the bump fractal and since we know how to convert from a recursive turtle program to an
iterated function system, all we need to do to get from a turtle description of a bump to an iterated
function system for the bump fractal is to combine these two procedures. We exhibit this algorithm
in Table 1. In order to avoid keeping track of the turtle’s state, we use Tao’s algorithm to convert
from a recursive turtle program to an iterated function system.
Bump Fractal ( Level ) CIFS
Base Case: FORWARD 1
Recursion:
1
1
( 1 )
1
1
( 1 )
FORWARD 1 → Fractal
( Level − 1 ) →
TRANS ( ivec )
2
2
( 2 )
2
2
( 2 )
FORWARD 1 → Fractal
( Level − 1 ) →
TRANS ( ivec )
n
n
( (^) n )
n
n
( (^) n )
FORWARD 1 → Fractal
( Level − 1 )
n + 1
n + 1
n + 1
n + 1
Table 1: Bump
→ Recursive Turtle Program
→ CIFS. All the rotation and scaling commands
are around the origin. The last three bump commands -- FORWARD 1, TURN
n + 1 , and RESIZE
n + 1 -- are ignored by the iterated function system, since the only purpose of these commands in
the bump program is to conduct the turtle to her final state. To read off the IFS from the
transformations in the last column, simply write down the transformations in reverse order and
group them between successive appearances of
Trans ( ivec ) (see Example 3).
Example 3: Koch Curve
Koch IFS Koch Bump Koch ( Level )
Base Case: FORWARD 1
Recursion:
SCALE (^) ( 1 / (^3) )
TRANS ( ivec )
→ Koch ( Level-1)
ROT ( π / (^3) )
π / 3
π / 3
TRANS ( ivec )
→ Koch ( Level-1)
ROT (^) (− 2 π / (^3) )
− 2 π / 3
− 2 π / 3
TRANS ( ivec )
→ Koch ( Level-1)
ROT ( π / (^3) )
π / 3
π / 3
→ Koch ( Level-1)
Rot ( π / 3 ) ∗ Trans ( ivec )∗ Rot (− 2 π / 3 ) ∗ Trans ( ivec )∗ Rot ( π / 3 ) ∗ Trans ( ivec )∗ Scale (^) ( 1 / (^3) )
M 1
M (^) 2
M 3
M (^) 4
A CIFS for the Koch curve is given by the transformations
1
2
3
4 }. To find these
transformations, we list in column 1 the transformations corresponding to the turtle program in
column 2 for the Koch bump. We then write these transformations horizontally in reverse order
and group these products between successive appearance of
Trans ( ivec ).
6. Summary
The main result of this lecture is the equivalence between recursive turtle programs (RTP) and
conformal iterated function systems (CIFS). The conformal transformations in the CIFS
correspond to changes of state between successive recursive calls in the RTP; the condensation set
of the CIFS is the geometry drawn during highest level of the recursive phase of the RTP. These
and other explicit correspondences between recursive turtle programs and conformal iterated
functions systems are summarized in Table 2. Since, by the trivial fixed point theorem, the fractal
generated by an iterated function system is independent of the base case, it follows from our
equivalence theorems that the fractal generated by a recursive turtle program is also independent of
the base case.
a. Write a turtle program to generate each of these bumps.
b. Write a recursive turtle program to generate the bump fractals corresponding to each of
these bumps.
c. Describe the transformations in the conformal iterated function systems that generate each
of these bump fractals.
a. Write a turtle program to generate each of these bumps.
b. Write a recursive turtle program to generate the bump fractals corresponding to each of
these bumps.
c. Describe the transformations in the conformal iterated function systems that generate each
of these bump fractals.
a. Write a turtle program to generate each of these bumps.
b. Write a recursive turtle program to generate the bump fractals corresponding to each of
these bumps.
c. Describe the transformations in the conformal iterated function systems that generate each
of these bump fractals.
a. Write a turtle program to generate each of these bumps.
b. Write a recursive turtle program to generate the bump fractals corresponding to each of
these bumps.
c. Describe the transformations in the conformal iterated function systems that generate each
of these bump fractals.
recursive turtle program for the Sierpinski gasket by Ron’s Algorithm (Example 1) and by Tao’s
Algorithm (Example 2).
a. Show that these two iterated function systems are identical.
b. Show that these two iterated function systems are not identical to the standard iterated
function system for the Sierpinski gasket given by the three scaling transformations
Scale ( P 1
Scale ( P 2
Scale ( P 3
c. Conclude from part b that the IFS for generating a fractal is not unique.
d. Construct a recursive turtle program that corresponds to the standard iterated function
system for the Sierpinski gasket given in part b.
same fractal when both of the following conditions are satisfied:
i. the pen is down and the anchor is up during the base case;
ii. both the pen and the anchor are up during the recursive body of the program.
a. Show that if we replace the classical turtle by the left-handed turtle and conformal
transformations by arbitrary affine transformations, then
i. Lemma 1 and Lemma 2 remain valid.
ii. Theorems 1, 2 and Corollaries 1-4 remain valid.
b. Explain how to extend Tao’s algorithm to convert recursive turtle programs for the left-
handed turtle to iterated functions systems consisting of arbitrary affine transformations.
a. Build a fractal that cannot be generated by a recursive turtle program for the classical turtle.
b. Construct a recursive turtle program for the left-handed turtle that generates the fractal in
part a.
Programming Projects:
a. Write a parser to convert recursive programs for the classical turtle into conformal iterated
function systems that generate the same fractal.
b. Write a parser to convert recursive turtle programs for the left-handed turtle into iterated
function systems that generate the same fractal (see Exercise 10).
a. Develop an algorithm that given two arbitrary iterated function systems determines whether
the two systems generate the same fractal or show that no such algorithm exists.
b. Develop an algorithm that given two arbitrary recursive turtle programs determines whether
the two programs generate the same fractal or show that no such algorithm exists.
Note that by the results in this chapter, the preceding two open problems are equivalent.