Skip to content

Instantly share code, notes, and snippets.

@Zi7ar21
Last active May 3, 2022 00:16
Show Gist options
  • Save Zi7ar21/af5fc0606e0113211fc116becb569d87 to your computer and use it in GitHub Desktop.
Save Zi7ar21/af5fc0606e0113211fc116becb569d87 to your computer and use it in GitHub Desktop.
A simple glsl function that checks if a point is part of the mandelbrot set.
// Mandelbrot Set
bool mandelbrot(vec2 c, int iter)
{
// Initialize Z
vec2 z = vec2(0.0);
// Iterate function (z = z ^ 2 + c)
for(int i = 0; i < iter; i++)
{
// Check if our point diverged
if(length(z) > 4.0){return false;}
// Compute the next point in the orbit
z = vec2((z.x*z.x)-(z.y*z.y), z.x*z.y*2.0) + c;
}
// The point never diverged, it's part of the Mandelbrot Set
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment