Implementation of Mandelbrot Fractal using Box Engine with Lua and GLSL
Box engine is developed by me to create 2D and 3d applications
Fractal below have the credits to https://www.shadertoy.com/view/tllSWj
- Space/Z to zoom in/out
- Q to change between fractals variants
- Move with arrows
The Mandelbrot set is a collection of points in the complex plane. Each point (c) is a complex number represented as (c = x + yi) (where (x) and (y) are real numbers, and (i) is the imaginary unit).
To check if a point (c) is in the Mandelbrot set, we repeatedly apply a formula and see if the result gets very large (tends to infinity). If it does, the point is not in the set. If it doesn't, the point is in the set.
Here's the basic GLSL code that does this:
for (int i = 0; i < max_iterations; i++)
{
if (length(z) > 8.0) {
break;
}
z = vec2(z.x * z.x - z.y * z.y, 2.0 * z.x * z.y) + c; // iteration formula
iterations++;
}
if (iterations == max_iterations)
{
fragColor = vec4(0, 0 , 0, 1.0); // outside
}
else
{
fragColor = (float(iterations)/float(max_iterations)); // inside
}
- Box Engine is available in Engine Folders with a release and the source code is in my repository (note that versions might differ)
- To run use
start.bat
or usestart_editor.bat
to use the engine editor and change settings better - The complete source code of the fractal is in Assets folder