42's project, zoom on fractal
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Fabien Stadelwieser 6413bf107f
Readme done
10 months ago
asset Readme done 10 months ago
inc sierpinsky and mandelrot fractal added 2 years ago
lib/libft sierpinsky and mandelrot fractal added 2 years ago
src subject compliant color pallete 2 years ago
.gitignore init 2 years ago
Makefile sierpinsky and mandelrot fractal added 2 years ago
README.md Readme done 10 months ago
author init 2 years ago



Display infinitely zoomable fractal.

Implemented :

./fractol [mandelbrot julia burning-ship sierpinski mandelrot]



Zoomed in

Zoomed out


Julia with another parameter (can be modified using the mouse)

Julia zoomed in


Burning-ship zoomed in


One of the requirement of this project was to use 42l's minilibX which only run easily on the school's mac.

Could be done on Linux but you're on your own.

So make sure you have :

  • MacOS
  • 42's MinilibX

Then :

git clone ssh://git@git.42l.fr:42084/Fabien/fractol.git
cd fractol

How it's done

For each fractal the goal is to get a number of iteration in a given point of a graph.

So for this you loop over each pixel of the screen, and for each pixel you

call your drawing function, draw_mandelbrot in this case. For Mandelbrot, Julia and Burning-ship:

  • The first thing you do is convert the (t_vec2) coordinate of the pixel into an imaginary number (t_reel) (x is the real part r, y is the imaginary i)
  • Adjust for the zoom and the offset
  • Iterate until the "normal" of the imaginary number is not above 2. By Pythagoras' theorem -> (nb.r * nb.r + nb.i * nb.i < 4)
  • For each iteration apply a different operation depending on the fractal
  • Colorize the pixel depending on the number of iteration result
#include "fractol.h"

uint32_t	draw_mandelbrot(t_fractol *fractol, t_vec2 pos)
	t_reel		base_point;
	t_reel		z;
	uint32_t	iter;
	double		tmp;

	base_point = (t_reel){
		.r = pos.x
			/ (fractol->mlx.win_size.x / fractol->fract->size.x)
			+ fractol->fract->pos.x,
		.i = pos.y
			/ (fractol->mlx.win_size.y / fractol->fract->size.y)
			+ fractol->fract->pos.y
	z = base_point;
	iter = 0;
	while (z.r * z.r + z.i * z.i < 4 && iter < fractol->fract->iter_num)
		tmp = z.r;
		z.r = z.r * z.r - z.i * z.i + base_point.r;
		z.i = 2 * z.i * tmp + base_point.i;
	return (iter);


Student project for School 42.

Realized in about a weekend by myself.

Final Grade: 116/125