is it possible to draw onto the canvas element without freezing the browser? I am printing approx. 3.000.000 dots to it, which freezes my browser for 2-3s.
Thank you!
This is what's happening 3 million times in a loop
for (var m = 0; m <= data.length - 1; m++) {
....
ctx_raw.beginPath();
ctx_raw.fillStyle = DATA_CONFIG.color;
ctx_raw.fillRect(x_value, y_value, 1, 1);
}
Edit 1: Improvement by Chris G is 30% more efficient
const image_data = ctx.getImageData(0, 0, canvas.width, canvas.height);
const data = image_data;
var index = (x_value + y_value * canvas.width) * 4;
data[index ] = 0;
data[index + 1] = 0;
data[index + 2] = 0;
data[index + 3] = 255;