Last active
May 3, 2022 00:16
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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