Skip to content

Instantly share code, notes, and snippets.

@anvaka
Created January 30, 2018 05:34
Show Gist options
  • Save anvaka/0f11251039eb366630bc7ca08ce0eefd to your computer and use it in GitHub Desktop.
Save anvaka/0f11251039eb366630bc7ca08ce0eefd to your computer and use it in GitHub Desktop.
// This shader creates a clock from three fractals:
// Two hands are rendered with `seconds` and `minutes` functions,
// While the border is rendered as a `border()`.
// The max of three colors gives the final picture
vec4 border(vec2 p) {
vec2 z = vec2(0.); float t = 0.;
vec2 c = c_mul(p, p); c = c_mul(c, c); c = c_mul(c,c);
for(int i = 0; i < 32; ++i) { if (length(z) > 2.) break;
vec2 z0 = z;
z = c_mul(z, z); z = c_mul(z,z);z = c_mul(z,z);z = c_mul(z,z0); z += c;
t = float(i);
}
return length(z)*vec4(t/64., t/32., t/24., 1.0);
}
vec4 seconds(vec2 p) {
float t = 0.; vec2 z = vec2(0.);
p = vec2(p.y, -p.x) * 450.;
float a = 2. * 3.14 * bease(mod(iFrame, 60.)/60.);
vec2 c = vec2(p.x * cos(a) - p.y*sin(a), p.y*cos(a) + p.x * sin(a));
for(int i = 0; i < 23; ++i) {
if (length(z) > 2.) break;
z = c_mul(z, c_exp(z)) + c_inv(c);
t = float(i);
}
return length(c_tan(z)) * vec4(t * vec3(1./64., 1./32., 1./16.), 1.0);
}
vec4 minutes(vec2 p) {
float t = 0.; vec2 z = vec2(0.); p = vec2(p.y,-p.x)*450.;
float a = 2.* 3.14 * mod(iFrame, 3600.)/3600.;
vec2 c = vec2(p.x * cos(a) - p.y*sin(a), p.y*cos(a) + p.x * sin(a));
for(int i = 0; i < 32; ++i) {
if (length(z) > 2.) break;
z = c_mul(z, c_exp(z)) + c_inv(c);
t = float(i);
}
return length(c_tan(z)) * vec4(t * vec3(1./23., 1./42., 1./50.), 1.0);
}
vec4 get_color(vec2 p) {
return max(
max(seconds(p), border(p)),
minutes(p));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment