function createPlot () {
let w = width;
let h = width / 1.6;
let pixelRatio = 2;
let canvas = DOM.canvas(w * pixelRatio, h * pixelRatio);
canvas.style.width = w + 'px';
canvas.style.height = h + 'px';
let regl = wrapREGL({
canvas: canvas,
pixelRatio: pixelRatio,
extensions: ['oes_standard_derivatives']
});
canvas.value = {
regl: regl,
createDrawFunction: function createPlotter (f) {
var drawField = regl({
vert: `
precision mediump float;
uniform vec2 aspectRatio;
attribute vec2 xy;
varying vec2 z;
void main () {
z = xy * aspectRatio;
gl_Position = vec4(xy, 0, 1);
}
`,
frag: `
${glsl.useStandardDerivatives}
${glsl.constants}
${glsl.precision}
${glsl.hypot}
${glsl.complex}
${glsl.wireframe}
${glsl.hsv2rgb}
${glsl.cubeHelix}
${glsl.domainColoring}
uniform float rootDarkening, poleLightening;
uniform float rootDarkeningSharpness, poleLighteningSharpness;
uniform float rectangularGridOpacity, polarGridOpacity;
varying vec2 z;
uniform float pixelRatio;
${f}
void main () {
gl_FragColor = vec4(domainColoring(
f(2.0 * z), // The evaluated function!
vec2(0.125, 1.0), // Polar grid spacing
polarGridOpacity, // Polar grid strength
vec2(1.0), // Rectangular grid spacing
rectangularGridOpacity, // Rectangular grid strength
poleLightening, // Pole lightening strength
poleLighteningSharpness, // Pole ligthening sharpness
rootDarkening, // Root darkening strength
rootDarkeningSharpness, // Root darkening sharpness
0.5 * pixelRatio // Line thickness
), 1.0);
}
`,
attributes: {
xy: [-4, -4, 4, -4, 0, 4],
},
uniforms: {
pixelRatio: regl.context('pixelRatio'),
aspectRatio: ctx => [ctx.framebufferWidth / ctx.framebufferHeight, 1],
rootDarkening: regl.prop('rootDarkening'),
poleLightening: regl.prop('poleLightening'),
rootDarkeningSharpness: regl.prop('rootDarkeningSharpness'),
poleLighteningSharpness: regl.prop('poleLighteningSharpness'),
rectangularGridOpacity: regl.prop('rectangularGridOpacity'),
polarGridOpacity: regl.prop('polarGridOpacity'),
n: (ctx, props) => props.n || 0,
t: regl.prop('t'),
},
count: 3
});
return function drawPlot (props) {
regl.poll()
drawField(props || {});
}
}
};
return canvas;
}