Daily Creative Coding

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

【GLSL】回転するチェッカーパターン

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

#define PI 3.14

precision mediump float;

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

void main(void) {

  vec2 pos = gl_FragCoord.xy - u_resolution / 2.0;
  float size = 30.0;
  vec2 st = pos / (size * 2.0);
  float angle = u_mouse.x / u_resolution.x;
  angle -= length(pos) * abs(u_mouse.y - u_resolution.y / 2.0) * 0.00001;
  mat2 rot = mat2(cos(angle), -sin(angle),
                  sin(angle), cos(angle));
  st = rot * st;
  float c = abs(step(0.5, fract(st.x)) - step(0.5, fract(st.y)));

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