function visualizeGrid(grid, {width = 640, ...options} = {}) {
const plot = Plot.plot({
grid: true,
round: true,
width,
height: Math.floor((grid.n / grid.m) * width * 0.8) + 20,
...options,
x: {domain: [grid.x1 - 0.5, grid.x2 + 0.5]},
y: {domain: [grid.y2 + 0.5, -0.5]},
color: {
domain: ["rock", "sand", "source"],
range: ["#5a4d41", "#c2b280", "red"]
},
marks: [
Plot.rect(grid.values, {
x1: (d, i) => grid.x1 + i % grid.m - 0.5,
y1: (d, i) => grid.y1 + Math.floor(i / grid.m) - 0.5,
x2: (d, i) => grid.x1 + i % grid.m + 0.5,
y2: (d, i) => grid.y1 + Math.floor(i / grid.m) + 0.5,
fill: (d) => d
})
]
});
plot.value = grid;
return plot;
}