1 Line replacement approach Koch Star (Snowflake) Area replacement approach Sierpenski Triangle Iterated Function System approach Heighway Dragon CSE 20232.

Slides:



Advertisements
Similar presentations
Two Special Right Triangles
Advertisements

Fundamentals of Engineering
Fractals with a Special Look at Sierpinskis Triangle By Carolyn Costello.
Make an Origami Jumping Frog
Chapter 14 Graph class design Bjarne Stroustrup
The Case of the Missing Coordinates
Business Transaction Management Software for Application Coordination 1 Business Processes and Coordination.
Coordinate Plane Practice The following presentation provides practice in two skillsThe following presentation provides practice in two skills –Graphing.
0 - 0.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Addition Facts
7.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 7 Introducing SVG Transformations on Elements.
GR2 Advanced Computer Graphics AGR
GR2 Advanced Computer Graphics AGR
9.1si31_2001 SI31 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture.
13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.
Iteration, the Julia Set, and the Mandelbrot Set.
Calypso Construction Features
Part- I {Conic Sections}
Pre-Calculus Chapter 6 Additional Topics in Trigonometry.
Recursive Strategies Eric Roberts CS 106B January 23, 2013.
Copyright 2012, 2008, 2004, 2000 Pearson Education, Inc.
Vector-Valued Functions 12 Copyright © Cengage Learning. All rights reserved.
Determining if a Triangle is Possible
Squares and Square Root WALK. Solve each problem REVIEW:
Splines I – Curves and Properties
Addition 1’s to 20.
25 seconds left…...
1. How many sides has a hexagon? a.5 b.6 c.7 d.8 b. 6.
Test B, 100 Subtraction Facts
Week 1.
© 2008 Pearson Addison-Wesley. All rights reserved Chapter 10 Modeling with Geometry.
April 12: Today’s activities: 1.Fold a circle to a …. 2.Movie (& cutting) 3.Four triangle problem (three parts) a. Making polygons b. Same and different.
CSE Lecture 17 – Balanced trees
Bottoms Up Factoring. Start with the X-box 3-9 Product Sum
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Right Triangles Consider the following equilateral triangle, with each side having a value of 2. Drop a perpendicular segment from the top vertex.
40S Applied Math Mr. Knight – Killarney School Slide 1 Unit: Sequences Lesson: SEQ-L3 Drawing Fractal Patterns Drawing Fractal Patterns Learning Outcome.
Finding Volumes.
Chapter 9: Recursive Methods and Fractals E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley Mohan Sridharan Based on Slides.
Homework discussion Read pages 388 – 391 Page 400: 49 – 52, 72.
Recursion: Overview What is Recursion? Reasons to think recursively? An Example How does recursion work?
The Wonderful World of Fractals
Approaches To Infinity. Fractals Self Similarity – They appear the same at every scale, no matter how much enlarged.
Module 7 Lesson 8 Create a tangram puzzle and observe relationships among shapes.
Structured Chaos: Using Mata and Stata to Draw Fractals
1 Excursions in Modern Mathematics Sixth Edition Peter Tannenbaum.
Fractals Nicole MacFarlane December 1 st, What are Fractals? Fractals are never- ending patterns. Many objects in nature have what is called a ‘self-
How complex ~ Developed by Andrew Derer ~ MathScience Innovation Center, Richmond, VA.
Infinities 6 Iteration Number, Algebra and Geometry.
Ch 9 Infinity page 1CSC 367 Fractals (9.2) Self similar curves appear identical at every level of detail often created by recursively drawing lines.
Some Fractals and Fractal Dimensions. The Cantor set: we take a line segment, and remove the middle third. For each remaining piece, we again remove the.
Koch Curve How to draw a Koch curve.. Start with a line segment (STAGE 0) *Divide the line into thirds *In the middle third produce an equilateral triangle.
Section 6.1 Images Viewing a Gallery of Fractals. Look for patterns.
CS324e - Elements of Graphics and Visualization Fractals and 3D Landscapes.
Learn about the quadrilaterals Understand the different types of quadrilaterals Students and Teachers will be able to.
Fractals! Bullock Math Academy March 22, 2014 Brian Shelburne
To find the perimeter of a rectangle, just add up all the lengths of the sides: Perimeter = L + w + L + w         = 2L + 2w To find the area of a rectangle,
Polygons A polygon is a plane shape with straight sides.
The Further Mathematics Support Programme Our aim is to increase the uptake of AS and A level Mathematics and Further Mathematics to ensure that more.
Geometry Origami - Angelfish
Fractals Project Natalie Rowe.
HONR 300/CMSC 491 Fractals (Flake, Ch. 5)
Finding Volumes.
S.K.H. Bishop Mok Sau Tseng Secondary School
HONR 300/CMSC 491 Fractals (Flake, Ch. 5)
The Wonderful World of Fractals
Presentation transcript:

