Daily Creative Coding

元「30 min. Processing」。毎日、Creative Codingします。

【GLSL】円形のチェッカーパターン

See the Pen circular checker pattern by aadebdeb (@aadebdeb) on CodePen.

#define PI 3.14159265359

precision mediump float;

uniform float u_time;
uniform vec2 u_mouse;
uniform vec2 u_resolution;

vec2 transform(vec2 st) {
  float size = length(st);
  float theta = atan(st.y, st.x);
  float xScale = u_mouse.x / u_resolution.x * 3000.0;
  float yBase = u_mouse.y / u_resolution.y * 1000000.0;
  return vec2(theta * xScale, yBase / size);
}

void main(void) {

  vec2 st = gl_FragCoord.xy - u_resolution / 2.0;
  float size = 20.0;

  st = transform(st);

  float c = abs(floor(mod(st.x / size, 2.0)) - floor(mod(st.y / size, 2.0)));

  gl_FragColor = vec4(vec3(c), 1.0);
}
f:id:aa_debdeb:20170407084154p:plain