makeRegl(`
const float pixelSize = 1.0;
const float PI = 3.141592653589793;
vec3 self = tf(0.,0.);
vec2 FC = gl_FragCoord.xy * pixelSize;
float random = fsnoise(FC) * .5 + .5;
float grid = max(
step(0.9, sin(FC.x * PI/4.)),
step(0.9, sin(FC.y * PI/4.))
);
if(t == 0.) {
gl_FragColor = vec4(
step(-1., -length(FC - .5)),
random * grid,
0.0,
1.0
);
return;
}
gl_FragColor = vec4(self, 1.0);
float diff = 0.;
float coeffSum = 0.;
const float rad2 = 5.0;
for(float y=-rad2; y<=rad2; y++) {
for(float x=-rad2; x<=rad2; x++) {
float coeff = exp(-length(vec2(x, y)) * 0.1);
diff += tf(x, y).r == 1. ? coeff : 0.;
coeffSum += coeff;
}
}
diff = diff / coeffSum;
float green = random * grid - clamp(diff, 0.0, 1.0) * 40.0;
gl_FragColor.g = clamp(self.g * 0.99 + green * 0.01, 0.0, 1.0);
vec2 theMostGreenCell;
float theGreenestGreen = 0.0;
const float rad = 4.;
for(float y=-rad; y<=rad; y++) {
for(float x=-rad; x<=rad; x++){
float green = tf(x,y).g;
if(green <= theGreenestGreen) continue;
if(tf(x,y+1.).r < 1. && tf(x+1.,y).r < 1. && tf(x,y-1.).r < 1. && tf(x-1.,y).r< 1.) continue;
if(tf(x,y).r == 1.) continue;
theGreenestGreen = green;
theMostGreenCell = vec2(x,y);
}
}
if(theGreenestGreen == 0.) return;
if(length(theMostGreenCell) == 0.) gl_FragColor.r = 1.;
`, `
vec3 tf(float x, float y) {
return texture2D(texture, mod(gl_FragCoord.xy + vec2(x, y), iResolution) / iResolution).rgb;
}
float fsnoise(vec2 c){
return fract(sin(dot(c, vec2(12.9898, 78.233))) * 43758.5453);
}
`, 100, 500)