function createDrawQuasicrystal(regl) {
return regl({
vert: `
precision highp float;
attribute vec2 aBigTri;
uniform mat3 inverseView3;
varying vec2 xy;
void main () {
// Use an inverse view matrix computed from the x-scale and y-scale
// to pass an x-y pair to the fragment shader
xy = (inverseView3 * vec3(aBigTri, 1)).xy;
gl_Position = vec4(aBigTri, 0, 1);
}`,
frag: `
precision highp float;
uniform float t;
varying vec2 xy;
const float PI = 3.14159265358979323846264;
vec4 color(float t) {
const float ar = 0.50, ag = 0.50, ab = 0.50;
const float br = 0.50, bg = 0.50, bb = 0.50;
const float cr = 1.00, cg = 1.00, cb = 1.00;
const float dr = 0.00, dg = 0.10, db = 0.20;
return vec4(
ar + br * cos(2.0 * PI * (cr * t + dr)),
ag + bg * cos(2.0 * PI * (cg * t + dg)),
ab + bb * cos(2.0 * PI * (cb * t + db)),
1.0
);
}
void main(void) {
const int n = ${N};
const float step = PI / float(n);
float alpha;
for (int i = 0; i < n; i++) {
float theta = float(i) * step;
alpha += cos(cos(theta) * xy.x + sin(theta) * xy.y + t);
}
gl_FragColor = color(alpha * 2.0 / float(n));
}`,
attributes: {
aBigTri: [-4, -4, 4, -4, 0, 4]
},
uniforms: {
t: regl.context('time')
},
count: 3,
depth: { enable: false }
});
}