pde2js: Processing to P5.js Converter
It can be used as web application with Spark or standalone, with the
- Clone the repository onto your local machine.
- We manage dependencies with
mvn installto install dependencies and run the tests. (You may need to install
mavenif it's not already on your local machine.)
ProcessingToP5Converter class is very simple:
String code = ...; // give your code as input here ProcessingToP5Converter converter = new ProcessingToP5Converter(code); System.out.println(converter.getJsCode());
A more thorough example is available in
If you'd like to run a web server instead, you can run
App.java, which will start a web server on
pde2js is implemented as series of visitor passes over the generated AST. These visitors can be found in the
ProcessingToP5Convertor calls each of these visitors to transform the AST in a way that makes it JS-friendly. (Each visitor has a class comment that should explain what it does; and by splitting up transformations into multiple passes, all of the visitors are quite short.)
The final pass,
var, function return types with
It's definitely nowhere close to perfect, but the first goal is to help new programmers avoid the headache and weird errors that occur when trying to manually transform their code for use on the Web. More complicated transformations can be added in the future.
Sample Processing files are given in the
samples/ directory, which should help to illustrate how each transformation over the AST works.
Contributions are welcome! Please let me know if you've found a bug, or have a feature request, by creating an issue. Pull requests are also welcome.