29
Turtles and Fractals Ron Goldman Department of Computer Science Rice University

Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

Turtles and Fractals

Ron GoldmanDepartment of Computer ScienceRice University

Page 2: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

Fractals

Sierpinski Triangle Fractal Swiss Flag

Koch Snowflake C-Curve

Page 3: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

Basic Turtle Programs

POLY (Length, Angle)

Repeat Forever

FORWARD (Length)

TURN (Angle)

SPIRAL (Length, Angle, Scalefactor)

Repeat Forever

FORWARD (Length)

TURN (Angle)

RESIZE (Scalefactor)

Page 4: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

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.

Page 5: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

Examples of POLY Procedures

Angle = π / 5

Angle = 3π / 7

Angle = π 2 / 2

Page 6: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

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

Page 7: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

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.

Page 8: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

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.

Page 9: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

Looping Program and Polygon Procedure

LoopingPr ogram

PolygonProcedure •

• LoopingPr ogram

Page 10: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

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

Page 11: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

Looping Curve

Page 12: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

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 ]

]]]

Page 13: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

Looping Spirals

PolySpiral StarSpiral

Page 14: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

Recursion

Problem: How can we generate more interesting shapes from turtle programs?

Solution: Recursion

Fractals: Recursion made visible.

Page 15: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

Motivation for Fractals

Representing Natural Objects

• Snowflakes, Mountains, Trees K

Drawing Interesting Pictures

Exploring Novel Mathematics

Performing Data Compression

Page 16: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

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

Page 17: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

Sierpinski Gasket

Page 18: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

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

Page 19: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

More Fractal Gaskets

Pentagonal Gasket Fractal Swiss Flag Rectangular Gasket

Page 20: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

Koch Curve

Koch Bump

Koch Curve

Page 21: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

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.

Page 22: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

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

Page 23: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

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

Page 24: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

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

Page 25: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

C–Curve

C-Bump

C-Curve

Page 26: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

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

Page 27: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

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.

Page 28: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

More Self-Similar Fractals

Fractal Hangman Fractal Bush Fractal Tree

Page 29: Turtles and Fractals - Rice UniversityFractal Curves and Turtle Programs Fractal Curves • Fractal curves usually cannot be represented by simple analytic expressions. • Fractal

More Self-Similar Fractals

Fractal Star Fractal Flower Fractal Leaf