Created
March 25, 2021 15:18
-
-
Save creaktive/131472f92ed80c71593c737e423cf649 to your computer and use it in GitHub Desktop.
Mandelbrot set plot, implemented as GLSL fragment shader
This file contains 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
// shamelessly stolen from https://p5js.org/reference/#/p5/loadShader | |
// ported to work with https://thebookofshaders.com/edit.php | |
precision highp float; | |
const int I = 500; | |
void main() { | |
vec2 vPos = gl_FragCoord.xy; | |
vec2 p = vec2(-0.74364388703, 0.13182590421); | |
float r = .00001; | |
vec2 c = p + vPos * r, z = c; | |
float n = 0.0; | |
for (int i = I; i > 0; i --) { | |
if(z.x*z.x+z.y*z.y > 4.0) { | |
n = float(i)/float(I); | |
break; | |
} | |
z = vec2(z.x*z.x-z.y*z.y, 2.0*z.x*z.y) + c; | |
} | |
gl_FragColor = vec4(0.5-cos(n*17.0)/2.0,0.5-cos(n*13.0)/2.0,0.5-cos(n*23.0)/2.0,1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment