We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I was wondering if there's a way to allow a user to write Processing code in the browser and run it, or if someone has already written a tool that does this. I imagine it would be done with reflection, which I know is possible in Java, but I don't know if there is a way to compile that kind of Java into JavaScript using processing.js. Maybe it could be done with the JavaScript eval function? I just don't want to reinvent the wheel, or do something that is not yet possible.
Answers
If you're running in the browser, you aren't using Java. You're using JavaScript.
(Technically you could use an applet, but that's almost definitely not what you want to do.)
Processing.js allows you to (basically) write Processing code that is then translated into JavaScript, which you can run in the browser.
Depending on what you want to do, you could just use something like CodePen to allow editing of code in the browser.
Here is a blog where I talk about using CodePen to add editable code to a tutorial site. (Or just go to any tutorial or example to see it in action.)
@eric_the_first -- this may be completely obvious, but I want to make sure (it wasn't clear from your question) that you are also starting from an awareness that
The output is compatible with online HTML+JavaScript coding tools of the kind that @KevinWorkman mentions, e.g.
While I haven't tried installing it, if you want to host your own p5.js sandbox, I believe that this is a working solution:
It currently has live demo sandbox.
The old Pjs library can transpile Java Mode sketches to JS in order to run it in the browser:
http://ProcessingJS.org/tools/processing-helper.html
http://www.OpenProcessing.org/sketch/create
Although we can't use any Java libraries. We've gotta stick to Processing's API:
http://ProcessingJS.org/reference/
We can install JavaScript Mode by following the instructions below:
https://GitHub.com/fjenett/javascript-mode-processing/issues/35
Alternatively, as already mentioned by others, you can decide to manually convert everything to p5.js library instead: https://GitHub.com/processing/p5.js/wiki/Processing-transition
Also @daniloprates recently called for collaborators on a not-yet-functioning online p2p5 project: "an experimental project that aims to convert Processing code into P5.js"
Interesting that all of this is happening in the context of things are moving farther away from Java-in-browser right now -- e.g. Oracle plans to kill the Java browser plugin starting early 2017.
Thanks for the prompt replies everyone. Embedding CodePen in my webpage looks like a great solution. I'll look into the other options too, in case one of them is a better fit.