generateInitState = (nInfected, density) => {
const initialState = (Array(radius * radius * 4)).fill(0);
const nSusceptible = Math.floor(radius * radius * density - nInfected);
const shuffled = [...Array(radius * radius).keys()]
.sort(() => 0.5 - Math.random()).sort(() => 0.5 - Math.random());
const infectedIdx = shuffled.slice(0, nInfected);
const susceptibleIdx = shuffled.slice(nInfected, nInfected + nSusceptible);
infectedIdx.forEach(i => {
initialState[4 * i + 1] = 255;
});
susceptibleIdx.forEach(i => {
initialState[4 * i] = 255;
});
return initialState;
}