{"code": "/*************************\n * domains of attraction *\n *   by pdkl95           *\n *************************/\n\n#ifdef GL_ES\nprecision mediump float;\n#endif\n\n#extension GL_OES_standard_derivatives : enable\n\nuniform float time;\nuniform vec2 mouse;\nuniform vec2 resolution;\n\n#define TAU 6.283185307179586\n#define SQ3 1.73205080756887729352744\n\n#define cx_i vec2(0.0, 1.0)\n#define cx_neg1 vec2(-1.0, 0.0)\n\n#define cx_mul(a, b) vec2((a).x*(b).x - (a).y*(b).y, (a).x*(b).y + (a).y*(b).x)\n#define cx_div(a, b) vec2(((a.x*b.x+a.y*b.y)/(b.x*b.x+b.y*b.y)),((a.y*b.x-a.x*b.y)/(b.x*b.x+b.y*b.y)))\n#define cx_conj(a) vec2(a.x,-a.y)\n\nvec2 cx_pow(vec2 z, float n) {\n\tfloat r2 = dot(z,z);\n\treturn pow(r2,n/2.0)*vec2(cos(n*atan(z.y,z.x)),sin(n*atan(z.y,z.x)));\n}\n\n/***\n *** the attractor polynomial\n ***/\nvec2 poly(vec2 z) {\n\treturn cx_pow(z, 5.0) + cx_neg1 + cx_mul(z, cx_neg1);\n}\n\nconst vec2 five = vec2(5.0, 0.0);\n\n/***\n *** the derivitave of the attractor polynomial\n *** !!! must match poly() !!!\n *** !!!   d(poly())/dz    !!!\n ***/\nvec2 dpoly(vec2 z) {\n\tvec2 dz = cx_pow(z, 4.0);\n\treturn cx_mul(five, dz) + cx_neg1;\n}\nvoid main( void ) {\n\tvec2 position = ((gl_FragCoord.xy / resolution.xy ) * 2.0) - 1.0;\n\tposition.y *= resolution.y / resolution.x;\n\tposition *= 1.8;\n\n\tvec3 color = vec3(0.0);\n\n\tvec2 z = position;\n\tvec2 w = poly(z);\n\t\n\t\n\tvec2  dp = vec2(0.0);\n\tvec2 wdp = vec2(0.0);\n\n\tfloat s = 1.0;\n\tfloat f = 1.0;\n\t\n\tfor (int i=0; i < 20; i++) {\n\t\tw = poly(z);\n\t\tif (                     f <= 0.01) { break; }\n\t\tif (cx_mul(w, cx_conj(w)).x > 0.01) { break; }\n\t      \n\t\tf *= 0.95;\n\t\ts = -s;\n\t\n\t\tdp = dpoly(z);\n\t\tz -= cx_div(w, dp);\n\t}\n\t\n\tfor (int n=0; n < 10; n++) {\n\t\tz = z - cx_div(poly(z), dpoly(z));\n\t}\n\t\n\tz = f * cx_div(cx_mul(z, z), cx_mul(z, cx_conj(z)));\n\t\n\tcolor.r = ( 0.24 * z.x) - ((SQ3 * 0.24) * z.y);\n\tcolor.g = ( 0.24 * z.x) + ((SQ3 * 0.24) * z.y);\n\tcolor.b = (-0.48 * z.x);\n\n\tcolor = 0.5 * f + color;\n\n\tgl_FragColor = vec4(color, 1.0);\n}", "user": "66092fd", "parent": null, "id": 47197}