You are on page 1of 34

COMPUTER GRAPHICS

ASSIGNMENT 3

Submitted by :- Roop Basant CSB19054


Submitted To:- Prof. Rosy Sarmah
FRACTALS
Definition:-

A curve or geometrical figure , each part of which has the same statistical character
as the whole.

A fractal is a non regular geometric shape that has same degree of non - regularity
on all scales. So fractals can be thought of never- ending patterns.

In mathematics , a fractals is subset of Euclidean space with a fractal dimension that


strictly exceeds its topological dimension.

Fractals often exhibit similar patterns at increasingly smaller scales, a property is


called self similarity.
The Mandelbrot himself summarised the fractals as “beautiful, damn
hard ,increasingly useful.

Initially the Mandelbrot defined the fractals as follows: “ A fractals is a set for
which the Hausdorff - Besicovitch dimension strictly exceeds the topological
dimension.
Mathematical formula use to generate a fractal

Julia Set
The Julia Set equation is:
Zn+1 = (Zn)2 + c
A self squaring function
For the Julia Set, the value of c remains constant and
the value of Zn changes
If we start with the complex number Z1= 0.5 + 0.6j, and let

displaystyle{c}={0.3}
c=0.3 and then feed this into the formula above, we have:

Z2 = (0.5 + 0.6j)2 + 0.3 = 0.19 + 0.6j

We now take this new answer and feed it back in:

Z3 = (0.19 + 0.6j)2 + 0.3 = -0.0239 + 0.228


Continuing, we find that

Z4 = 0.24858721 − 0.0108984j and

Z5 = 0.3616768258

− 0.005418405698j
Name and Example of some fractals

Wassily Kandinsky Mobius Nautilus Square


MandelBulb Richard Feynman
Fractal
Two People’s history and their contribution in the field of
fractals

Benoit B.Mandelbrot
November 1924 – 14 October 2010) was a Polish-born French-American
mathematician and polymath with broad interests in the practical sciences,
especially regarding what he labeled as "the art of roughness" of physical
phenomena and "the uncontrolled element in life". He referred to himself as a
"fractalist" and is recognized for his contribution to the field of fractal geometry,
which included coining the word "fractal", as well as developing a theory of
"roughness and self-similarity" in nature.
In 1936, while he was a child, Mandelbrot's family emigrated to France
from Warsaw, Poland. After World War II ended, Mandelbrot studied
mathematics, graduating from universities in Paris and the United States
and receiving a master's degree in aeronautics from the
California Institute of Technology. ..

Because of his access to IBM's computers, Mandelbrot was one of the


first to use computer graphics to create and display fractal geometric
images, leading to his discovery of the Mandelbrot set in 1980. He
showed how visual complexity can be created from simple rules.
Developing "fractal geometry" and the Mandelbrot set
In 1975, Mandelbrot coined the term fractal to describe these structures
and first published his ideas in the French book Les Objets Fractals:
Forme, Hasard et Dimension, later translated in 1977 as Fractals: Form,
Chance and Dimension.

Mandelbrot ended up doing a great piece of science and identifying a


much stronger and more fundamental idea—put simply, that there are
some geometric shapes, which he called "fractals", that are equally
"rough" at all scales.
Fractals and the "theory of roughness"
Mandelbrot created the first-ever "theory of roughness", and he saw
"roughness" in the shapes of mountains, coastlines and river basins; the
structures of plants, blood vessels and lungs; the clustering of galaxies. His
personal quest was to create some mathematical formula to measure the
overall "roughness" of such objects in nature.

Fractals are also found in human pursuits, such as music, painting,


architecture, and stock market prices. Mandelbrot believed that fractals, far
from being unnatural, were in many ways more intuitive and natural than the
artificially smooth objects of traditional Euclidean geometry:

Mandelbrot emphasized the use of fractals as realistic and useful models for
describing many "rough" phenomena in the real world. He concluded that "real
roughness is often fractal and can be measured.
Sierpinski
He was a Polish mathematician. He was known for contributions to set theory
(research on the axiom of choice and the continuum hypothesis), number theory,
theory of functions and topology. He published over 700 papers and 50 books.
Sierpiński enrolled in the Department of Mathematics and Physics at the
University of Warsaw in 1899 and graduated four years later. In 1903, while still
at the University of Warsaw, the Department of Mathematics and Physics offered
a prize for the best essay from a student on Voronoy's contribution to number
theory. Sierpiński was awarded a gold medal for his essay, thus laying the
foundation for his first major mathematical contribution.
Three well-known fractals are named after him (the Sierpiński triangle, the
Sierpiński carpet, and the Sierpiński curve), as are Sierpiński numbers
and the associated Sierpiński problem .
Self Similarity

