processing-p5-convert is a source code translator that that converts Processing/Java code to p5.js/Javascript code. It includes a command line tool, and can also be used in the browser to convert and run Processing sketches.
Source code translation is implemented by parsing the Processing/Java code into a syntax tree. The syntax tree retains all code symbols, which facilitates reconstruction of the source code. processing-p5-convert walks the syntax tree, performing transformations as it reconstructs the source code.
Most of the basic syntax (braces, function calls, conditionals, loops) is identical between Java and Javascript. Some source code transformations handle language differences (e.g. declaration of variables, functions, and classes, for-each vs. for-of loops, Java ArrayList vs. Javascript array). Other source code transformations handle specific differences between the Processing and p5.js APIs.
Please report any issues that you find!
I use Processing to teach computer science. To run Processing sketches on web pages, I previously used the processing.js project, which has now been retired.
This project relies on these open source projects:
-
prettier (code formatting)
-
- java-parser (code parsing)
- prettier-java-plugin (code formatting)