Professional Documents
Culture Documents
Fractal
Fractal
Grafika Komputer
Pertemuan 8
Prof. Suyoto
This Week
• Approaches to Infinity
–Fractals and Self-Similarity
–Iterative Function Systems
–Lindenmayer Systems
–Curves
–Natural Images (trees, landscapes..)
• Mandelbrot and Julia Sets
• Generating realistic landscapes
Introduction
What is a Fractal?
– A fractal is an image with self-similar
properties produced by recursive or iterative
algorithmic means.
“anything which has a substantial measure of exact or statistical self-similarity”
F+F+F+F-F+F
L-Systems
Starting with:
F+F+F+F
and the production rule:
F -> F+F-F-FF+F+F-F
int ch;
while((ch = fgetc(ifp)) != -1)
{
switch(ch)
{
case 'F': fprintf(ofp,"%s",rule);
break;
default: fprintf(ofp,"%c",ch);
break;
}
}
fclose(ifp);
fclose(ofp);
remove("ldata.txt");
rename("ltemp.txt", "ldata.txt");
}
}
L-Systems
• Programming L-Systems
drawString(int len, float angle)
{
FILE *ifp;
if( (ifp = fopen("ldata.txt","r")) == NULL )
exit(-1); //cannot open files
int ch;
while( (ch = fgetc(ifp)) != -1)
{
switch(ch)
{
case 'F': cvs.forward(len, 1);
break;
case '+': cvs.turn(-angle);
break;
case '-': cvs.turn(angle);
break;
}
}
}
L-Systems
L-Systems
• Programming L- 1 iteration
Systems
– The more iterations you
do, the bigger the curve
will get..
– Therefore you need to
3 iterations
modify the length of the
sides depending on the
number of iterations.
L-Systems
• There is a limit to the number of shapes that
can be drawn with just and ‘F’ directive.
• L-Systems need to be restricted to just F,
you can use however many replacement
letters and strings you like.
L-Systems
• For example, F, X and Y:
• F -> ‘F’
• X -> ‘X+YF+’
• Y -> ‘-FX-Y’
• atom = “X” (starting string)
• But the turtle only draws with F
– This of course is no rule, you could make X and
Y draw as well… it is up to you!!!
L-Systems
The Dragon Curve
F -> ‘F’
X -> ‘X+YF+’
Y -> ‘-FX-Y’
atom = “X”
12 iterations
L-Systems
Koch Island
F -> ‘F+F-F-FF+F+F-F’
X -> ‘’
Y -> ‘’
atom = “F+F+F+F”
5 iterations
L-Systems
• If you look at a tree you will notice that it is
made up of smaller copies of itself.
• e.g. A tree branch is just a smaller version
of a tree.
• Being self-similar doesn’t mean each
smaller version has to be EXACTLY the
same.
L-Systems
• Lets look at a tree
F But that can’t
F be right?
F
F
F -> F+F-F
L-Systems
• Lets look at a tree
F
F
F return here
F
start here
F -> F+F-F
L-Systems
• Lets look at a tree
F
F
F return here
F
start here
F -> F[+F]-F
L-Systems
• Lets look at a tree
F -> F[+F][-F]
• An my personal favourite:
• Affine Transformations:
• T {a,b,c,d,e,f}
x' a b c x
y ' d e f . y
1 0 0 1 1
T1 {0,0,0,0,0.16,0}
T2 {0.2,-0.26,0,0.23,0.22,1.6}
T3 {-0.15,0.28,0,0.26,0.24,0.44}
T4 {0.75,0.04,0,-0.04,0.85,1.6}
Affine Transformations
• An my personal favourite:
Affine Transformations
• An my personal favourite:
Affine Transformations
• An my personal favourite:
Iterative Function Systems
•An iterative function system (IFS) takes a set
of affine transformations and transforms a
point through them based on a random
selection of the transformation.
• -mandelbrot_orbit.exe
Julia Sets
• Julia sets are extremely complicated sets of
points in the complex plane.
• There is a different Julia set for each value
of c.
• One version is the Filled Julia Set:
– the set of all starting points whose orbits are
finite.
Julia Sets
c = -0.5+0.58i
Julia Sets
c = -0.76+0.147i
Julia Sets
c = 0.32019+0.25694i
Julia Sets
c = -0.74+0.14i
Fractal Landscapes
Fractal Landscapes
Fractal Landscapes
Divide and Perturb
Fractal Landscape
Fractal Landscape
Fractal Landscape
Fractal Landscape
Fractal Landscape
Fractal Landscapes
• Brownian Motion
– divide and lift
– randomly cut a line in two, randomly lift that
point, then smooth surrounding area.
Fractal Landscapes
• Step One: Randomly
select a spot on a mesh
and raise height by a
random amount.
Fractal Landscapes
• Step Two: Slope from
tip of adjusted height
to edge of map.
Fractal Landscapes
• Step Three: Do this for
all edges of the map.
Fractal Landscapes
• Step Four: Smooth
sharp ridges by raising
surrounding surface to
an even slope.
Fractal Landscapes
• Step Five: Do this for
all four ridges.
Fractal Landscapes
• Step Six: Perform the
lifting and smooth
procedure as many
times as you like.
Fractal Landscapes
• Step Seven: Now
decide on a maximum
height and chop the
highest peaks off.