2

My understanding is that Processing.js converts Processing code into javascript. But if one does not want to write in Processing, one can use methods and properties of the processing object like so:

function sketchCirc(processing) {

    function drawCirc() {
            processing.background(100);
            processing.ellipse(X,Y,radius,radius);
            processing.fill(0,121,184);
            processing.stroke(255);
        }

    processing.draw = function() {

        drawCirc();
    }

I prefer to use the above approach (meaning accessing methods of the processing object), but are there any downsides to this? I want to avoid having to learn the Processing language from scratch. Please let me know what your ideas are.

1 Answer 1

4

Processing.js doesn't convert Processing code into JavaScript. It is a Javascript library that mirrors/wraps Processing methods. It's still a javascript library, like any and since it mirrors Processing's main functions, you can use roughly the same syntax. If Processing.js converted Processing code into JavaScript, it would convert Java libraries to JavaScript, which is not true.

There shouldn't be any downsides to using Processing as you've described above.

Processing's reference isn't amazingly long nor difficult and if you plan to stay in 2D, you'll probably use even less of what's listed there. If you're using an IDE with autocompletion for JS you probably won't even need to the reference as function names are mostly intuitive.

It might worth having a play with Processing and getting used as you'll also be able to deploy standalone applications to Windows/Linux/OSX/Android. The alpha releases even include a JavaScript mode with some neat examples, straight out of the box.

Update Using Processing 2 or newer versions you can add a JavaScript Mode into the IDE which will also include some nice examples.

Also, there is newer, pure javascript implementation called p5.js. This might be closer to hat you're looking for.

Still if Processing isn't your cup of tea, you might want to try PaperJS or Raphael.

Sign up to request clarification or add additional context in comments.

6 Comments

Your statement Processing.js doesn't convert Processing code into JavaScript contradicts the Processing.js doc. Your answer is confusing: Processing code (often referred to as sketches) is the code that the Processing programming language interprets, thus also different from java. In what language Processing is implemented (java or javascript) is a different issue. (I'm not confident enough with Processing to edit your answer or provide a different one.)
I guess we're getting to the blurry line of preference. Processing is promoted as a language in itself, but orginally it always used Java and expanded on it. If you look at Processing from the Java point of view Processing is a java library which abstracts a lot of the common functionalities in a minimal API, but probably not a standalone language in itself. I the assumption was made that if Processing.js converts Processing ode into JavaScript, this will also work with libraries, which is false. Processing.js doesn't convert anything AFAIK, although again that is now how Processing.js...
...promotes itself. From my point of view, Processing.js is a javascript port of the java Processing library. The nice thing about it is it allows the user to use pretty much the same syntax as you would in the Processing IDE: java. Still notice that not all the language features as supported (e.g. try using a typed ArrayList with processing.js). Long story short, if indeed Processing.js was converting Processing code to JavaScript, it would of course convert all the libraries, right ? Libraries are compiled, but trying to run the source classes through Processing.js will not work...
...as I mentioned, it's going back to the main difference between java and javascript
if indeed Processing.js was converting Processing code to JavaScript, it would of course convert all the libraries, right ... Not necessarily: it really depends upon what processingjs can compile. As it stands today, the processing-1.4.1.js compile function builds an abstract syntax tree. A quick look at the parseProcessing function suggest that it understands even generics. The aprox. 1200 lines of code make it difficult to grasp its limitations, but I guess it understands only a subset of Java. Another difficult one is native code
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.