The term fractal was first used by mathematician Benoit Mandelbrot in 1974.
He based it on the Latin word fractus which means "broken" or "fractured".
A fractal is an abstract mathematical object, like a curve or a surface, which pattern remains the same at every scale.
Various natural phenomena – like the romanesco cabbage – have some fractal features.
⏯️ FRACTALES Videos presentation
⏯️ How to make Julia FRACTALES
⏯️ How to make Mandelbrot FRACTALES
- Use the school graphical library: the
MiniLibX
- Includes basic necessary tools to open a window, create images and deal with keyboard and mouse events
- Use the mathematical notion of complex numbers, to take a peek at the concept of optimization in computer graphics and practice event handling
🔢 Live Preview + Explanation | 🧮 Math in details
➿ Explanation with great creation a fractal step by step ⬆️ ⬆️
Mandelbrot set is generated by iterating a simple function on the points of the complex plane. The points that produce a cycle (the same value over and over again) fall in the set, whereas the points that diverge (give ever-growing values) lie outside it.
The initial value of
The set iterate from
$\ c $ is a complexe number :
For code purpose:
To adjust: c = scale + offset
If magnitude
int ft_mandelbrot_set(double x, double y, int max_iterations)
{
double scaled_x;
double scaled_y;
double real;
double imaginary;
double a;
double b;
int count;
scaled_x = (x - WIDTH / 2) * 4 / WIDTH;
scaled_y = (y - HEIGHT / 2) * 4 / HEIGHT;
a = 0;
b = 0;
count = 0;
while (count < max_iterations)
{
real = (a * a) - (b * b);
imaginary = 2 * a * b;
a = real + scaled_x;
b = imaginary + scaled_y;
if (b + a > 4)
return (count);
count++;
}
return (count);
}
To center content/ offset with
- x and y are the pixel coordinates in the display. WIDTH and HEIGHT are the dimensions of your display area. The
(x - WIDTH / 2.0)
and(y - HEIGHT / 2.0)
parts shift the coordinate system so that the center of your display corresponds to (0, 0) in the complex plane. - The multiplication by
4.0 / WIDTH
and4.0 / HEIGHT
scales the coordinates so that you are looking at a region that spans -2 to 2 (both in real and imaginary parts) in the complex plane. This scaling factor of 4.0 is somewhat arbitrary and can be adjusted based on your preferences to zoom in or out of the Mandelbrot set.
Mandelbrot - Complexe Analysis
Mandelbrot -> contains julia sets
The key difference between the Mandelbrot set and the Julia set is that the Mandelbrot set uses the coordinates of the point in the complex plane to determine if the point is in the set, while the Julia set uses a constant value for all the points in the set.
Julia Set$\ Z_{n + 1} = Z_n + c$
After numerous iterations, if the magnitude of
static int ft_julia_set(double x, double y, int max_iterations)
{
double real;
double imaginary;
double a;
double b;
int count;
a = (x - WIDTH / 2) * 4 / WIDTH;
b = (y - HEIGHT / 2) * 4 / HEIGHT;
count = 0;
while (count < max_iterations)
{
real = (a * a) - (b * b);
imaginary = 2 * a * b;
a = real + c_real;
b = imaginary + c_imaginary;
if (b + a > 2)
return (count);
count++;
}
return (count);
}
The difference between this calculation and that for the Mandelbrot set is that the real and imaginary components are set to their respective absolute values before squaring at each iteration.
Code for burning ship
static int ft_burningship_set(
double x,
double y,
t_fractol *fractol,
int count)
{
double scaled_x;
double real;
double imaginary;
double a;
double b;
scaled_x = fractol->fra.x + (x - WIDTH / 2) * fractol->fra.zoom / WIDTH;
fractol->fra.param_storage = fractol->fra.y
+ (y - HEIGHT / 2) * fractol->fra.zoom / HEIGHT;
a = 0;
b = 0;
count = 0;
while (count < fractol->fra.max_iterations)
{
real = (a * a) - (b * b);
imaginary = 2 * a * b;
a = fabs(real + scaled_x);
b = fabs(imaginary + fractol->fra.param_storage);
if (b + a > 4)
return (count);
count++;
}
return (count);
}
/**
* * Draw mandelbrot fractal
* @param: fractol
*/
void ft_burningship(t_fractol *fractol)
{
double x;
double y;
int iter;
iter = 0;
x = 0;
while (x < WIDTH)
{
y = 0;
while (y < HEIGHT)
{
iter = ft_burningship_set(x, y, fractol, iter);
if (iter == fractol->fra.max_iterations)
fractol->fra.fractal_data[(int)(x + y * WIDTH)]
= fractol->col.color_array[fractol->col.color_number - 1];
else
fractol->fra.fractal_data[(int)(x + y * WIDTH)]
= fractol->col.color_array[ft_colormode(iter, fractol)];
y++;
}
x++;
}
}
🔗 Details
A complex number is a number that can be written in the form
The set of complex numbers, denoted by
Based on the nature of the real part and imaginary part, any complex number can be classified into four types:
- imaginary number
- zero complex number
- purely imaginary number
- purely real number.
For
- If
$\ a = 0$ and$\ b \neq 0$ , then$\ Z$ is an imaginary number. - If
$\ a = 0$ and$\ b = 0$ , then$\ Z$ is a zero complex number. - If
$\ a \neq 0$ and$\ b = 0$ , then$\ Z$ is a purely real number. - If
$\ a \neq 0$ and$\ b \neq 0$ , then$\ Z$ is a complex number.
Every real number is a complex number, but every complex number is not necessarily a real number.
The set of all complex numbers is denoted by
The magnitude of a number (also called its absolute value) is its distance from zero, so
- the magnitude of 6 is 6
- the magnitude of −6 is also 6
The magnitude of a vector is its length (ignoring direction).
For a complex number
The simplest algorithm for generating a representation of the Mandelbrot set is known as the "escape time" algorithm. A repeating calculation is performed for each x, y point in the plot area and based on the behavior of that calculation, a color is chosen for that pixel.
Color based on escape of iterations loop within bound
The escape time algorithm is popular for its simplicity. However, it creates bands of color, which, as a type of aliasing, can detract from an image's aesthetic value. This can be improved using an algorithm known as "normalized iteration count", which provides a smooth transition of colors between iterations. The algorithm associates a real number ν \nu with each value of z by using the connection of the iteration number with the potential function.
...