function grid(data, rows, cols, maxVal=1) {
const gamma = 0.6;
const ctx = DOM.context2d(width / 2, width / 2);
ctx.fillStyle = 'lightgrey';
ctx.fillRect(0, 0, width, width);
ctx.scale(width / 2 / cols, width / 2 / rows);
for (let row=0; row<rows; row++) {
for (let col=0; col<cols; col++) {
const grey = Math.round(Math.max(0, Math.min(1, data[row][col] / maxVal)) ** gamma * 255);
ctx.fillStyle = `rgba(${grey}, ${grey}, ${grey})`;
ctx.fillRect(col, row, 1, 1);
}
}
return ctx.canvas;
}