fragShader = `
precision highp float;
uniform vec2 u_resolution, u_translate;
uniform float u_scale;
uniform int u_d;
const int maxIters = ${maxIters};
vec3 colorScale( float t )
{
vec3 a,b,c,d;
a = vec3(0.5);
b = vec3(0.5);
c = vec3(1.);
d = vec3(0.,0.1,0.2);
return a + b*cos( 6.28318*(c*t+d) );
}
float mandelbrot(float x, float y) {
vec2 z, c;
float d = float(u_d);
c.x = x;
c.y = y;
z = c;
int iterCount = 0;
for(int i=0; i<maxIters; i++) {
float r = sqrt(z.x*z.x + z.y*z.y);
float theta = atan(z.y, z.x);
float rNew = pow(r,d);
float thetaNew = d*theta;
float x = rNew*cos(thetaNew) + c.x;
float y = rNew*sin(thetaNew) + c.y;
if((x * x + y * y) > 4.0) break;
z.x = x;
z.y = y;
iterCount += 1;
}
return float(iterCount)/float(maxIters);
}
void main() {
float xpt = (gl_FragCoord.x - u_translate.x) / u_resolution.x / u_scale;
float ypt = (u_resolution.y - gl_FragCoord.y - u_translate.y) / u_resolution.y / u_scale;
float t = mandelbrot( xpt, ypt);
gl_FragColor = vec4(colorScale(fract(sqrt(t)+0.5)),1);
}
`