View
7
Download
0
Category
Preview:
Citation preview
Turtles and Fractals
Ron GoldmanDepartment of Computer ScienceRice University
Fractals
Sierpinski Triangle Fractal Swiss Flag
Koch Snowflake C-Curve
Basic Turtle Programs
POLY (Length, Angle)
Repeat Forever
FORWARD (Length)
TURN (Angle)
SPIRAL (Length, Angle, Scalefactor)
Repeat Forever
FORWARD (Length)
TURN (Angle)
RESIZE (Scalefactor)
Propositions
POLY Proposition
The vertices generated by the POLY program lie on a circle.
SPIRAL Proposition
The vertices generated by the SPIRAL program lie on a spiral.
Examples of POLY Procedures
€
Angle = π / 5
€
Angle = 3π / 7
€
Angle = π 2 / 2
Proof of POLY Proposition
•R
RR
L
LL
x = R
α
αα
α βA
A
C
D
E
F
•
•
••
€
G
ΔCDE ≅ ΔCEF (SSS)A + β +α = A +α +α ⇒ β =α
€
ΔCEF ≅ ΔCFG (SAS)∴ x = R
Looping Lemmas
Circle Looping Lemma
Any procedure that is a repetition of the same collection of FORWARD and TURN
commands has the structure of POLY(Length, Angle), where
Angle = Total Turning within the Loop
Length = Total Distance traveled within the Loop
That is, the two programs have the same boundedness, closing, and symmetry.
In particular, if Angle ≠
€
2πk for some integer k, then all the vertices generated
by the same FORWARD command inside the loop lie on a common circle.
Looping Lemmas (continued)
Spiral Looping Lemma
Any procedure that is a repetition of the same collection of FORWARD, TURN,
and RESIZE commands has the structure of SPIRAL(Length, Angle, Scalefactor),
where
Angle = Total Turning within the Loop
Length = Total Distance traveled within the Loop
Scalefactor = Total Scaling within the Loop
That is, the two programs have the same boundedness and symmetry.
In particular, if Angle ≠
€
2πk for some integer k, and Scalefactor ≠
€
±1, then all
the vertices generated by the same FORWARD command inside the loop lie on a
common spiral.
Looping Program and Polygon Procedure
LoopingPr ogram
•
PolygonProcedure •
• LoopingPr ogram
Sample Looping Program
WALK
Repeat Forever
FORWARD 1
TURN
€
π / 3
FORWARD
€
1/ 4
TURN
€
π / 4
FORWARD
€
1/ 3
TURN
€
−π / 2
FORWARD
€
3/5
TURN
€
π /6
Looping Curve
More Sample Looping Program
PolySpiral
Repeat 20
Spin[
€
2π /20
Scale[1.01
Poly[5,
€
2π /5 ]
]]]
StarSpiral
Repeat 20
Spin[
€
2π /20
Scale[1.1
Poly[5,
€
4π /5 ]
]]]
Looping Spirals
PolySpiral StarSpiral
Recursion
Problem: How can we generate more interesting shapes from turtle programs?
Solution: Recursion
Fractals: Recursion made visible.
Motivation for Fractals
Representing Natural Objects
• Snowflakes, Mountains, Trees K
Drawing Interesting Pictures
Exploring Novel Mathematics
Performing Data Compression
Fractal Curves and Turtle Programs
Fractal Curves• Fractal curves usually cannot be represented by simple analytic expressions.• Fractal curves are generally defined by
-- Recursive Procedures-- Iterated Transformations-- Infinite Series
Turtle Programs• Recursion is used to express self-similarity.• Coordinates are irrelevant to shape.• Turtle programs are easily translated into fractal programs.
Examples• Fractal Gaskets• Bump Fractals• Other Self-Similar Fractals
Sierpinski Gasket
Sierpinski Gasket
Main Idea• Make a smaller Sierpinski gasket at one of the corners. • Then move to another corner and make another small Sierpinski gasket. • Then move to another corner and make another small Sierpinski gasket. • Then return the turtle to its initial position and heading.
Recursive Turtle ProgramSierpinski(Level)
If Level = 0, Draw a TriangleElse
Repeat 3 TimesRESIZE 1/2Sierpinski(Level–1)RESIZE 2MOVE 1TURN
€
2π /3
More Fractal Gaskets
Pentagonal Gasket Fractal Swiss Flag Rectangular Gasket
Koch Curve
Koch Bump
Koch Curve
Koch Curve
Basic Idea
• Make a smaller Koch curve along the first edge of the bump.
• Then move to the next edge and make another small Koch curve.
• Then move to the next edge and make another small Koch curve.
• Then move to the next edge and make another small Koch curve.
Simpler Approach
• Replace each straight line on the bump by a Koch curve.
• Replace each FORWARD command by a recursive call.
Koch Curve
Koch Bump Koch(Level)
If Level = 0, FORWARD 1
Else
RESIZE 1/3 → RESIZE 1/3FORWARD 1 → Koch(Level-1)TURN 60 → TURN 60FORWARD 1 → Koch(Level-1)TURN −120 → TURN −120FORWARD 1 → Koch(Level-1)TURN 60 → TURN 60FORWARD 1 → Koch(Level-1)RESIZE 3 → RESIZE 3
Universal Bump–Fractal Program
Bump Bump_Fractal(Level)
If Level = 0, FORWARD 1
Else
TURN A1 TURN A1RESIZE
€
S1 → RESIZE
€
S1FORWARD 1 → Bump_Fractal
€
(Level −1)TURN
€
A2 → TURN
€
A2RESIZE
€
S2 → RESIZE
€
S2FORWARD 1 → Bump_Fractal
€
(Level −1)
M MFORWARD 1 → Bump_Fractal
€
(Level −1)RESIZE
€
Sn+1 → RESIZE
€
Sn+1TURN
€
An+1 → TURN
€
An+1
Typical Bump Assumptions
1. Turtle Final Orientation = Turtle Initial Orientation• Total Turning = 0
•
€
Akk=1
n+1∑ = 0
2. Turtle Returns to Initial Line• Total Y–Distance = 0
•
€
SkSin Ajj=1
k∑
k=1
n∑ = 0
3. Turtle Travels Distance=Size Along Initial Line• Total X–Distance = Size
•
€
SkCos Ajj=1
k∑
k=1
n∑ =1
C–Curve
C-Bump
C-Curve
C–Curve
Bump C(Level)
If Level = 0, FORWARD 1
Else
TURN 45 → TURN 45
RESIZE
€
22
→ RESIZE
€
22
FORWARD 1 →
€
C Level −1( )TURN −90 → TURN −90FORWARD 1 →
€
C Level −1( )TURN 45 → TURN 45RESIZE
€
2 → RESIZE
€
2
More Bumps on Bumps
Additional Examples
• Rectangular Bumps
• Pentagonal Bumps
• Space Filling Curves
Additional Extensions
• Scales and Angles can be selected randomly.
• Each FORWARD command can be replaced by a different FRACTAL program.
• Fractal programs can be connected with TURN and FORWARD transitions.
More Self-Similar Fractals
Fractal Hangman Fractal Bush Fractal Tree
More Self-Similar Fractals
Fractal Star Fractal Flower Fractal Leaf
Recommended