P5.js Redo Tool

I hope everyone is doing well.

I’m trying to create a redo tool using P5.js.
I’m using a constructor function to make the tool.
What should I add to this function below? I want the redo button to work shapes.

Thank you


Pretend you are the redo button. When you get clicked, your job is to redo the last change that was undone.

How are you going to know what the undone change was change was?!? Thankfully, the undo action has a data structure that’s tracking all the changes. Hopefully it remembers the changes it’s undone! If you can make use of that information, you can simple draw the last shape again.

I tried this, but it didn’t work.

let fillVal = 255;

function draw() {
  if (keyIsDown(CONTROL) && keyIsDown(90)) fillVal = 0;
  rect(25, 25, 50, 50);