In mathematics, a self-similar object is exactly or approximately similar to a part of itself


(i.e., the whole has the same shape as one or more of the parts).Self-similarity is a typical
property of fractals.
A time developing phenomenon is said to exhibit self-similarity if the numerical value of
certain observable quantity

{\displaystyle f(x,t)}

measured at different times are different but the corresponding dimensionless quantity at
given value of

{\displaystyle x/t^{z}}

remain invariant.
Five natural fractals with their name
Fern Sea Shells
Romanescu Lightning
Dancing Peacock
Iteration
Iteration means the repetition of a single formula again & again with slightly different value based on the
previous iteration result. Using iteration by the fractal function to generate complex pictures.

Different types of Iteration:-

1. Integer iteration

The usual definition of iteration, where the functional equation:

{\displaystyle f^{n}(x)=f(f^{n-1}(x))}
is used to generate the sequence:

{\displaystyle \{f(x),f^{2}(x),f^{3}(x),...\}}
known as the natural iterates of f(x), which forms a monoid under composition.

For invertible functions f(x), the inverses are also considered iterates, and form the sequence:
{\displaystyle \{...,f^{-2}(x),f^{-1}(x),x,f(x),f^{2}(x),...\}}
known as the integer iterates of f(x), which forms a group under composition.
Fractional iteration :-
Solving the functional equation: f(x)=g^{n}(x) Once this functional equation is solved, then the
rational iterates f^{(m/n)}(x) are the integer iterates of g(x).

Continuous iteration :-
A generalization of the usual notion of iteration, where the functional equation (FE): f n(x) = f(f n-
1(x)) must be satisfied for all n in the domain (real or complex).
Sierpinski Gasket:-
#include <GL/glut.h>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<iostream>
using namespace std
//points
float xa = 400;
float ya = 200;
float xb = 400;
float yb = 600;
float xc = 600;
float yc = 400;
float xd=600;
float yd=100;
float x = xa;
float y = ya;
//sierpinski

