function drawPixels(ctx, pixelColors) {
const dpi = devicePixelRatio;
const { width, height } = ctx.canvas;
const id = ctx.getImageData(0, 0, width, height);
const pixels = id.data;
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
const offData = y * id.width + x;
const offPixel = (y * id.width + x) * 4;
if (!pixelColors[offData]) continue;
const { r, g, b, opacity } = pixelColors[offData].rgb();
pixels[offPixel] = r;
pixels[offPixel + 1] = g;
pixels[offPixel + 2] = b;
pixels[offPixel + 3] = opacity * 255;
}
}
ctx.putImageData(id, 0, 0);
}