in P5 I have some drawings that remain static the entire time. It seems inefficient to put them in the draw method where they'll be drawn and redrawn again and again since they're not moving.
I tried placing the static drawings in setup but that doesn't work.
Is there a way to have some items drawn once and then kept statically rendered for more efficiency?
Sounds like you might be looking for the createGraphics function, which allows you to create a buffer that you can draw to. You'd only need to draw to the buffer once, and then you can draw the buffer to the screen each frame.
See this search for more info.
You can also learn more in the p5.js reference.
you could just put it in the draw function if it's not too complicated. I can render thousands of ellipses moving around without lagging. if you are using a for loop to draw some very complicated pattern then you should probably use the createGraphics function. the reason that you can't put it in the setup function is that if you have a background in the draw function it basically clears everything on the screen every frame
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With