/*
This JS code is run once per cell (100x100 = 10000 calls per frame. Be mindful.).
variables:
x: X position of the cell
y: Y position of the cell
cell: The original cell. It is advised you make a new cell as seen below.
getCell(x, y): Gets a cell based on the coordinates.
max_value: The highest state a cell can be in (based on the palette)
Review the below code to get some ideas.
*/
let new_cell = {
state: cell.state
};
if(cell.state > 0) {
new_cell.state = cell.state - 1;
return new_cell;
}
for(let offsetX of [-1, 1]) {
if(getCell(x + offsetX, y).state == max_value) {
new_cell.state = max_value;
return new_cell;
}
}
for(let offsetY of [-1, 1]) {
if(getCell(x, y + offsetY).state == max_value) {
new_cell.state = max_value;
return new_cell;
}
}
if(Math.trunc(Math.random() * 10000) == 69) {
new_cell.state = max_value;
}
return new_cell;