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.

dopatraman
  • 13,416
  • 29
  • 90
  • 154

1 Answers1

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.

Community
  • 1
  • 1
George Profenza
  • 50,687
  • 19
  • 144
  • 218
  • Your statement _Processing.js doesn't convert Processing code into JavaScript_ contradicts the [Processing.js doc](http://processingjs.org/articles/jsQuickStart.html#quickstart). Your answer is confusing: _Processing code_ (often referred to as _sketches_) is the code that the [Processing programming language](http://processing.org/about/) 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.) – Alberto Mar 06 '13 at 08:33
  • 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... – George Profenza Mar 08 '13 at 17:44
  • ...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... – George Profenza Mar 08 '13 at 18:12
  • ...as I mentioned, it's going back to the main difference between java and javascript – George Profenza Mar 08 '13 at 18:14
  • _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](http://en.wikipedia.org/wiki/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 – Alberto Mar 11 '13 at 10:02
  • ...but this is just to be a bit pedantic. In my opinion, this debate doesn't affect the essence of your answer "_There shouldn't be any downsides to using Processing as you've described above_," that due to my lack of experience with Processing, I cannot assess. – Alberto Mar 11 '13 at 10:08