When I was helping with Taeyoon's first Signing Coders workshop I noticed that a lot of people got hung up on the concept of functions at the very beginning. They also had a hard time making sure that their code was actually inside a function (i.e. before the final closing bracket).
This made me wonder if it would be possible for p5 to always export the createCanvas function, so that a sketch could actually consist of the following:
createCanvas(100, 100);
fill(255, 0, 200);
Always exporting createCanvas isn't an option for p5, but we can support this use case from the widget.
Since we're doing static analysis already, it shouldn't be too hard for us to walk the AST and find out if they've declared a setup or draw function. If they haven't, we can just wrap the user's code in setup() ourselves.
From https://github.com/processing/p5.js/issues/1359#issuecomment-209658934:
Always exporting
createCanvas
isn't an option for p5, but we can support this use case from the widget.Since we're doing static analysis already, it shouldn't be too hard for us to walk the AST and find out if they've declared a setup or draw function. If they haven't, we can just wrap the user's code in
setup()
ourselves.