Title: Programming Snazzy Fractals
1Programming Snazzy Fractals
- Roshanak Roshandel Adair Dingle
- Department of Computer Science
- and Software Engineering
- Seattle University
2Euclidean Geometry
3Can we describe nature using Euclidean Geometry?
- Tree using cylinders??
- Mountains using triangles??
- Clouds using circles??
- Leaves??
- Rocks??
4Well
- We can describe man made structures using
Euclidean geometry - But nature is full of rough edges and non uniform
shapes - Geometry of irregular shapes, non-smooth edges,
infinite details, and infinite length
5(No Transcript)
6(No Transcript)
7(No Transcript)
8(No Transcript)
9(No Transcript)
10(No Transcript)
11(No Transcript)
12(No Transcript)
13(No Transcript)
14What is a Fractal?
- Geometric figures just like circles and
rectangles, but they also have some special
properties - Structural self-similarity
- All over nature
- Flowers, trees, mountains, stalagmite, snow
flakes, - Fractals are objects that look the same
regardless of the magnification
15(No Transcript)
16The Sierpinski Triangle
- Step 1 Draw an equilateral triangle with sides
of 2 triangle lengths each. Connect the
midpoints of each side.
How many shaded triangles?
How many equilateral triangles do you now have?
17Step 2
- Draw another equilateral triangle with sides of 4
triangle lengths each. - Connect the midpoints of the sides and shade the
triangle in the center as before.
How many shaded triangles now?
18Step 3
How many shaded triangle now?
19Step 4
How many shaded triangles Now? What if we keep
going?
20The Koch Snowflake
First step
After 2 steps
21After 3 steps
22After n steps
23The Koch snowflake is six of these put together
to form . . .
. . . a snowflake.
24Notice that the perimeter of the Koch snowflake
is infinite . . .
. . . but that the area it bounds is finite
(sure enough, it is contained in the white
square).
25Do you see a pattern?
- We have to do something over and over and over
again - Its hard!
- Its tedious!
- Can we get help?
26What can computers do?
- Computers are really good at
- following instructions
- processing data you provide (names, numbers,
etc.) - making decisions according to rules you specify
- repeating, repeating, repeating and repeating
- Lets look at some examples from Python
Programming Language
271) following instructions
- Load the software (the Python interpreter) that
will obey your commands! - Type 'python
- You will see the interpreter's prompt gtgtgt
- This prompt tells you that the interpreter is
waiting for another command.
28Try the Following
- gtgtgt print "hello"
- gtgtgt print "name" use your name
- gtgtgt myName "name"
- gtgtgt print "hello " myName
292) Processing Data You Provide
- Let's use the Python interpreter as a calculator
to see how it processes numbers. - gtgtgt38 4
- gtgtgt23428973 345/3
30Calculations.
- gtgtgt x int(raw_input('Please enter an integer
')) - gtgtgt y int(raw_input('Please enter an integer
')) - gtgtgt x y
- gtgtgt x y
313) making decisions according to rules you specify
- gtgtgt myWord raw_input('Please input a word')
- gtgtgt if (myWord is myName)
- ... print "Hello, oh great master " myName
- ... else
- ... print myWord " is not recognized by my
instructions"
324) Repeating Repeating Repeating
- gtgtgt for i in range(1, 10)
- ... print myName
- gtgtgt for i in range(1, 10)
- ... for j in range(1,5)
- ... print myName,
- ... print " is great!"
33Loops
- gtgtgt for i in range(1, 10)
- ... print myName " is
- ... for j in range(1,5)
- ... print "great, ",
- ... print "great!"
34Function
- Do we have to type everything all the time? Can
we store some instructions to be used later on? - gtgtgt def WordCompare(someWord)
- ... if (someWord is myName)
- ... print "Hello, oh great master " myName
- ... else
- ... print someWord " is not recognized by my
instructions"
35Now lets do some fractal programming!
36Resources
- Download Python Interpreter
- http//www.python.org
- For this presentation go to
- http//fac-staff.seattleu.edu/roshanak/fractals
- Questions? Send us an email
- roshanak_at_seattleu.edu
- dingle_at_seattleu.edu