{
const context = createContext();
const pixels = new Uint32Array(context.getImageData(0, 0, width, height).data.buffer);
const startColor = pixels[startIndex];
const queue = new Queue;
queue.push(startIndex, 0);
yield context.canvas;
while (queue.length) {
await visibility();
const i = queue.pop();
const x = i % width;
const y = Math.floor(i / width);
context.fillStyle = "#f00";
context.fillRect(x, y, 1, 1);
context.fillStyle = "#ccc";
if (x > 0 && pixels[i - 1] === startColor) {
pixels[i - 1] = 0;
queue.push(i - 1, (x - startX) ** 2 + (y - startY) ** 2);
context.fillRect(x - 1, y, 1, 1);
}
if (x < width - 1 && pixels[i + 1] === startColor) {
pixels[i + 1] = 0;
queue.push(i + 1, (x - startX) ** 2 + (y - startY) ** 2);
context.fillRect(x + 1, y, 1, 1);
}
if (y > 0 && pixels[i - width] === startColor) {
pixels[i - width] = 0;
queue.push(i - width, (x - startX) ** 2 + (y - startY) ** 2);
context.fillRect(x, y - 1, 1, 1);
}
if (y < height - 1 && pixels[i + width] === startColor) {
pixels[i + width] = 0;
queue.push(i + width, (x - startX) ** 2 + (y - startY) ** 2);
context.fillRect(x, y + 1, 1, 1);
}
yield context.canvas;
}
}