diff options
| author | Akshay Nair <phenax5@gmail.com> | 2023-12-03 22:57:03 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2023-12-03 22:57:03 +0530 |
| commit | 61b7b7484e141319479df532c185961eef8edf0c (patch) | |
| tree | 41e2eade003e87a8f2dd9efd83210f826234bc92 /sketches | |
| parent | 70f96933be628f956b63dda79effcc83b4d60ed1 (diff) | |
| download | creative-coding-playground-61b7b7484e141319479df532c185961eef8edf0c.tar.gz creative-coding-playground-61b7b7484e141319479df532c185961eef8edf0c.zip | |
improved newton's fractal coloring
Diffstat (limited to 'sketches')
| -rw-r--r-- | sketches/02/newton.frag | 30 | ||||
| -rw-r--r-- | sketches/02/screenshots/1.jpg | bin | 66810 -> 242241 bytes | |||
| -rw-r--r-- | sketches/02/screenshots/2.jpg | bin | 147734 -> 230782 bytes |
3 files changed, 12 insertions, 18 deletions
diff --git a/sketches/02/newton.frag b/sketches/02/newton.frag index ac31d73..b905d1b 100644 --- a/sketches/02/newton.frag +++ b/sketches/02/newton.frag @@ -21,38 +21,32 @@ vec2 cpow(vec2 z, float n) { return pow(r, n) * vec2(cos(n * theta), sin(n * theta)); } +float fabs(float a) { return a > 0. ? a : -a; } + void main() { - float time = mod(1.1 + mod(u_time * 1000.0, 100000.0) / 10000.0, 10.); - // float time = 2.0; + float time = mod(0.5 + mod(u_time * 1000.0, 100000.0) / 10000.0, 2.); float ratio = u_resolution.x / u_resolution.y; vec2 pos = v_position.xy/vec2(1.0, ratio); + vec2 prevZ; vec2 z = 2.0 * (pos - vec2(0., 0.)); - int i; - vec2 prevZ = z; - for (i = 0; i < MAX_ITERATIONS; i++) { + int iterations = 0; + for (int i = 0; i < MAX_ITERATIONS; i++) { prevZ = z; vec2 value = cpow(z, 3.0) + vec2(1., 0.); vec2 value_der = 3.0 * cpow(z, 2.0); z = z - time * cdiv(value, value_der); - if (length(z - prevZ) > 30.0) { - break; - } + iterations++; + if (fabs(z.x - prevZ.x) < 0.001) break; } - gl_FragColor = vec4(0., 0., 0., 1.); - - float diff = length(z - prevZ); + float val = float(iterations) * 10.0 / float(MAX_ITERATIONS); + float g = val * 0.5; + float b = val * 0.8; - if (diff > 10.0) { - gl_FragColor = vec4(97., 42., 191., 255.0) / 255.; - } else if (diff > 1.0) { - gl_FragColor = vec4(150., 191., 69., 255.0) / 255.; - } else if (diff > 0.0) { - gl_FragColor = vec4(27., 14., 50., 255.0) / 255.; - } + gl_FragColor = vec4(0.0, g, b, val); } diff --git a/sketches/02/screenshots/1.jpg b/sketches/02/screenshots/1.jpg Binary files differindex 67a2266..1fb1721 100644 --- a/sketches/02/screenshots/1.jpg +++ b/sketches/02/screenshots/1.jpg diff --git a/sketches/02/screenshots/2.jpg b/sketches/02/screenshots/2.jpg Binary files differindex da745cb..fd4d4be 100644 --- a/sketches/02/screenshots/2.jpg +++ b/sketches/02/screenshots/2.jpg |
