You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue probably depends on having #188 done since it should significantly reduce the amount of duplicated JS code.
Currently, to simply use pyp5js to run a sketch via JS can be hard. Take the demo editor for example. pyp5js forced it to be a regular sketch with a demo.py file when this should be unnecessary. There should be a more elegant way to use pyp5js as a JS-like library.
Of course, such type of usage would only work under Pyodide mode since Transcrypt requires a transpilation step. In my best dream, we'd have a pyp5js.js file being served over a CDN (or maybe installable via npm?) and with an API you would use like:
constpythonCode=$("#python-code-holder").html();constcodeConfig={code: pythonCode,sketchDivId: "sketch-div",// optional, defaults to sketch-hoderpyodideUrl: "https://cdn.jsdelivr.net/pyodide/v0.18.1/full/pyodide.js",// optional, defaults to most recent versionglobalP5InsanceName: "p5_instance",// oṕtional, defaults to p5_instance. Usefull if user wants multiple sketches per page};constoutput=awaitPyP5Js.runCode(codeConfig);// this is a promiseconsole.log(output);console.log(window.p5_instance);
A question I have is: how to expose the p5 sketch object? Currently we're poorly storing it on window.instance, but the naming sucks, although I'm no expert on Javascript to have proper opinion if adding new variables to the window object is a bad thing or not. Insights here would be helpful =)
There's a lot to be done to achieve this. From the top of my head, I can list:
Refactor current window.runSketchCode to be a promise instead of synchronous function;
Add define a global PyP5Js object exposing the runCode function;
This issue probably depends on having #188 done since it should significantly reduce the amount of duplicated JS code.
Currently, to simply use pyp5js to run a sketch via JS can be hard. Take the demo editor for example.
pyp5js
forced it to be a regular sketch with ademo.py
file when this should be unnecessary. There should be a more elegant way to use pyp5js as a JS-like library.Of course, such type of usage would only work under Pyodide mode since Transcrypt requires a transpilation step. In my best dream, we'd have a
pyp5js.js
file being served over a CDN (or maybe installable via npm?) and with an API you would use like:A question I have is: how to expose the p5 sketch object? Currently we're poorly storing it on
window.instance
, but the naming sucks, although I'm no expert on Javascript to have proper opinion if adding new variables to thewindow
object is a bad thing or not. Insights here would be helpful =)There's a lot to be done to achieve this. From the top of my head, I can list:
window.runSketchCode
to be a promise instead of synchronous function;PyP5Js
object exposing therunCode
function;runCode
should download Pyodide and properly configure it;.tar.gz
file?)The text was updated successfully, but these errors were encountered: