It is very useful to export stills from a P5.js sketch, both for documentation, or as an ouput of your project.
A very simple trick is to create a keyboard shortcut allowing to download an image. keyPressed() is a built-in function from P5.js helping to do just that. Combined with a conditional, we can set the event to match any desired key, and then use save(), another built-in function to achieve our goal.
Automatic file-naming export
For a precise journaling or your exports, use regular string literals with Time & date helpers to name your exports:
let timestamp = ` ${year()}-${nf(month(),2)}-${nf(day(),2)}_ ${nf(hour(),2)}-${nf(minute(),2)}-${nf(second(),2)}`;// nf() helps converting numbers into strings, with a given number of digits. // https://p5js.org/reference/p5/nf/save(`myCanvas_${timestamp}.jpg`);// will download a file named something like // "myCanvas_2026-09-17_15-04-37.jpg"