1. Fractal Rendering
in Developer C++
Computer Graphics Seminar
Aritra Sarkar
SC09B009
Department of Avionics
Indian Instituteof Space Science and Technology
2. Coding Platform
Developer C++
BloodshedDev-C++ is a full-featured Integrated Development
Environment (IDE) for the C and C++ programming languages.
It uses the MinGW or TDM-GCC 64bit port of the GCC as its
compiler. Dev-C++ can also be used in combination with Cygwin or
any otherGCC-based compiler
Main Package used
graphics.h
windows.h
Other options:Apophysis, XaoS, Terragen, Ultra Fractal
8. The Britain Coastline
The coastline paradox is the
counterintuitive observation
that the coastline of a
landmass does not have a
well-defined length. This
results from the fractal-like
properties of coastlines. The
first recorded observation of
this phenomenon was by
Lewis Fry Richardson.
11. Introduction to fractals
A fractal is a mathematical set that has a fractal dimension that
usuallyexceeds its topological dimension and may fall between the
integers. Fractals are typically self-similar patterns, where self-
similar means they are "the same from near as from far". Fractals
may be exactly the same at every scale, or, they may be nearly the
same at different scales.
As mathematical equations, fractals are usually nowhere
differentiable, which means that they cannot be measured in
traditionalways. An infinite fractal curve can be perceived of as
winding through space differently from an ordinary line, still being a
1-dimensional line yet having a fractal dimension indicating it also
resembles a surface.
12. • Irregularity locally and globally that is not easily described in traditional
Euclidean geometric language
• Simple and "perhaps recursive" definitions
• Fine or detailed structure at arbitrarily small scales.
• Self-similarity, which may be manifested as
• Exact self-similarity: identical at all scales; e.g. Koch snowflake
• Quasi self-similarity: approximates the same pattern at different scales;
may contain small copies of the entire fractal in distorted and
degenerate forms; e.g., the Mandelbrot set's satellites are
approximations of the entire set, but not exact copies
• Statistical self-similarity: repeats a pattern stochastically so numerical
or statistical measures are preserved across scales; e.g., randomly
generated fractals; the well-known example of the coastline of Britain,
for which one would not expect to find a segment scaled and repeated
as neatly as the repeated unit that defines, for example, the Koch
snowflake
• Qualitative self-similarity: as in a time series
• Multi-fractal scaling: characterized by more than one fractal dimension
or scaling rule
Types and identification
13. Objects that are rendered in Computer Graphics using fractals:
Clouds River networks
Fault lines Mountain ranges
Craters Lightning bolts
Coastlines Animal coloration patterns
Romanesco broccoli Snow flakes
Crystals Blood vessels and pulmonary vessels
Ocean waves DNA
Various vegetables (cauliflower, broccoli)
Phenomenon that are rendered in Science using fractals (apart from the above):
Heart rates Psychological subjective perception
Heartbeat Fractal Universe Theory
Earthquakes
Applications
14. Fractal antennas & transistor
Fractal heat exchangers
Digital imaging
Urban growth
Fractal landscape or Coastline complexity
Enzyme/enzymology (Michaelis-Menten kinetics)
Generation of new music
Signal and image compression
Creation of digital photographic enlargements
Seismology, geology, archeology and geography
Fractal in soil mechanics
Computer and video game design
Computer graphics
Organic environments
Fractography and fracture mechanics
Generation of patterns for camouflage, such as MARPAT
Technical analysis of price series
Fractals in networks
Neuroscience
Pathology
In technology
15. Dimensions
Topological Dimension < Hausdorff Dimension
Box Counting : log(n) / log(r)
n = number of partitions in each iteration
1/r = scaling factor of successive iterated parts
16. Cantor Set/Dust
Georg Cantor in 1883
Noise over transmission lines by
Benoit Mandelbrot for IBM
Fractal heartbeat
n = 2 ; 0 <1/r < 1
1D set : log(2) / log(3) = 0.6309
2D dust : log(4) / log(3) = 1.2619
void draw(float x1, float x2, float y1, float y2, int n, int c ) {
float x3,y3,x4,y4,x,y;
n++;
x=x2-x1;
rectangle(x1,y1,x2,y1+30);
setfillstyle(1,COLOR(180,180,180));
floodfill((x1+x2)/2,y1+10,COLOR(180,180,180));
if(n>6) return;
draw(x1,x1+x/3,y1+80,y1+80,n,0);
draw(x1+x*2/3,x2,y1+80,y1+80,n,0); }
17. Vicsek Saltire and Cross
n = 5
r = 3
Box Counting : log(5) / log(3) = 1.4649
The family of Vicsek fractals is one of the most
important and frequently studied regular fractal
classes, and it is of considerable interest to
understand the dynamical processes on treelike
fractal family.
19. Sierpinski Carpet / Menger Sponge
Wacław Sierpiński in 1915
n = 8
r = 3
Box Counting : log(8) / log(3) = 1.8928
20. T - Square
T-square has a fractal dimension of
log(4)/log(2) = 2. The black surface
extent is almost everywhere in the
bigger square, for, once a point has
been darkened, it remains black for
every other iteration; however some
points remain maroon.
The fractal dimension of the boundary
equals log(3)/log(2)= 1.58496.
21. Koch Curve / Anti-snowflake
Helge von Koch in 1904
n = 4
r = 3
Box Counting : log(4) / log(3) = 1.2619
Generalised:
Angle between 0 and 90 deg
Polygon n-flake
22. Dragon Curve
NASA physicists John Heighway, Bruce Banks, and William Harter
n = 2
r = sqrt(2)
Box Counting : log(2) / log(sqrt(2)) = 2
Can be tiled in many ways
23. Levy’s C
Paul Pierre Lévy
dimension : 1.9340
Used in detecting cancerous blood vessels in
kidneys
24. Pythagorean Tree
Albert E. Bosman in 1942
n = 2
r = 2/sqrt(2)
Box Counting : log(2) / log(2/sqrt(2)) = 2
26. Chaos Method
In mathematics, the term chaos game as coined by
Michael Barnsley, originally referred to a method of
creating a fractal, using a polygon and an initial point
selected at random inside it. The fractal is created by
iteratively creating a sequence of points, starting with the
initial random point, in which each point in the sequence
is a given fraction of the distance between the previous
point and one of the vertices of the polygon; the vertex is
chosen at random in each iteration. Repeating this
iterative process a large number of times, selecting the
vertex at random on each iteration, and throwing out the
first few points in the sequence, will often (but not
always) produce a fractal shape.
The "chaos game" method plots points in random order
all over the attractor. This is in contrast to other methods
of drawing fractals, which test each pixel on the screen
to see whether it belongs to the fractal. The general
shape of a fractal can be plotted quickly with the "chaos
game" method, but it may be difficult to plot some areas
of the fractal in detail.
28. Quasi-symmetric Fractals
In ComputerGraphics systems, Quasi-symmetric fractals are
rendered by rate of convergence of a complex iterative function.
The steps are:
• x-y (column – row) place is modeled as Complex Plane
(Argand’s Plane)
• For each coordinatepixel generate an initial seed
• Iterate the complex function till a particularvalue is reached
(or for a fixed number of times)
• Colourregions based on the number of iterations taken to reach
the value (or value reached after fixed iterations)
30. Orbit Traps
Colour each pixel based on minimum distance of z achieved from a fixed
point during n-iteration.
It has two types:
1. Point Based
2. Line Based e.g. Pickover Stalks
31. Random Counters
The Buddhabrot is rendered by first creating a 2-dimensional array of counters, each
counter corresponding to a final pixel of the image initialized to zero. A random
sampling of c points are iterated through the Mandelbrot function. For points which do
escape within a chosen maximum number of iterations, thus not in the Mandelbrot set,
their values are sent through the Mandelbrot function again and this time its path is
plotted into the array. After a large number of c values have been iterated, grayscale
shades are then chosen based on the values recorded in the array. The result is a density
plot highlighting regions where z values spend the most time on their way to infinity.
1993 Usenet post to scientific fractals by Melinda Green first mentions it.
32. Julia
Gaston Julia and Pierre Fatou
zn+1 = zn
2 + c
z2x=pow(z1x,2)-pow(z1y,2)-0.835;
z2y=2*z1x*z1y-0.212;
z=sqrt(pow(z2x,2)+pow(z2y,2));
z1x=z2x;
z1y=z2y;
33. Burning Ship
Michael Michelitsch and Otto E. Rössler in 1992
main() {
initwindow(1350,680,"IMAGE 1",0,0);
float cx,cy,z1x=0,z1y=0,zdum,z; int k;
for(int i=1;i<1350;i++) {
for(int j=1;j<680;j++) {
cx=i*.0002-1.9;
cy=j*.0002-0.1;
z1x=0;z1y=0;
z=sqrt(pow(z1x,2)+pow(z1y,2));
for(k=1;k<100&&z<6;k++) {
zdum=pow(z1x,2)-pow(z1y,2)+cx;
z1y=2*fabs(z1x)*fabs(z1y)+cy;
z1x=zdum;
z=sqrt(pow(z1x,2)+pow(z1y,2)); }
if(k<9) {putpixel(i,j,COLOR(20,20,k*1.7));}
else if(k<19) {putpixel(i,j,COLOR(20,20,k*30));}
else if(k<40) {putpixel(i,j,COLOR(180-k*20,180-k*20,20));}
else if(k<90) {putpixel(i,j,COLOR(180-k*10,20,20));}
else putpixel(i,j,COLOR(0,0,0)); }}
writeimagefile(“Burning Ship.jpeg",0,0,1350,680);
getch(); }
34. Phoenix
Zn+1 = Z2
n + Re(C) + Im(C)*Zn-1
where: C = Re(C)+i*Im(C), Re(C) and Im(C) are x and y coordinates.
Initial value of Z = 0
35. Glynn Set
Earl F. Glynn, from Julia Set
z = ze + mu where: mu=a+bi & e = 1.5
main() {
initwindow(1335,680,"IMAGE 1",0,0);
float cx,cy,z1x=0,z1y=0,zdum1,zdum2,znxt=0,zprex,zprey,th;
int k;
for(int i=1;i<1350;i++) {
for(int j=1;j<680;j++) {
cy=i*.00028-0.1872;
cx=j*-0.00043-0.392;
z1x=cx; z1y=cy;
zdum1=cx;zdum2=cy;
for(k=1;(k<100&&(zdum1+zdum2)<16);k++) {
zdum1=z1x*z1x;
zdum2=z1y*z1y;
th=atan2(z1y,z1x);
z1x=pow(sqrt(zdum1+zdum2),1.5)*cos(1.5*th)-0.2;
z1y=pow(sqrt(zdum1+zdum2),1.5)*sin(1.5*th)-0.0; }
putpixel(i,j,COLOR(abs(z1y-340)/abs(z1x-775),k*2.5,60)); }}
writeimagefile(“Glynn.jpeg",0,0,1335,680);
getch(); }
36. Diffusion-limited aggregation
Diffusion-limited aggregation (DLA) is the process whereby particles undergoing a
random walk due to Brownian motion cluster together to form aggregates of such particles.
This theory, proposed by Witten and Sander in 1981, is applicable to aggregation in any
system where diffusion is the primary means of transport in the system. DLA can be
observed in many systems such as electro-deposition, Hele-Shaw flow, mineral deposits,
and dielectric breakdown.
The clusters formed in DLA processes are referred to as Brownian trees. These clusters are
an example of a fractal. In 2-D these fractals exhibit a dimension of approximately 1.71 for
free particles that are unrestricted by a lattice
37. 3D Fractals - Mandelbulb
Requires ray-tracing or similar colouring techinques and Quaternion Mathematics
38. Surface Rendering
Extension of Geometric Fractals, in 3 dimension
May use noise models (e.g. Perlin Noise)
Used extensively in Computer Games and Animated movies
E.g. StarWars Death Star, Star Trek Borg Cubes
39. Living on the Edge
Fractals are widely known as the Equations of Nature, they
are also the Boundary of Chaos.
The present universe can also be modeled as Fractal
Universe, with us at the boundary of a chaotic creation. The
perfect parameters that created the beauty of nature, as we
know it. The best variability possible, keeping the system
stable. A slight shift, and all would have been chaotic.
40. References
“The Fractal Geometry of Nature” by Benoit Mandelbrot
http://www.bugman123.com/Fractals/index.html
http://en.wikipedia.org/wiki/List_of_fractals_by_Hausdorff_dimens
ion
“IntroducingFractals:A Graphic Guide” by Nigel Lesmoir-Gordon
“Chaos:A Very Short Introduction”by Leonard A. Smith
“Chaos” by James Gleick
……. and Google image search
41. Acknowledgements
I would like to take this opportunity to thank
Harsh Agarwal
Aerospace, IIST, 2009 Batch
for teaching me the basics of Fractal Programming
in Developer C++ in our 2nd Semester (Feb – May 2010)
and all the participants of
Conscientia 2011
R-Dimension (Fractal Rendering Workshop)
conducted by Harsh Agarwal and me,
for the valuable discussion sessions