1 Line replacement approach Koch Star (Snowflake) Area replacement approach Sierpenski Triangle Iterated Function System approach Heighway Dragon CSE Lecture 34 – Procedural Fractals

2 Line replacement Fractal shapes are based on lines or curves that are replaced by sequences of similar lines or curves at each level of recursion Shapes are self-similar Same/similar shapes at every level Examples Koch Star (Snowflake) Sierpenski Dragon Heighway Dragon

3 Area Replacement Fractal shapes are based on simple shapes that are replaced or cut out with collections of the same or similar shapes Again, these are self-similar at all levels of detail Examples Box Fractal (our Square) Sierpenski Triangle (our Gasket) Sierpenski Carpet

4 Iterated Function System A method of generating a fractal by repeated application of a set of functions Each application typically moves one point on the fractal to another Examples Mandelbrot & Julia Sets (escape time measure) Heighway Dragon (two functions selected at random) Fern (4 functions randomly chosen with set frequencies)

5 Koch Star Based on 3 Koch Curves (triangle shape) Start each curve with a line segment Subdivide segment into thirds Replace middle third with two sides of an equilateral triangle that would have had the replaced edge segment as its third side These bump-outs always go on the same side of the original line Original segment after first replacement

6 Koch Star Initial shape (3 edges forming an equilateral triangle) Snowflake shown at detail levels 1, 2, 3, 4 Images from wikipedia.com

7 Koch Star // need to pass WinStuff &X or use it globally void KochStar::draw(void) { if (Xwin->isOpen()) { // call function to draw (after subdividing as necessary) // each of the three triangle edges subdivide_edge_and_draw(pt[0],pt[1],depth); subdivide_edge_and_draw(pt[1],pt[2],depth); subdivide_edge_and_draw(pt[2],pt[0],depth); } // NOTE: the corner points are in the vector pt; // and each has an x and y coordinate. KochStar is a class // that inherits from Shape and the outline of any shape is // a polygon of edges between point pairs in the sequence // pt[0] to pt[1], pt[1] to pt[2],..., pt[n-1] to pt[0]