void draw_sierpinskl() {

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

glOrtho(0, 1080, 0, 720, -1, 1); //set range

glBegin(GL_POINTS); //to plot points

glColor3f(0,1,1); //R G B color of point

glVertex2f(xa,ya);

glVertex2f(xb,yb);

glVertex2f(xc,yc);

float div=2;

for(int i=0; i<100000; i++) {

float r;

r = (rand()%3);

if(r == 0) {

x = (x+xa)/div;

y = (y+ya)/div;

}
if(r == 1) { x = (x+xb)/div;

y = (y+yb)/div;

if(r == 2) {

x = (x+xc)/div;

y = (y+yc)/div;

glVertex2f(x,y);

glEnd(); //to end glBegin()

glFlush();

int main(int argc, char** argv) {

glutInit(&argc, argv);

glutCreateWindow("Sierpinski");

glutInitWindowSize(1080, 720);

glutInitWindowPosition(150, 150);

glutDisplayFunc(draw_sierpinskl);

glutMainLoop();

return 0; }
Sierpinski gasket
Chaos_Game :-
#include <chrono>
#include <iostream>
#include <random>
#include <thread>
#include <GL/gl.h>
#define WIDTH 768
#define HEIGHT 768
using namespace std;

struct point{
double x;
double y;
};

int main(int argc, char * argv[]){

int depth = 131072;


if(argc > 1){
depth = atoi(argv[1]);
}

glfwInit();

GLFWwindow * window = glfwCreateWindow(WIDTH, HEIGHT, "Chaos Game!", NULL, NULL);

if(!window){
return -1;
}

glfwMakeContextCurrent(window);
glOrtho(-WIDTH/2, WIDTH/2, 0, HEIGHT, -1.0, 1.0);

int num_corners = 5;
point corners[num_corners];
corners[0].x = 0;
corners[0].y = HEIGHT;
corners[1].x = WIDTH/2;
corners[1].y = 0;
corners[2].x = -WIDTH/2;
corners[2].y = 0;
default_random_engine rand;
uniform_real_distribution<double> height_dist(0.0, (double) HEIGHT);
uniform_real_distribution<double> width_dist((double) -WIDTH/2.0, (double) WIDTH/2.0);
uniform_int_distribution<int> corner_dist(0, num_corners-1);
while(true){

glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
chrono::high_resolution_clock::time_point start = chrono::high_resolution_clock::now();
point p;
p.x = width_dist(rand);
p.y = height_dist(rand);

for(int i = 0; i < depth; i++){

int corner = corner_dist(rand);


p.x = p.x - (p.x - corners[corner].x) / 2.0;
p.y = p.y - (p.y - corners[corner].y) / 2.0;

if(i > 32){


if(p.y > HEIGHT/2){
glColor3f(0.0f, 1.0f, 0.0f);
}
else{
if(p.x > 0){
glColor3f(1.0f, 0.0f, 0.0f);
}
else{
glColor3f(0.0f, 0.0f, 1.0f);
}
}
glVertex2i(p.x, p.y);
}
}
cout << chrono::duration_cast<chrono::duration<double>>
(chrono::high_resolution_clock::now() - start).count() << "\n";
glEnd();
glfwSwapBuffers(window);
this_thread::sleep_for(chrono::milliseconds(100));
}

return 0;
}
chaos_game
Menger Sponge:-
#include <iostream>
#include <random>
#include <thread>
#include <GL/gl.h>

#define WIDTH 768


#define HEIGHT 768
using namespace std;

int three_pow(int exp){


int num = 1;
for(int i = 0; i < exp; i++){
num *= 3;
}
return num;
}
int main(int argc, char * argv[]){
int max_depth = 5;
glInit();
GLwindow * window = glfwCreateWindow(WIDTH, HEIGHT, "Menger Sponge!", NULL, NULL);
if(!window){

return -1;
}

glfwMakeContextCurrent(window);
glOrtho(0, WIDTH, 0, HEIGHT, -1.0, 1.0);

while(true){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.72f,0.72f, 0.0f);
glBegin(GL_QUADS);
chrono::high_resolution_clock::time_point start = chrono::high_resolution_clock::now();
for(int d = 0; d < max_depth; d++){
double depth = (double) three_pow(d);
for(int i = 0; i < depth; i++){
double x_step = WIDTH / depth;
for(int j = 0; j < depth; j++){
double y_step = HEIGHT / depth;
double center_x = x_step*double(i) + x_step/2.0;
double center_y = y_step*double(j) + y_step/2.0;
glVertex2i(center_x + x_step/6.0, center_y + y_step/6.0);
glVertex2i(center_x + x_step/6.0, center_y - y_step/6.0);
glVertex2i(center_x - x_step/6.0, center_y - y_step/6.0);
glVertex2i(center_x - x_step/6.0, center_y + y_step/6.0);
}
}
}
cout << chrono::duration_cast<chrono::duration<double>>
(chrono::high_resolution_clock::now() - start).count() << "\n";
glEnd();
glfwSwapBuffers(window);
this_thread::sleep_for(chrono::milliseconds(100));
}

return 0;
}
Menger Sponge
Fractal Tree:-
#include <GL/glut.h>

#include<stdio.h>

#include<math.h>

#include<stdlib.h>

#include<iostream>

using namespace std;

void drawTree(int current_Depth, int maxDepth)

if (current Depth > maxDepth)

return;

if (current_Depth <= maxDepth - 2)

glColor3d(0.72, 0.72, 0.0);

glLineWidth(10 * static_cast<GLfloat>(pow(TREE_FACTOR, current_Depth)));

else

glColor3d(0.72, 0.72, 0.0);

glLineWidth(30 * static_cast<GLfloat>(pow(TREE_FACTOR, current_Depth)));

}
double lineLen = TREE_LINE_BASE_LEN * pow(TREE_FACTOR, current_Depth);

glBegin(GL_LINES);

glVertex2d(0, 0);

glVertex2d(0, lineLen);

glEnd();

int angle_1 = 10 + rand() % 40;

int angle2 = 10 + rand() % 40;

glTranslated(0, lineLen, 0);

glRotated(-angle1, 0, 0, 1);

drawTree(current_Depth + 1, maxDepth);

glRotated(angle_1 + angle_2, 0, 0, 1);

drawTree(current_Depth + 1, maxDepth);

glRotated(-angle2, 0, 0, 1);

glTranslated(0, -lineLen, 0);

int main(int argc, char** argv) {

glutInit(&argc, argv);

glutCreateWindow("fractal Tree");

glutInitWindowSize(1080, 720);

glutInitWindowPosition(150, 150);

glutDisplayFunc(drawTree);

glutMainLoop();

return 0;

}
Fractal Tree

You might also like