読者です 読者をやめる 読者になる 読者になる

Daily Creative Coding

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

【GLSL】セルの分割

See the Pen cellular division by aadebdeb (@aadebdeb) on CodePen.

#define PI 3.14159265359
#define TWO_PI PI * 2.0

precision mediump float;

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

float random (float v) {
    return fract(sin(v + 0.3423) * 100000.0);
}

void main(void) {
  vec2 st = gl_FragCoord.xy / u_resolution;

  float min1 = 100.0;
  float min2 = 200.0;
  for (int i = 0; i < 40; i++) {
    vec2 p = vec2(random(float(i)), random(float(i) + 1000.0));
    float r = random(float(i) + 2000.0) * 0.05 + 0.05;
    float a = u_time * 0.0002 + random(float(i) + 3000.0) * TWO_PI;
    p += vec2(r * cos(a), r * sin(a));
    float d = distance(p, st);
    if (min1 > d) {
      min2 = min1;
      min1 = d;
    } else if (min2 > d) {
      min2 = d;
    }
  }


  float c = smoothstep(0.0, 0.004, min2 - min1);

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