My logic is simple, create a state array and a stateIndex, when the user interacts with the drawing, save the current state as an entry in the array and increment the stateIndex.
When the user presses “undo” (for this sketch press any key), decrement the stateIndex and draw to the page whatever value is in state for that index.
I’ve implemented it in this sketch https://editor.p5js.org/mr_anonymous/sketches/s0C1M7x1w but as you can see instead of storing the last state of the drawing it seems to only store the blank state.
Anyone know what’s going wrong?