render = {
const canvas = document.createElement('canvas');
canvas.width = 1000;
canvas.height = 1000;
const gl = canvas.getContext('webgl', { premultipliedAlpha: false });
const gpu = new GPU.GPU({canvas, context: gl});
function getColor(t) {
if (t >= 0 && t <= 0.25)
return [255 + (0 - 255) * t / 0.25, 255 + (0 - 255) * t / 0.25, 255];
if (t >= 0.25 && t <= 0.55)
return [0, 255 * (t - 0.25) / 0.3, 255 + (0 - 255) * (t - 0.25) / 0.3];
if (t >= 0.55 && t <= 0.85)
return [255 * (t - 0.55) / 0.3, 255, 0];
if (t >= 0.85 && t <= 1)
return [255, 255 + (0 - 255) * (t - 0.85) / 0.15, 0];
return [255, 255, 255];
}
return gpu.createKernel(function(canvas) {
const pixel = canvas[this.thread.y][this.thread.x];
const alpha = pixel[3];
const rgb = getColor(alpha);
this.color(rgb[0], rgb[1], rgb[2], alpha);
})
.setOutput([1000, 1000])
.setGraphical(true)
.setFunctions([getColor]);
}