blur = (values) =>
values.map((d, i) => {
if (d == 0) return 0;
const cl = i % width > 0 ? i - 1 : i;
const cr = i % width < width - 1 ? i + 1 : i;
const tl = i % width > 0 ? i - width - 1 : i;
const tm = i - width;
const tr = i % width < width - 1 ? i - width + 1 : i;
const bl = i % width > 0 ? i + width - 1 : i;
const bm = i + width;
const br = i % width < width - 1 ? i + width + 1 : i;
return [i, cl, cr, tl, tm, tr, bl, bm, br]
.map((j) => {
if (j >= 0 && j < width * height && values[j] > 0) {
return (1 / 9) * values[j];
} else {
return (1 / 9) * d;
}
})
.reduce((a, b) => a + b);
})