sigrist-svelte-mandelbrot-explorer
Version:
A svelte component that renders the mandelbrot set using WebGL. Try this [Demo](https://sigrist.dev/apps/mandelbrot).
3 lines (2 loc) • 1.66 kB
TypeScript
declare const _default: "precision highp float;\n\nuniform mat3 translation_matrix;\nuniform float angleOffset;\nuniform float maximumIterations;\n\nvarying vec2 fragCoord;\n\nvoid main(){\n\n vec3 coordinate = translation_matrix * vec3(fragCoord, 1.0);\n\n float x0 = coordinate.x;\n float y0 = coordinate.y;\n float x = 0.0;\n float y = 0.0;\n \n float numIterations = 0.0;\n for(float iter = 0.0; iter < 1000.0; iter++){\n \n if(x*x + y*y > 4.0){\n break;\n }\n if(numIterations >= maximumIterations){\n break;\n }\n float xtemp = x*x -y*y + x0;\n y = 2.0 * x * y + y0;\n x = xtemp;\n numIterations++;\n }\n \n vec3 color;\n if(numIterations < maximumIterations){\n float log_zn = log(x*x + y*y) / 2.0;\n float nu = log(log_zn / log(2.0))/log(2.0);\n\n numIterations = numIterations + 1.0 - nu;\n\n float color1Ratio = numIterations / maximumIterations * 50.0 + angleOffset;\n vec3 color1 = vec3( sin(color1Ratio) *0.5 + 0.5, sin(color1Ratio + 2.09437866667 ) *0.5 + 0.5, sin(color1Ratio- 2.09437866667) *0.5 + 0.5);\n\n float color2Ratio = (numIterations * 1.0)/ maximumIterations * 50.0 + angleOffset;\n vec3 color2 = vec3(sin(color2Ratio) *0.5 + 0.5, sin(color2Ratio + 2.09437866667 ) *0.5 + 0.5, sin(color2Ratio- 2.09437866667) *0.5 + 0.5);\n\n float ratio = fract(numIterations);\n color = ratio * color1 + (1.0-ratio) * color2; \n\n \n\n }else{\n color = vec3(0.0,0.0,0.0);\n }\n gl_FragColor = vec4(color, 1.0);\n}";
export default _default;