diff options
| author | Akshay Nair <phenax5@gmail.com> | 2023-11-11 14:53:08 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2023-11-11 14:53:08 +0530 |
| commit | ada4af0a94ba5723ec8366d9f75ef86f8650a512 (patch) | |
| tree | 7cfb9f3745555684ade0d73a69ac0571e144536c /sketches | |
| parent | 73137f0315aa9080389f96170e7e7248e6c55c7d (diff) | |
| download | creative-coding-playground-ada4af0a94ba5723ec8366d9f75ef86f8650a512.tar.gz creative-coding-playground-ada4af0a94ba5723ec8366d9f75ef86f8650a512.zip | |
feat: optimizes and changes polka a bit
Diffstat (limited to 'sketches')
| -rw-r--r-- | sketches/04/polka.frag | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/sketches/04/polka.frag b/sketches/04/polka.frag index 1a93292..97baa9c 100644 --- a/sketches/04/polka.frag +++ b/sketches/04/polka.frag @@ -2,35 +2,30 @@ varying vec4 v_position; uniform vec2 u_resolution; uniform float u_time; -#define MAX_ITERATIONS 100 #define DOTS 32. +const float segment = 2.0 / (DOTS + 1.); + void main() { float time = u_time * 2.; float ratio = u_resolution.x / u_resolution.y; - vec2 pos = v_position.xy/vec2(1.0, ratio); - - gl_FragColor = vec4(0., 0., 0., 1.); + vec2 pos = (v_position.xy - 1.0)/vec2(1.0, ratio); - float segment = 2.0 / (DOTS + 1.); + vec2 cell_pos = abs(floor(pos / segment)) - 0.5; + int alt = int(mod(cell_pos.x + cell_pos.y, 2.)); - for (float i = 0.; i < DOTS; i++) { - for (float j = 0.; j < DOTS; j++) { - int alt = int(mod(i + j, 2.)); - vec2 step = vec2(segment * (i + 1.0), segment * (j + 1.0)); - float radius = (sin(time - length(pos)) + 1.)*0.02; - if (alt == 0) { - radius = (0.04 - radius); - } + float radius = (sin(time - length(pos + 0.5)) + 1.)*0.02; + if (alt == 0) { + radius = (0.04 - radius); + } - if (length(pos - 1. + step) < radius) { - if (alt == 0) { - gl_FragColor = vec4(.17, .24, .31, 1.); - } else { - gl_FragColor = vec4(0.75, 0.22, 0.17, 1.); - } - } + gl_FragColor = vec4(0., 0., 0., 1.); + if (length(pos - 0.0 + cell_pos*segment) < radius) { + if (alt == 0) { + gl_FragColor = vec4(.17, .24, .31, 1.); + } else { + gl_FragColor = vec4(0.75, 0.22, 0.17, 1.); } } } |
