Storing drawing data in array for P5 drawing application?

Hi I am trying to help out a few of my students with a question that they have about drawing programs that they are building in P5.

Start by drawing to the canvas using:

line(mouseX, mouseY, pmouseX, pmouseY

Then if they have something like an expandable menu that pops up over their drawing, what is the simplest way to store the drawing so that they can display it again when the expandable menu closes.

I’m having a hard time explaining this. So this is an example:

This student wants to display more drawing menu options when the user clicks the More box. But then when you close the box, have the drawing come back. I think they have to store their drawing data in an array, but is there a simpler way to do it? We are all beginners with P5, so thanks for any advice you might have!

1 Like


aside from your question please also see 2 different ways

1 Like

Thank you! This is exactly what we needed.