8 Koch Star edge manipulation void KochStar::subdivide_edge_and_draw( const Point& a, const Point& b, int rec_depth) { if (rec_depth > 1) { // Point ab1 is 1/3 distance from a to b Point ab1( (2.0*a.getx()+b.getx()) / 3.0, (2.0*a.gety()+b.gety()) / 3.0); // Point ab2 is 2/3 distance from a to b Point ab2( (a.getx()+2.0*b.getx()) / 3.0, (a.gety()+2.0*b.gety()) / 3.0); // calculate length of current edge (a,b) double dx = b.getx() - a.getx(); double dy = b.gety() - a.gety(); double L = sqrt(dx*dx + dy*dy);

9 Koch Star edge manipulation // calculate the direction of the current edge (a,b) double theta = atan2(dy,dx); // increase angle by 60 degrees theta += PI/3.0; if (theta < 0.0) theta = 2.0*PI + theta; // calculate coordinates of point bumped out from triangle // it starts at point ab1 and runs at angle theta for 1/3 the // original edge length double outx = ab1.getx() + L*cos(theta)/3.0; double outy = ab1.gety() + L*sin(theta)/3.0;

10 Koch Star edge manipulation // create a Point with these coordiantes Point bump(outx,outy); // make recursive calls to further subdivide edges and draw // note: rec_depth is decreased by 1 in each call subdivide_edge_and_draw(a,ab1,rec_depth-1); // edge (a,ab1) subdivide_edge_and_draw(ab1,bump,rec_depth-1); // edge (ab1,bump) subdivide_edge_and_draw(bump,ab2,rec_depth-1); // edge (bump,ab2) subdivide_edge_and_draw(ab2,b,rec_depth-1); // edge (ab2,b) } else // now draw the small edge piece from a to b Xwin->X_draw_edge(a.getx(),a.gety(),b.getx(),b.gety(),colorX); }

11 Sierpenski Dragon Based on 4 curves (square shape) Start each curve with a line segment Subdivide segment into fourths Replace middle two segments with three sides of a square that would have had the replaced edge segment as its fourth side These bump-outs always go out and then in Original segment after first replacement

12 Sierpenski Dragon Initial shape (4 edges forming a square) Dragon shown at detail levels 1, 2, 3

13 Square Gasket Based on a square shape Start with a single square Replace the square with 5, each having a side length 1/3 rd that of the original Replacement squares go in each corner and the center Original after 1 st replacement after 2 nd

14 Square Gasket void Square::draw() { if (Xwin->isOpen()) { // if this is a depth 1 Square then actually draw it if (depth == 1) // Xlib code to draw 4 edges bounding the square for (int i=0; i<4; i++) Xwin->X_draw_edge(pt[i].getx(),pt[i].gety(), pt[(i+1)%4].getx(),pt[(i+1)%4].gety(), colorX); else // Otherwise, subdivide & draw smaller Squares subdivide_and_draw(); }

15 Square subdivision void Square::subdivide_and_draw(void) { double mult=1.0; // 0.5 or other value for interesting shapes if (depth > 1) { // new squares have sides 1/3 length of original double newSide = fabs(pt[0].getx()-pt[2].getx())/3.0; // Center is halfway between opposite corners pt[0] & pt[2] double cx = 0.5*(pt[0].getx()+pt[2].getx()); double cy = 0.5*(pt[0].gety()+pt[2].gety()); // 5 new squares 1/3 side size as originals Square s1(Xwin,Point(cx,cy),newSide); Square s2(Xwin,Point(cx+mult*newSide,cy+mult*newSide),newSide); Square s3(Xwin,Point(cx+mult*newSide,cy-mult*newSide),newSide); Square s4(Xwin,Point(cx-mult*newSide,cy+mult*newSide),newSide); Square s5(Xwin,Point(cx-mult*newSide,cy-mult*newSide),newSide);

16 Square subdivision // set color of 5 new Squares same as this one int r, g, b; getColor(r,g,b); s1.setColor(r,g,b); s2.setColor(r,g,b); s3.setColor(r,g,b); s4.setColor(r,g,b); s5.setColor(r,g,b); // set depth to 1 less than this Square s1.setDepth(depth-1); s2.setDepth(depth-1); s3.setDepth(depth-1); s4.setDepth(depth-1); s5.setDepth(depth-1); // draw the 5 smaller Squares s1.draw(); s2.draw(); s3.draw(); s4.draw(); s5.draw(); }

17 Sierpenski Gasket Based on a triangle shape Start with a single triangle Replace the triangle with 3, each having a side length 1/2 that of the original Replacement triangles go in each corner Original after 1 st replacement after 2 nd

18 Heighway Dragon Producible in several ways Folding Fold strip of paper in half, again and again, in same direction Unfold so each fold is 90 degrees and look at shape edge-on Line replacement Start with a line (length L) Replace with two segments L/sqrt(2) forming an isosceles triangle with original The replace each of these in turn, the same way, but alternate direction of bump, left, right, left, … Levels of detail 1,2,3,4 from wikipedia.com

19 Heighway Dragon Producible in several ways Iterative Function System Start with Z as the origin of the complex plane Randomly alternate between these two functions to derive next point Z from previous Z = ((1+j)*Z)/2 Z = 1 –((1-j)*Z)/2 The UNION of all such points is the Dragon Example: 100,000 iterations

20 Heighway Dragon IFS (main) // as in Mandelbrot set program, image size is ROWS x COLUMNS, // complex plane is LEFT..RIGHT, TOP..BOTTOM for (r=0;r<ROWS;r++) for (c=0;c<COLUMNS;c++) image[r][c] = 0; // set all pixels to black Z.setReal(0.0); Z.setImaginary(0.0); for (int i=0; i<count; i++) { nextPoint(Z); // finds next Z in IFS defining dragon r = (int)((TOP-Z.getImaginary())/dy); // find image row c = (int)((Z.getReal()- LEFT)/dx); // find image column if (0 <= r && r < ROWS && 0 <= c && c < COLUMNS) image[r][c] = 32 + i%224; // set pixel color else cout << "bad r,c" << r << ' ' << c << endl; }

21 Heighway Dragon IFS (calc) // the Heighway Dragon is defined by applying each of the // following functions to the previous value of Z in order // to find the next value of Z. The choice of which to // apply is random. void nextPoint(Complex& Z) { if (rand()%2) Z = 0.5*Complex(1.0,1.0)*Z; else Z = *Complex(1.0,-1.0)*Z; }

22 Our Fractal Shape Inheritance Hierarchy (for last homework) Point Simple location in 2D plane Shape Polygon with edges between sequence of Point pairs KochStar : Shape Triangle based, edge division and replacement Square : Shape Square based, area division and replacement SerpGasket* : Shape Triangle based, area subdivision and replacement SerpDragon* : Shape Square based, edge division and replacement * you will complete these based on given examples