diff --git a/.gitignore b/.gitignore deleted file mode 100644 index c8af71c..0000000 --- a/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -# OS X ignores -.DS_Store - -# Jekyll ignores -_site diff --git a/404.html b/404.html deleted file mode 100644 index 02cda41..0000000 --- a/404.html +++ /dev/null @@ -1,5 +0,0 @@ ---- -layout: default ---- -

Page not found

-

The page you requested could not be found. Click here to return home.

diff --git a/README.md b/README.md index 8a613a7..96f5e07 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,14 @@ -The Processing.js website -========================= +Processing.js +============= -This is our website, in all it's glory. +Processing.js was a port of the [Processing](https://processing.org) programming language for the web, and was maintained from November 2011 to December 2018, having been unofficially retired in March of 2017. -Testing the website locally ---------------------------- +If you're looking for the last version of Processing.js before the project was officially discontinued, you're looking for [v1.6.6](https://github.com/processing-js/processing-js/tree/v1.6.6). -Install [Jekyll](https://github.com/mojombo/jekyll/wiki/Install) on your computer, -clone this repository, and run `jekyll` inside the root of the repository. This will -compile (yes, seriously) the website into the _site directory, and start a localhost -web server running on port 4000. Jekyll will automatically recompile the site if you -make any changes. +That last version of the website itself can be found as an [archived tree](https://github.com/processing-js/processing-js.github.io/tree/archive) on github. + +If you want to use Processing on the web today, please have a look at the newer [P5.js](https://p5js.org) project, which was a reimagining of Processing "if it had been designed for use on the web from the get-go". + +Thank you to everyone who used Processing.js in the past, and of course: everyone who worked on the project over the years. + +- The Processing.js Team diff --git a/_config.yml b/_config.yml deleted file mode 100644 index 0161519..0000000 --- a/_config.yml +++ /dev/null @@ -1,8 +0,0 @@ -# Github defaults -safe: true -lsi: false -pygments: true - -# Processing.js settings -auto: true -server: true diff --git a/_layouts/default.html b/_layouts/default.html deleted file mode 100644 index 7e7f932..0000000 --- a/_layouts/default.html +++ /dev/null @@ -1,83 +0,0 @@ - - - - - Processing.js - - - - - - - -
-
- -
- a port of the Processing Visualization Language - - - -
-
-{{ content }} -
- -
- - -
- - Fork me on GitHub - - - diff --git a/_layouts/post.html b/_layouts/post.html deleted file mode 100644 index 71278da..0000000 --- a/_layouts/post.html +++ /dev/null @@ -1,8 +0,0 @@ ---- -layout: default ---- -
-

{{ page.title }}

-
{{ page.date | date_to_string }}
-{{ content }} -
diff --git a/articles/_posts/2011-12-01-PomaxGuide.html b/articles/_posts/2011-12-01-PomaxGuide.html deleted file mode 100644 index 6b065c6..0000000 --- a/articles/_posts/2011-12-01-PomaxGuide.html +++ /dev/null @@ -1,1423 +0,0 @@ ---- -layout: default -desc: Pomax's guide to Processing.js -title: Pomax Guide -permalink: /articles/PomaxGuide.html ---- - - -
-

Pomax's guide to Processing.js

- - -

This page tries to explain how to quickly and (as) correctly (as possible) use -Processing sketches on webpages. The information is based on the work done by -the processing.js group.

- -

This information on this page reflects the best of my knowledge anno November -2010, and processing.js becomes more and more complete, so it is possible that the -information on this page changes over time. Should you spot any incompletenesses -or blatant mistakes, please contact me at - -pomax at nihongoresources.com, - -with the obvious substitutions in place to make it a legal email address.

- - -

What is Processing?

- -

The "Processing" language (also referred to as "P5") is a programming language with a focus on data visualisation. Of course, "data" is a loose concept, and -Processing can be used for anything from drawing a few lines and circles on a screen, to full blown interactive animations. -In fact, a basic Processing program is two lines of code, and will already play an animation:

- -{% highlight java %} -void setup() { size(..., ...); } -void draw() {} -{% endhighlight %} - -

Of course this program doesn't show you anything, because all it does is set up the visual context to have a certain width and height (indicated in the setup -method as the size(...,...) instruction) and then calls draw() every few milliseconds. Of course, draw() is empty, so it won't actually show you anything. -A more useful minimal program would be a "hello world" program, but I hate those because they only show a programming language can write text, and that's pretty much the -least interesting feature of any programming language. Instead let's look at a minimal program that makes sense for a data visualisation language:

- -{% highlight java %} -float frame = 0; // we start at frame 0 -float framerate = 24; // our "sketch" will have a framerate of 24 frames per second. - -int ball_x; // ball administration: x coordinate -int ball_y; // ball administration: y coordinate -int ball_radius = 20; // ball administration: ball radius - -void setup() { - size(200,200); // set draw area size - frameRate(framerate); // set animation framerate - ball_x = width/2; // set the initial ball coordinates - ball_y = ball_radius; // set the initial ball coordinates - stroke(#003300); // set the default shape outline colour - fill(#0000FF); // set the default shape fill colour -} - -void draw() { - frame++; // note that we're one frame further than last time - float bounce_height = height/2 * abs(sin(PI*frame/framerate)); // compute the ball height for this frame - float ball_height = height - (bounce_height+ball_radius); // because the top of the screen is 0, and the bottom is "height", - background(#FFFFEE); // clear the drawing area - ball_y = (int) (ball_height); // set the new ball y position - ellipse(ball_x,ball_y,ball_radius,ball_radius); // draw the ball -} -{% endhighlight %} - - -
-play controls: - - -
-
-

This looks a bit long for a minimal program, but then again, this actually does something: it shows us a ball that bounces up and down, taking one second for each bounce. It shows a few aspects of -Processing too: every variable is strongly typed. So you have to indicate what you'll be using a variable for, and you can choose from:

- - - -

And of course there are also the typical complex data types:

- - - -

You'll see why this last one turns out to be really useful later on.

- -

Coming back to the minimally functional example of a Processing program, or "sketch", there are also some examples of Processing' own API at work. The following methods are native Processing calls:

- - - -

The Processing API is in fact quite expansive (See http://processing.org/reference for the full list), but it can't cover everything. Luckily it supports object oriented programming, so that our previous example can also be written as an object oriented sketch:

- -
-
-Bouncer bouncer;
-void setup() {
-size(200,200);
-frameRate(24);
-stroke(#003300);
-fill(#0000FF);
-bouncer = new Ball(width/2,20,20);
-}
-void draw() {
-bouncer.computeNextStep(width, height, frameRate);
-background(#FFFFEE);
-bouncer.draw();
-}
-
-interface Bouncer {
-void computeNextStep(int width, int height, float framerate);
-void draw(); 
-}
-
-class Ball implements Bouncer
-{
-int x,y,radius;
-int step=0;
-
-Ball(int x, int y, int r) {
-this.x = x;
-this.y = y;
-this.radius = r;  }
-
-void computeNextStep(int sketch_width, int sketch_height, float frame_rate) {
-step++;
-float sin_value = abs(sin(PI*step/(float)frame_rate));
-float bounce_height = sketch_height/2 * sin_value;
-float ball_height = sketch_height - (bounce_height + radius);
-y = (int) (ball_height); }
-
-void draw() { ellipse(x,y,radius,radius); }
-}
- -
-play controls: - - -
-
-

Instead of doing everything in the draw() function, the object oriented approach tucks all the code that relates to computing the ball's position in the definition -for what we consider a "Ball". To be good object oriented programmers, we've also said that things that are a Ball are also a Bouncer, and this lets us extend our -sketch very easily to instead of a bouncing ball, have a bouncing box by keeping almost everything the same, and adding a new class Box that's a Bouncer:

- -
-
-
-void setup() {
-...
-bouncer = new Box(width/2,20,20,20);
-}
-class Box implements Bouncer
-{
-int x,y,w,h;
-int step=0;
-
-Box(int x, int y, int w, int h) {
-this.x = x;
-this.y = y;
-this.w = w;
-this.h = h; }
-
-void computeNextStep(int sketch_width, int sketch_height, float frame_rate) {
-step++;
-float sin_value = abs(sin(PI/2.0 + (PI*step/(float)frame_rate)));
-float bounce_height = sketch_height/2 * sin_value;
-float ball_height = sketch_height - (bounce_height + h);
-y = (int) (ball_height); }
-
-void draw() { rect(x,y,w,h); }
-}
-
- -
-play controls: - - -
-
-

All of a sudden we have a bouncing box, that starts from a falling position instead of from the ground, and we didn't have to modify the master draw() function for -it! In fact, let's just use a group of bouncing things:

- - -
-
-Bouncer[] bouncer = new Bouncer[3];
-
-void setup() {
-...
-bouncer[0] = new Ball(width/3-20,20,20);
-bouncer[1] = new Box(width/2-10,20,20,20);
-bouncer[2] = new Ball((2*width/3)+20,20,20);
-}
-
-void draw() {
-for(int b=0, end=bouncer.length; b<end;b++) {
-bouncer[b].computeNextStep(width, height, frameRate); }
-background(#FFFFEE);
-for(int b=0, end=bouncer.length; b<end;b++) {
-bouncer[b].draw(); }
-}
-...
-
- -
-play controls: - - -
-
-

Fantastic, two bouncing balls and a bouncing box, bouncing counter-point to each other. But it's not very interactive yet. Let's change it so that we can "hang on" -to bouncing things until we let go of them again. Processing allows interaction with the keyboard and mouse, using what are known as "event handlers", methods that Processing automatically calls for you when you use the keyboard or mouse. In this case we care about mouse interaction, so we'll look at mousePressed and mouseReleased events:

- - -
-
-
-void mousePressed() {
-for(int b=0, end=bouncer.length; b<end;b++) {
-if(bouncer[b].mouseOver(mouseX, mouseY)) {
-bouncer[b].mousePressed(); 
-}
-}
-}	
-void mouseReleased() {
-for(int b=0, end=bouncer.length; b<end;b++) {
-bouncer[b].mouseReleased(); 
-}
-}	
-abstract class Bouncer
-{
-int x, y;
-boolean canmove = true;
-int step = 0;
-abstract void computeNextStep(int width, int height, float framerate);
-abstract void draw();
-abstract boolean mouseOver(int mx, int my);
-void mousePressed() { canmove = false; }
-void mouseReleased() { canmove = true; }
-}
-
-class Ball extends Bouncer
-{
-int radius;
-
-Ball(int x, int y, int r) {
-this.x = x;
-this.y = y;
-this.radius = r;  
-}
-void computeNextStep(int sketch_width, int sketch_height, float frame_rate) {
-if(canmove) {
-step = (int)((step+1) % frame_rate);
-float sin_value = abs(sin(PI*step/(float)frame_rate));
-float bounce_height = sketch_height/2 * sin_value;
-float ball_height = sketch_height - (bounce_height + radius);
-y = (int) (ball_height); 
-}
-}
-void draw() { ellipse(x,y,radius,radius); }
-
-boolean mouseOver(int mx, int my) {
-return sqrt((x-mx)*(x-mx) + (y-my)*(y-my)) <= radius; 
-}
-}
-class Box extends Bouncer
-{
-int w,h;
-int step=0;
-
-Box(int x, int y, int w, int h) {
-this.x = x;
-this.y = y;
-this.w = w;
-this.h = h; 
-}
-void computeNextStep(int sketch_width, int sketch_height, float frame_rate) {
-if(canmove) {
-step = (int)((step+1) % frame_rate);
-float sin_value = abs(sin(PI/2.0 + (PI*step/(float)frame_rate)));
-float bounce_height = sketch_height/2 * sin_value;
-float ball_height = sketch_height - (bounce_height + h);
-y = (int) (ball_height); 
-}
-}
-void draw() { rect(x,y-h/2,w,h); }
-boolean mouseOver(int mx, int my) {
-return x<=mx && mx<=x+w && (y-h/2)<=my && my<=(y+h/2); 
-}
-}
-
- -
-play controls: - - -
-
-

Because the Ball and Box classes will do the same thing on mouse interaction, the interface Bouncer has been changed to an actual class too, to take care of some of -the shared functionality. Now if you click on anything that's a Bouncer it'll stop moving until you let it go. Let's go one step further an just allow us to move the -bouncing things around, too.

- -
-
-Bouncer[] bouncer = new Bouncer[3];	
-void setup() {
-size(200,200);
-frameRate(24);
-stroke(#003300);
-fill(#0000FF);
-bouncer[0] = new Ball(width/3-20,20,20);
-bouncer[1] = new Box(width/2-10,20,20,20);
-bouncer[2] = new Ball((2*width/3)+20,20,20);
-}	
-void draw() {
-for(int b=0, end=bouncer.length; b<end;b++) {
-bouncer[b].computeNextStep(width, height, frameRate); 
-}
-background(#FFFFEE);
-for(int b=0, end=bouncer.length; b<end;b++) {
-bouncer[b].draw(); 
-}
-}	
-void mousePressed() {
-for(int b=0, end=bouncer.length; b<end;b++) {
-if(bouncer[b].mouseOver(mouseX, mouseY)) {
-bouncer[b].mousePressed(); 
-}
-}
-}
-void mouseReleased() {
-for(int b=0, end=bouncer.length; b<end;b++) {
-bouncer[b].mouseReleased(); 
-}
-}
-void mouseDragged() {
-for(int b=0, end=bouncer.length; b<end;b++) {
-bouncer[b].mouseDragged(mouseX, mouseY); 
-}
-}		
-abstract class Bouncer
-{
-int x, y;
-boolean canmove = true;
-int step = 0;
-int xoffset = 0;
-int yoffset = 0;
-
-void computeNextStep(int width, int height, float framerate) {
-if(canmove) {
-reallyComputeNextStep(width, height, framerate); 
-}
-}
-abstract void reallyComputeNextStep(int width, int height, float framerate);
-
-abstract void draw();
-
-abstract boolean mouseOver(int mx, int my);
-
-void mousePressed() {
-canmove = false; 
-}
-void mouseReleased() {
-canmove = true;
-x += xoffset;
-y += yoffset;
-xoffset = 0;
-yoffset = 0; 
-}
-void mouseDragged(int mx, int my) {
-if(!canmove) {
-xoffset = mx-x;
-yoffset = my-y;
-}           
-}
-}
-
-class Ball extends Bouncer
-{
-int radius;
-
-Ball(int x, int y, int r) {
-this.x = x;
-this.y = y;
-this.radius = r;  
-}
-
-void reallyComputeNextStep(int sketch_width, int sketch_height, float frame_rate) {
-step = (int)((step+1) % frame_rate);
-float sin_value = abs(sin(PI*step/(float)frame_rate));
-float bounce_height = sketch_height/2 * sin_value;
-float ball_height = sketch_height - (bounce_height + radius);
-y = (int) (ball_height); 
-}
-
-void draw() { ellipse(x+xoffset,y+yoffset,radius,radius); }
-
-boolean mouseOver(int mx, int my) {
-return sqrt((x-mx)*(x-mx) + (y-my)*(y-my)) <= radius; 
-}
-}	
-class Box extends Bouncer
-{
-int w,h;
-int step=0;
-
-Box(int x, int y, int w, int h) {
-this.x = x;
-this.y = y;
-this.w = w;
-this.h = h; 
-}
-
-void reallyComputeNextStep(int sketch_width, int sketch_height, float frame_rate) {
-step = (int)((step+1) % frame_rate);
-float sin_value = abs(sin(PI/2.0 + (PI*step/(float)frame_rate)));
-float bounce_height = sketch_height/2 * sin_value;
-float ball_height = sketch_height - (bounce_height + h);
-y = (int) (ball_height);
-}
-
-void draw() { rect(x+xoffset,(y-h/2)+yoffset,w,h); }
-
-boolean mouseOver(int mx, int my) {
-return x<=mx && mx<=x+w && (y-h/2)<=my && my<=(y+h/2); 
-}
-}
-
- -
-play controls: - - -
-
-

And with that, on to the original topic of this article: using Processing on web pages

- - - -

Putting a sketch on the page

- -

The great thing about Processing is that it can be used on webpages. Traditionally, you would convert your sketch to a java applet, and embed that on a page, but the processing.js project has changed this: you can now use your sketches directly without turning it into an applet at all. In the same way that you include a javascript file, or a CSS stylesheet, you can simply link to your sketch and magic happens.

- -

Let's say we save the previous sketch, with the bouncing and the mouse interaction, as "mysketch.pde", and we want to show this on a webpage. Using processing.js, this is a trivially simple trick:

- -
-
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>My Processing Page</title>
-<script type="text/javascript" src="processing.js"></script>
-</head>
-
-<body>
-<canvas id="mysketch" data-processing-sources="mysketch.pde"></canvas>
-</body>
-</html>
- - -
-play controls: - - -
-
-

And we're done. In fact, I went ahead and made sure this page already uses processing.js, and that there is a mysketch.pde to load. If you click on the play control for the sketch above, it will start running, and do exactly what you would expect it to do based on what it does when you run it from the Processing environment.

- - - -

Putting a sketch inline on the page

- - -

While not recommended, you can also put your sketch directly on a page, much like how you can put javascript or CSS styles directly on a page. However, in order for processing.js to properly load your code, you'll need some extra help in the form of the "init.js" file that is included with the processing.js examples archive from the processing.js downloads page

- -
-
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>My Processing Page</title>
-<script type="text/javascript" src="processing.js"></script>
-
-<script type="text/javascript" src="init.js"></script>
-</head>
-<body>
-<script type="application/processing" target="mysketch">
-void setup() { ... }
-void draw() { ...}
-class SomeClass {
-...
-}
-</script>
-
-<canvas id="mysketch"/></canvas>
-</body>
-</html>
- -

There are several reasons for why this is not a very good practice, but the most important one is that this way you can't be sure whether or not you've written a bug-free sketch. By writing it directly on the page, you might in fact have written some buggy code, which you will then find is terribly hard to debug because the browser is not equiped with a debugger for Processing code. In fact, processing.js rewrites your sketch into pure javascript (using some terribly clever tricks that we won't go into), so even if when it tells you where the error is in a javascript debugger, it will tell you where it went wrong in the converted javascript object, not the actual place in your source code. So keep it as a separate file, and make sure to test your code in the Processing IDE!

- - - - -

Making your sketch and your page see each other

- - -

Just running a sketch on a page is fine, but the benefit of a webpage is that it offers the kind of user interaction that you can't get from within the sketch itself. Pretty buttons, text areas that fold away, pop up, etc. make it very attractive to have your sketch do all the animation graphicsy work, but have all the information about the sketch, as well as controls for it, on the webpage. This is entirely possible - in fact, the "stop" and "play" buttons for the sketch above are examples of javascript telling the sketch what to do. Because a webpage offers more than a plain sketch can, processing.js has a few special tricks up its sleeve, so that you can get the most out of your creative work. Arguably the most important of these is the "get the sketch" function:

- -
-
-var mysketch = Processing.getInstanceById('mysketchid');
- -

This is the pivotal function on the javascript side of things. It gives you a direct reference to your sketch, and everything in it, so that you can call any function and examine and modify any -variable that is in the sketch.

- - - -

Making javascript see your sketch

- -

Let's say we have the following sketch:

- -

-
-void setup() {
-size(200,200);
-noLoop();						// turn off animation, since we won't need it
-stroke(#FFEE88);
-fill(#FFEE88);
-background(#000033);
-text("",0,0);					// force Processing to load a font
-textSize(24);					// set the font size to something big
-}
-
-void draw() { }
-
-void drawText(String t)
-{
-background(#000033);
-// get the width for the text
-float twidth = textWidth(t);			
-// place the text centered on the drawing area
-text(t, (width - twidth)/2, height/2);	
-}
-
- -

We can make this sketch draw a different text based on some text we have on our webpage, using javascript. This is in fact really easy: first, -let's save this processing code as mysketch2.pde, and load it onto a page in the same way as earlier in the article. -Then, we use javascript to ask for our sketch instance, after which we call the "drawText" function with some text that we get from the web page -that the sketch is running on:

- -
-
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>My Processing Page</title>
-<script type="text/javascript" src="processing.js"></script>
-
-<script type="text/javascript">
-function drawSomeText(id) {
-var pjs = Processing.getInstanceById(id);
-var text = document.getElementById('inputtext').value;
-pjs.drawText(text); }
-</script>
-</head>
-<body>
-<canvas id="mysketch2" data-processing-sources="mysketch2.pde"/></canvas>
-
-<input type="textfield" value="my text" id="inputtext"/>
-<button onclick="drawSomeText('mysketch2')"/>
-</body>
-</html>
-
- -

This has the same effect as the sketch that's running below. Simply fill in a bit of text, and hit the ▶ button to see the sketch render it on the drawing area.

- -
-set text: - - -
-
-

So far so good, but what if we also want to make Processing code call javascript? In order for us to so, while making sure the sketch keeps running both on your page an in the Processing environment, we have to do a bit more work

- - - -

Making your sketch "see" javascript

- -

You can't just stick plain javascript in your sketch and hope everything goes well because it's "on a web page". A better approach is to neatly separate your sketch and your on-page javascript, and ensure that whatever you want to do on your page runs through a javascript function. How do we do that? Let's say we have the following page:

- -
-
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>My Processing Page</title>
-
-<script type="text/javascript" src="processing.js"></script>
-</head>
-<body>
-<canvas id="mysketch3" data-processing-sources="mysketch3.pde"/></canvas>
-<div id="coordinates">
-
-x/y: <input type="textfield" id="xcoord"/>/<input type="textfield" id="ycoord"/>
-</div>
-</body>
-</html>
- -

And say we have the following sketch, which we'll save as mysketch3.pde:

- -
-
-void setup() {
-size(200,200);
-stroke(255);
-background(0);
-noLoop(); 
-}
-void draw() {
-fill(0,0,0,40);
-rect(-1,-1,width+2,height+2); 
-}
-void mouseMoved() {
-line(mouseX,0,mouseX,height);
-line(0,mouseY,width,mouseY);
-redraw(); 
-}
-
- -

As an exercise, let's try to get the mouse coordinates from that mouseMoved event onto the page. This means we'll need to define a javascript function that will do this for us:

- -
-
-function showXYCoordinates(x, y) {
-document.getElementById('xcoord').value = x;
-document.getElementById('ycoord').value = x; 
-}
-
- -

And we'll need to make the sketch know that there is such a thing as javascript, and that it has this function:

- -
-
-interface JavaScript {
-void showXYCoordinates(int x, int y); 
-}
-
-void bindJavascript(JavaScript js) {
-javascript = js; 
-}
-
-JavaScript javascript;
-
-void setup() { ...}
-void draw() { ... }
-void mouseMoved() {
-...
-if(javascript!=null){
-javascript.showXYCoordinates(mouseX, mouseY); 
-}
-}
-
- -

What we've done is we've told Processing: "There are things that follow the JavaScript interface. This means that whatever else they can do, they'll have a function called "showXYCoordinates" and that function takes two arguments, both of type int." -- of course, the sketch will not magically know our on-page javascript, so we also define a function that lets us tell the sketch what actually counts as javascript, -which is what the bindJavascript(...) function is for.

- -

This leaves us with needing to make sure that we really do tell the sketch what javascript is, which we'll do as follows on the page:

- -
-
-var bound = false;
-
-function bindJavascript() {
-var pjs = Processing.getInstanceById('mysketch3');
-if(pjs!=null) {
-pjs.bindJavascript(this);
-bound = true; 
-}
-if(!bound) setTimeout(bindJavascript, 250); 
-}
-
-bindJavascript();
- -

This defines a function that checks whether processing.js has loaded our sketch yet. If not, it tries again 250ms later. If the sketch is loaded, the reference to -the sketch is used to tell it what "javascript" should be. This is achieved by virtue of processing.js trusting that you wrote valid code. As such, as long as you're on -the javascript side of things, you can pass the sketch whatever you like, and the sketch will trust that it conforms to what the method says the type should be. In this -case we pass the javascript "this" value (which refers to the global javascript environment for the current window), and tell processing "this thing conforms to your JavaScript interface, s -o it has loads of things but the only thing you need to be concerned about is whether or not it has a showXYCoordinates(int, int) function, which it does."

- -

So, our final sketch behaves like the sketch below, and our final page source looks like the following:

- -
-
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>My Processing Page</title>
-
-<script type="text/javascript" src="processing.js"></script>
-<script type="text/javascript">
-var bound = false;
-
-function bindJavascript() {
-var pjs = Processing.getInstanceById('mysketch3');
-if(pjs!=null) {
-pjs.bindJavascript(this);
-bound = true; }
-if(!bound) setTimeout(bindJavascript, 250); 
-}
-bindJavascript();
-
-function showXYCoordinates(x, y) {
-document.getElementById('xcoord').value = x;
-document.getElementById('ycoord').value = y; 
-}
-</script>
-</head>
-<body>
-
-<canvas id="mysketch3" data-processing-sources="mysketch3.pde"/></canvas>
-<div id="coordinates">
-x/y: <input type="textfield" id="xcoord"/>/<input type="textfield" id="ycoord"/>
-</div>
-</body>
-
-</html>
- - - -
-x/y coordinates: / -
-
- -

Passing complex objects from javascript to your sketch

- -

This leaves us with one last topic that we need to cover, simply because it's so common: using an AJAX approach to get some data, and then passing that data, properly formatted, to your sketch.

- - - -

Actually using Processing objects

-

One interesting thing that processing.js allows us to do is to create objects as we defined them in our sketch, in javascript, -and then hand them over to the sketch to deal with. To give an example, let's use the following sketch, which lets you draw points by clicking with the mouse, and links up all the points with lines:

- -
-
-ArrayList points;
-
-ArrayList getPoints() { return points; }
-
-void setup() {
-size(200,200);
-points = new ArrayList(); 
-noLoop();
-stroke(255,0,0);
-fill(255); 
-}
-
-void draw() {
-background(200,200,255);
-for(int p=0, end=points.size(); p<end; p++) {
-Point pt = (Point) points.get(p);
-if(p<end-1) {
-Point next = (Point) points.get(p+1);
-line(pt.x,pt.y,next.x,next.y); }
-pt.draw(); }
-}
-
-void mouseClicked() {
-points.add(new Point(mouseX,mouseY));
-redraw(); 
-}
-
-class Point {
-int x,y;
-Point(int x, int y) { this.x=x; this.y=y; }
-void draw() { ellipse(x,y,10,10); }
-}
-
- - -
click to place points
-
- - -

We can also make javascript place some points for us, automatically, by using the following javascript:

- - -
-
-function loadPoints(id, button) {
-var pjs = Processing.getInstanceById(id);
-var points = pjs.getPoints();
-points.add(new pjs.Point(10,10));
-points.add(new pjs.Point(10,190));
-points.add(new pjs.Point(190,190));
-points.add(new pjs.Point(190,10));
-pjs.draw(); 
-}
-
- -
load points:
- -
-

Because processing.js turns the sketch into actual javascript, every class we defined in it can be created using new pjs.ClassName(arguments,...).

- - - -

JSON

- -

Another way to get data from javascript into a sketch is by way of a JSON description. JSON is particulary interesting because javascript can read a JSON text string and immediately turn it into a full-fledged javascript object. Let's look at our point-drawing sketch again, this time with a dedicated "addPoint" method:

- -

-
-ArrayList points;
-void setup() {
-size(200,200);
-points = new ArrayList(); 
-}
-void draw() {
-background(200,200,255);
-for(int p=0, end=points.size(); p<end; p++) {
-Point pt = (Point) points.get(p);
-if(p<end-1) {
-Point next = (Point) points.get(p+1);
-line(pt.x,pt.y,next.x,next.y); }
-pt.draw(); }
-}
-
-void mouseClicked() {
-addPoint(mouseX,mouseY); 
-}
-
-Point addPoint(int x, int y) {
-Point pt = new Point(x,y);
-points.add(pt);
-return pt; 
-}
-
-class Point {
-int x,y;
-Point(int x, int y) { this.x=x; this.y=y; }
-void draw() {
-stroke(255,0,0);
-fill(255);
-ellipse(x,y,10,10); 
-}
-}
-
- -

Now what if -- instead of using mouse clicks, or predetermined javascript -- we want to load points based on some data on a remote server? We change our web page so -that it can deal with JSON data from a remote server, and then make our javascript tell the sketch what to do:

-
-
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>My Processing Page</title>
-<script type="text/javascript" src="jquery.js"></script>
-
-<script type="text/javascript" src="processing.js"></script>
-<script type="text/javascript">
-function drawPoints(id) {
-var pjs = Processing.getInstanceById(id);
-var json = $.get("http://thatfunkysite.com/serving/json.asp");
-var data = eval("("+json+")");
-if(data) {
-// we know the JSON is an array of points, called "points"
-for(p=0, end=data.points.length; p<end; p++) {
-var point = data.points[p];
-pjs.addPoint(point.x, point.y); 
-}
-}
-}         
-</script>
-</head>
-<body>
-<canvas id="mysketch5" data-processing-sources="mysketch5.pde"/></canvas>
-<div id="controller"><button id="loadPoints" onclick="loadPoints('mysketch5')"/></div>
-</body>
-</html>
- -
load points:
-
- -

The JSON that gets loaded in the example sketch in this section is the following:

- -
	{ 'points' : [ {'x': 10 , 'y': 10} , {'x': 190 , 'y': 10} , {'x': 190 , 'y': 190} , {'x': 10, 'y': 190} ] }
- - - -

XML

- - -

Another favourite is the XML document. This is where the Processing data type "XMLElement" comes into play. Rather than trying to use javascript to parse the XML, we pass the xml data straight on to our sketch, which will know exactly what to do with it:

- - - -
load points:
- - -
-
-function loadPoints(id, button) {
-button.disabled = "disabled";
-var pjs = Processing.getInstanceById(id);
-var xml = $.get("http://thatfunkysite.com/serving/getxml.php");
-pjs.buildFromXML(xml); 
-}
-
- -

And the handling in our sketch will look like this:

- -
-
-void buildFromXML(String xml) {
-XMLElement data = new XMLElement(xml);
-XMLElement[] xmlpoints = data.getChildren();
-for(int p=0, end=xmlpoints.length; p<end; p++) {
-XMLElement xmlpoint = xmlpoints[p];
-int x = xmlpoint.getIntAttribute("x");
-int y = xmlpoint.getIntAttribute("y");   
-points.add(new Point(x, y)); 
-}
-redraw(); 
-}
-
- -

If the xml thus loaded looks like the following snippet, the sketch will behave in the way the sketch below does:

- -
-
-<xml>
-<point x='10' y='10'/>
-<point x='190' y='50'/>
-<point x='10' y='90'/>
-<point x='190' y='140'/>
-<point x='10' y='190'/>
-</xml>
-
- - - -

SVG

- -

A special kind of XML document is the SVG Scalable Vector Graphics document. What's special about it is that it already represents visual data, and Processing can load SVG XML natively.

- - - - - -
drawing with SVG
-
- -
-
	
-XMLElement svgxml;
-PShape ps;
-int x=0;
-int y=0;
-int xoffset=0;
-int yoffset=0;
-int xmark=0;
-int ymark=0;
-void setup() {
-size(200,200);
-noLoop(); 
-}	
-void draw() {
-background(255);
-stroke(0);
-for(int px=0; px<width; px+=10) { line(px,0,0,px); }
-for(int py=0; py<height; py+=10) { line(width,py,0,py+height); }
-stroke(#000066);
-for(int py=0; py<height;py+=10) { line(0,py,width,py); }
-if(ps!=null) { shape(ps,x-xoffset,y-yoffset,200,200); }
-}
-void mousePressed() {
-xmark = mouseX;
-ymark = mouseY; 
-}
-void mouseDragged() {
-xoffset = xmark-mouseX;
-yoffset = ymark-mouseY; 
-redraw(); 
-}
-void mouseReleased() {
-if(xoffset!=0 || yoffset!=0) {
-x -= xoffset;
-y -= yoffset;
-xoffset=0;
-yoffset=0; 
-}
-else {
-XMLElement path = svgxml.getChild(0);
-path.setAttribute("fill",getNextColor());
-bindSVG(svgxml); 
-}
-}	
-String[] colors = {"#f0f8ff","#faebd7","#00ffff","...", ..., ... };
-int color_len = colors.length; 
-int current_color = 0;	
-String getNextColor() {
-current_color = (current_color+1)%color_len;
-return colors[current_color]; 
-}	
-void buildFromSVG(String svg) {
-svgxml = new XMLElement(svg);
-bindSVG(svgxml); 
-}	
-void bindSVG(XMLElement svg) {
-ps = new PShapeSVG(svgxml);
-redraw(); 
-}
-
- -

This sketch will load the following SVG code, and allows you to click on the shape to change its color, or click-drag it to move it around:

- -
-
-<svg width='200' height='200'>
-
-<path d='M 10 10 L 190 10 L 140 100 L 190 190 L 10 190 L 50 100 L 10 10 M 100 80 L 140 30 L 50 30 L 100 80 M 100 120 L 50 170 L 140 170 Z'/>
-</svg>
-
- - -

Javascript Objects

-

One last thing you may want to pass to a sketch is a real javascript object. Say we have a physics library that we want to take advantage of in our -sketch, and for Processing it's a .jar file, but there's a javascript version too. This thing lets us create a javascript "Physics" object that we can -call functions on for computing momentum and force transfer when we make two things hit each other. Since processing.js does not support .jar libraries -(because it's precompiled binary java class code, and pjs cannot unpack a jar file, reverse engineer the .java source, transform it to Processing API -calls, then confirm all calls are supported) we'll use this convenient javascript library. But how to do this cleanly?

-

We have to do three things:

-
    -
  1. Write an interface for the object we're using, so our sketch will know what it even is,
  2. -
  3. use a javascript binding so that we can ask javascript to make these objects for us, and
  4. -
  5. write a javascript function to make these objects for us.
  6. -
-

So let's get cracking! First we determine which functions in the javascript Physics object we actually make use of. We could write an interface that -has correct method signatures for every function in the library, but this would be overkill. After reviewing our code we see that we actually only -make use of three of the objects functions: collide_objects(forcevector1, forcevector2, collisionangle), get_force_vector(startpoint, distancevector, -accelleration) and get_trajectory(startpoint, objectmass, initialvector, gravityvector, gravitystrength). Let's build our interface:

-
-
	
-interface Physics
-{
-// collision modifies the two force vectors in place. Nothing is returned.
-void collide_objects(float[] forcevector1, float[] forcevector2, float collisionangle);
-
-// get force vector returns a force vector
-float[] get_force_vector(float[] startpoint, float[] distancevector, float accelleration);
-
-// trajectory calculation returns a curve, represented as a lest of 2D coordinates
-float[][] get_trajectory(float[] startpoint, float objectmass, float[] initialvector, float[] gravityvector, float gravitystrength);
-}
-
-
-

First job done. Now to bind javascript. We've already looked at how to do this, so just follow the standard procedure and job's a good'n. -In addition to whatever javascript functions you want to expose, however, we must add one more:

-
-
	
-interface JavaScript {
-...
-Physics buildPhysicsObject([properly typed variables to match the javascript constructor]);
-...
-}
-
-
- -

Finally, we now make use of our purely javascript library in our js file(s):

-
-
	
-function buildPhysicsObject(x, y, someothervar)
-{
-return new Physics(x,y,someothervar);
-}
-
-
-

This last step seems silly, but we have to delegate the task of building a javascript object to javascript. If we tried to do this inside our sketch, -processing.js will not complain, but Processing will. To make matters worse, it also obscures the point of failure: if something goes wrong in the sketch, -did it go wrong because processing.js has a bug, or because you were sloppy with javascript inside a Processing sketch? Golden rule: keep the different -languages separated as much as possible.

-

We're almost set to use our javascript library for Processing purposes now. The only thing left is to create these objects and then use them in our sketch:

-
-
	
-class MassBody
-{
-// a class for bodies with mass that travel with some speed and are located at some x/y position
-float[] forceVector = new float[2]; // 2 dimensional vector;
-int XDIM = 0;  // index constant
-int YDIM = 1;  // index constant
-float x = 0;  // position
-float y = 0;  // position
-MassBody(float x, float y) { forceVector[XDIM] = 0; forceVector[YDIM] = 0; this.x=x; this.y=y; }
-void draw() { /* draws the body */ }
-float[] getForce() { return forceVector; }
-void impartForce(float[] stimulus) { forceVector[XDIM] += stimulus[XDIM]; forceVector[YDIM] += stimulus[YDIM]; }
-void updatePosition() { x+=...; y+=...; }
-}
-
-MassBody body1 = new MassBody(...);
-MassBody body2 = new MassBody(...);
-
-Phsyics physicsObject
-
-void bindJavascript(JavaScript js) {
-javascript = js; 
-int x = 0;
-float y = 9;
-String[] somevalues = {"scalar", "vector", "tensor"};
-physicsObject = javascript.buildPhysicsObject(x,y,somevalues);
-}
-void setup()
-{
-...
-}     
-void draw()
-{
-// if the two bodies collide, compute the resultant forces
-if(body1.collides(body2))
-{
-// forces are recomputed in place
-float angle_12 = body1.getAngleTo(body2);
-physicsObject.collide_objects(body1.getForce(), body2.getForce(), angle_12);
-body1.updatePosition();
-body2.updatePosition();
-}
-body1.draw();
-body2.draw();
-}
-
-
-

And we're done!

- - -

Processing.js as javascript graphics library

-

As last point of business, you can of course also use Processing.js as a pure graphics library, by invoking it for some canvas and then calling -Processing API calls directly. Let's jump right in! The following code is what you would write on-page, although of course as ever it's far better -practice to link to your source files, so you should really place what's in the script tags in a file myPjsSketch.js and link to it using src="..." -instead.

-

The following code is split up into multiple (numbered) sections.

-
    -
  1.   -
    -
    	
    -<canvas id="glibcanvas"></canvas>
    -<script type="text/javascript">
    -(function(){
    -var canvas = document.getElementById('glibcanvas');
    -var pjs = new Processing(canvas, function(p) {});
    -
    -
    -
  2. -

    This binds a new Processing instance to the indicated canvas. The function(p) {} -bit is actually completely unimportant, but must be used until ticket -# 1111 lands in Processing.js 1.2 (March 2011). Once 1.2 is out, the binding will simply be var pjs = new Processing(canvas).

    -
  3.   -
    -
    -// let's write a sketch
    -var value=0;
    -// Definition for the initial entry point
    -pjs.setup = function() {
    -pjs.size(200,200);
    -// we want to turn off animation, because this is a demo page and it
    -// would use cpu while not being looked at. Only draw on mousemoves
    -pjs.noLoop(); 
    -}
    -
    -
    -
  4. -

    This setup() function defines the entry point for our sketch. It sizes the canvas, and tells it not to animate by default.

    -
  5.   -
    -
    -// Draw a "sine wave" using two bezier curves, with an undulating amplitude.
    -pjs.draw = function() {
    -// partially clear, by overlaying a semi-transparent rect
    -// with background color
    -pjs.noStroke();
    -pjs.fill(255,75);
    -pjs.rect(0,0,200,200);
    -// draw the "sine wave"
    -pjs.stroke(100,100,200);
    -pjs.noFill();
    -pjs.bezier(0,100, 33,100+value, 66,100+value, 100,100);
    -pjs.bezier(100,100, 133,100+-value, 166,100+-value, 200,100);
    -}
    -
    -
  6. -

    The draw() function defines the main draw function, which is called whenever a frame update is requested (either because the sketch is looping, or -because redraw() is called manually)

    -
  7.   -
    -
    -pjs.mouseMoved = function() { 
    -value = ( pjs.mouseY-100);
    -pjs.redraw(); 
    -}
    -
  8. -

    The mouseMoved() function is a Processing event handler that is triggered by the mouse moving around over the canvas. It is far more convenient to -use the built-in event handler than to write our own.

    -

    This is all we need in our sketch, so there's only one call left to make:

    -
  9.   -
    -
    -// Finally, calling setup() will kickstart the sketch
    -pjs.setup();
    -})();
    -</script>
    -
    -
    -
  10. -
- -

So let's see that in action - the code that we just ran through is supposed to draw a sinewave, -with an amplitude that depends on where the mouse is on the canvas. If all went well, it will look like this:

- - - - - -

More information

- -

This guide was brought to you by Mike "Pomax" Kamermans. -

For more information, you can visit the following websites, or visit us in the #processing IRC channel on irc.mozilla.org.

- -
diff --git a/articles/_posts/2011-12-02-RenderingModes.html b/articles/_posts/2011-12-02-RenderingModes.html deleted file mode 100644 index dbe547f..0000000 --- a/articles/_posts/2011-12-02-RenderingModes.html +++ /dev/null @@ -1,257 +0,0 @@ ---- -layout: default -desc: The different rendering modes available in Processing.js -title: Rendering Modes -permalink: /articles/RenderingModes.html ---- -

- Understanding Rendering Modes in Processing.js

-

- Introduction

-

- The Processing language enables complex 2D and 3D graphics programming without having - to understand the details of the underlying graphics system. It is designed to be - easily learned, yet allows one's skills to grow and evolve without ever feeling - limited.

-

- Processing can be used to work with both 2D and 3D graphics. It achieves this through - a number of different rendering engines, which affect how it works. For example, - one might choose to render a 2D sketch using the JAVA2D and P2D renderers or create - 3D sketches with the P3D and OPENGL renderers. There are also renderers for creating - PDFs. Processing allows developers to choose renderers based on tradeoffs of speed - and quality.

-

- A renderer is chosen through the use of Processing's - size() function. For example, to create a 2D sketch that is 200 by 200 pixels - in size: -

size(200, 200, P2D);
-

-

- The 2D Rendering Context

-

- Processing.js uses the HTML canvas element to provide 2D and WebGL rendering contexts. - The canvas 2D API is used to implement Processing's JAVA2D and P2D renderers (see - the canvas API for - details on canvas). You can create a 2D Processing.js sketch using any of the following: -

    -
  1. -
    size(200, 200, P2D);
    -
  2. -
  3. -
    size(200, 200, JAVA2D);
    -
  4. -
  5. -
    size(200, 200); // default is 2D
    -
    -
  6. -
-

-

- Here is a simple 2D Processing.js sketch: -
-
- -

-int i = 0; 
-void setup() {
-    size(200, 200); 
-    background(255);
-    smooth();
-    strokeWeight(15);
-    frameRate(24);
-} 
-void draw() {
-    stroke(random(50), random(255), random(255), 100);
-    line(i, 0, random(0, width), height);
-    if (i < width) {
-        i++;
-    } else {
-        i = 0; 
-    }
-}
-
-

-

- The WebGL (3D) Rendering Context

-

- Processing.js 3D renderers (P3D and OPENGL) are implemented using WebGL. The Web-based - Graphics Library (WebGL) is a canvas rendering context that provides a JavaScript - based 3D drawing API for the web (see - https://developer.mozilla.org/en/WebGL). WebGL is based on OpenGL ES 2.0, - a subset of OpenGL designed to be used in embedded devices. Many modern browsers - support WebGL, but not all. You can confirm that your browser and computer/operating - system support WebGL here. - You can download a WebGL enabled browser - here.

-

- Just as Processing relies on OpenGL for its 3D graphics (OPENGL renderer), Processing.js - uses OpenGL via WebGL, allowing Processing.js sketches to work just like their Processing - equivalent.

-

- In order to create a 3D OpenGL sketch in Processing, two things are necessary. First, - the OpenGL library must be imported. Second, the OpenGL rendered must be specified: -

-import processing.opengl.*
-...
-size(200, 200, OPENGL);
-
-

-

- Since Processing.js is actually JavaScript, it does not support importing Java-based - libraries. However, in order to enable sketches written in Processing to work in - Processing.js, the import line can be safely included—Processing.js will simply - ignore it. The following methods of creating a 3D Processing.js sketch are equivalent: -

    -
  1. -
    import processing.opengl.* ... size(200, 200, OPENGL);
    -
  2. -
  3. -
    size(200, 200, P3D);
    -
  4. -
-

-

- Here is a simple Processing.js 3D sketch:
-
- -

-size(200, 200, OPENGL);
-noStroke();
-background(50);
-lights();
-translate(width/2+30, height/2, 0);
-rotateX(-PI/6);
-rotateY(PI/3 + 210/float(height) * PI);
-box(45);
-translate(0, 0, -50);
-box(30);
-
-

-

-
- Here's another more complex one:
-
- -

-float ang = 0, ang2 = 0, ang3 = 0, ang4 = 0;
-float px = 0, py = 0, pz = 0;
-float flapSpeed = 0.2;
-void setup(){
-  size(200, 200, OPENGL);
-  frameRate(50);
-  noStroke();
-}
-void draw(){
-  background(0);
-  camera();
-  // Flight
-  px = sin(radians(ang3)) * 170;
-  py = cos(radians(ang3)) * 300;
-  pz = sin(radians(ang4)) * 500;
-  translate(width/2 + px, height/2 + py, -700+pz);
-  rotateX(sin(radians(ang2)) * 120);
-  rotateY(sin(radians(ang2)) * 50);
-  rotateZ(sin(radians(ang2)) * 65);
-  
-  // Body
-  fill(153);
-  box(20, 100, 20);
-  // Left wing
-  fill(204);
-  pushMatrix();
-  rotateY(sin(radians(ang)) * -20);
-  rect(-75, -50, 75, 100);
-  popMatrix();
-  // Right wing
-  pushMatrix();
-  rotateY(sin(radians(ang)) * 20);
-  rect(0, -50, 75, 100);
-  popMatrix();
-  // Wing flap
-  ang += flapSpeed;
-  if (ang > 3) {
-    flapSpeed *= -1;
-  } 
-  if (ang < -3) {
-    flapSpeed *= -1;
-  }
-  // Increment angles
-  ang2 += 0.01;
-  ang3 += 2.0;
-  ang4 += 0.75;
-}
-
-
-

-


- Once you have a 3D enabled browser installed you can try out some example 2D and - 3D sketches here. -

-

- Processing.js as a Simplified Web Drawing API

-

- Once a 3D sketch has been created, all of the normal Processing drawing operations - can be done. Most Processing functions have 2D and 3D versions (e.g., you provide - different arguments for points in 2D or 3D space). By learning the Processing syntax, - it's easy to create complex 2D and WebGL graphics without ever touching the underlying - graphics APIs. This is true of Processing and Java, and also of Processing.js and - canvas/WebGL. The Processing langauge provides a powerful and beginner friendly - on-ramp to canvas 2D and WebGL. Consult the - Processing.js Langauge Reference for specific details on how to use each - function.

-

- Using the Processing.js API in JavaScript

-

- In addition to running standard Processing sketches, Processing.js can also be used - in so-called API mode. This is the Processing language API which is accessbile to - JavaScript without any Processing code. The Processing.js API is available if you - download the complete Processing.js zip file instead of just the .js file from the - Downloads page (for example: processing.js-version.zip vs processing.min.js) (http://processingjs.org/download). - It is essentially the same as Processing.js, but without the code parser (i.e., - you can use the API either way, but the Processing.js API is a somewhat smaller - file). See - Writing JavaScript-only Processing.js Code for more details.

-

- Accessing the Raw Canvas Context - Advanced:

-

- It's also possible to work with the raw canvas context, both 2D and WebGL, from - Processing.js, JavaScript, or both. This is not a recommended method, since it will - make your Processing.js sketch harder to use in Processing; however, sometimes it's - useful to know how to control the canvas context from outside the sketch in JavaScript, - or to do something that Processing doesn't allow, which the canvas or WebGL APIs - do.

-

- All Processing.js sketches have an externals property, accessible from within the - Processing code as a global variable. This object is meant to allow for accessing - and sharing external but related data between the sketch code and the web page. - The externals object has a number of useful properties, including: -

-

-

- From JavaScript, these can be accessed via a Processing.js sketch's instance: -

-var p = Processing.instances[0];
-var context = p.externals.context;
-var p2 = Processing.getInstanceById('canvas-id');
-var p2Canvas = p2.externals.canvas;
-
-

-

- The same thing can be done from within Processing code, where the externals object - is available as a global variable: -

-// Processing.js allows you to mix JavaScript, so using var is fine here:
-var currentContext = externals.context;
-
-

-Once you have a reference to the context, you can use any valid canvas API call, -including raw WebGL functions if using a 3D sketch. diff --git a/articles/_posts/2011-12-03-p5QuickStart.html b/articles/_posts/2011-12-03-p5QuickStart.html deleted file mode 100644 index dd377bb..0000000 --- a/articles/_posts/2011-12-03-p5QuickStart.html +++ /dev/null @@ -1,466 +0,0 @@ ---- -layout: default -desc: A guide to Processing.js for Processing developers -title: Processing Quick Start -permalink: /articles/p5QuickStart.html ---- -
-

- Processing.js Quick Start - Processing Developer Edition

-

- Introduction

-

- This quick start guide is written from the standpoint of a Processing developer. - No HTML or JavaScript knowledge is assumed, and only basic Processing knowledge - is necessary.

-

- Index

-
    -
  1. For the Impatient
  2. -
  3. Why Processing.js? -
      -
    1. The Web: from Java to JavaScript
    2. -
    3. Processing.js uses Modern Web Standards
    4. -
    -
  4. -
  5. Writing a Processing.js Sketch
  6. -
  7. Obtaining Processing.js
  8. -
  9. Creating a Processing.js Web Page
  10. -
  11. Running your Processing.js Web Page
  12. -
  13. Things to Know as a Processing Developer using Processing.js -
      -
    1. Processing.js has no data directory
    2. -
    3. Processing.js implements Processing, but not all of Java
    4. -
    5. Processing.js only has two rendering modes
    6. -
    7. Division which is expected to produce an integer might need explicit casting
    8. -
    9. Processing.js has to cheat to simulate Processing's synchronous I/O
    10. -
    11. Processing.js requires more care with variable naming than Processing
    12. -
    13. Calling color() with out-of-range values produces unpredictable colors
    14. -
    -
  14. -
  15. It is possible to put Processing code directly in your web page
  16. -
  17. Whatever you can do with the web, you can do with Processing.js
  18. -
-

- For the Impatient

-

- If you're in a rush, here's what you need to know:

-
    -
  1. Processing.js is written in JavaScript, and uses HTML5's <canvas> element. - It converts your Processing code to JavaScript and runs it.
  2. -
  3. To use it, download Processing.js here: - downloads
  4. -
  5. Make your Processing *.pde files as you normally would, for example hello-web.pde
  6. -
  7. Create a web page that includes Processing.js as well as a <canvas> with info - about where to get your sketch file (you can specify multiple *.pde files, separating - them with spaces):
  8. -
-
-
-<script src="processing-1.0.0.min.js"></script>
-<canvas data-processing-sources="hello-web.pde"></canvas>
-
-
-

- Load your web page, and it will parse, translate, and run your sketch in the browser.

-

- Why Processing.js?

-

- The Web: from Java to JavaScript

-

- Processing is built using Java. It was created at much the same time that the web - was starting. At this time the choice of the Java language, and Java Runtime, as - implementation targets for Processing made a lot of sense. In the mid-1990s, Java - was poised to become the language of the web, with Applets and other Java technologies - being used broadly on the client-side. Even Netscape, who created the language which - would eventually become the lingua franca of the web with JavaScript, named their - language so as to align themselves with the growing hype around Java.

-

- In the end, Java became an important server side technology, receding from the client-side - and browser. Today, most web browsers still support Java Applets, by means of a - binary plugin. However, few web developers deploy Java-based web applications now, - due to long load and startup times and difficulties relying on Java (or compatible - Java versions) being installed. This trend is not isolated to Java, but is happening - to all browser plugins (e.g., Flash), which are becoming less popular as issues - of security, installation, deployment, etc. make them inconvenient or risky.

-

- Another reason that plugins like Java and Flash have fallen out of favour is that - recent advances in standard web technologies, specifically HTML5 and JavaScript, - have made it possible to do things that previously depended on native (i.e., faster, - compiled) code. Companies like Google, with GMail and Google Docs, or Scribd (see - Scribd-in-HTML5) - have shown that HTML, CSS, and JavaScript alone are enough to build fast, full featured - web applications.

-

- Processing.js uses Modern Web Standards

-

- Processing.js is built using JavaScript and HTML5. Processing.js is really two things: - a Processing-to-JavaScript translator; and an implementation of the Processing API - (e.g., functions like line(), stroke(), etc.) written in JavaScript instead of Java. - It might seem odd at first to imagine your Processing sketches running in a browser, - usually without modification. But this is exactly what Processing.js enables.

-

- Processing.js automatically converts your Processing code to JavaScript. This means - that you don't have to learn JavaScript in order to run your code in a browser. - You can, quite literally, write your code using the Processing IDE like you always - have, and follow the steps below to get it running on the web. There's nothing new - to learn, beyond getting a simple web page created.

-

- Under the hood, Processing.js uses the new HTML5 canvas element to create your sketch's - graphics. The canvas element is a new feature of the web, and is either implemented - or will be implemented by all major web browsers. All Processing drawing features - have been reimplemented in Processing.js to use canvas, so any browser that supports - canvas will also support Processing.js.

-

- Here's a sample of a Processing.js sketch running in the browser. If you can see - it working, your browser supports everything you need already, and you can move - on to instructions below.

- -

- Writing a Processing.js Sketch

-

- There's nothing you should do differently to write sketches for Processing.js: you - write your Processing.js code exactly like Processing. For most people, this will - mean using the Processing IDE, which has the nice benefit of letting you write, - run, and test your code all in once place. Remember, any valid Processing sketch - should also be a valid Processing.js sketch.

-

- If you want to experiment with web-based Processing.js code editors, you can also - try these:

- -

- Let's make a simple sketch that is 200 by 200 in size, sets the background to gray, - draws a small white circle, and prints a message to the debug console:

-
-
-void setup() {
-  size(200, 200);
-  background(100);
-  stroke(255);
-  ellipse(50, 50, 25, 25);
-  println("hello web!");
-}
-
-
-

- I'll assume below that you saved this to a file called hello-web.pde -

-

- Obtaining Processing.js

-

- Processing.js is a JavaScript library that is meant to be included in a web page. - You don't have to compile it, tell your web server about it, etc. It simply has - to be included in a web page, and the browser will do the rest.

-

- You can download Processing.js at the download - page. The library comes in a number of forms, for example:

- -

- The version numbers may be different as you read this, but note the file extensions. - Both end in .js, but one also has .min. The .min version is Processing.js in a minified - form, which means it will be smaller to download (minified JavaScript uses tricks - like removing whitespace and renaming long variable names to single letters). File - sizes, and download times, matter on the web in a way they don't with normal Processing - sketches.

-

- Creating a Processing.js Web Page

-

- It's easy to get overwhelmed with the amount there is to learn about modern web - technologies. But there's a secret: you can ignore 95% of it as you start, and add - more later as you have time and interest. Unlike compilers or programming languages, - web browsers are designed to accept almost any input you throw at them, whether - valid or not, whether complete or not. Here's your first Processing.js web page:

-
-
-<script src="processing-1.0.0.min.js"></script>
-<canvas data-processing-sources="hello-web.pde"></canvas>
-
-
-

- That's it! No <html> or <body> tags, no title, no CSS, just the processing.js - script, and a canvas. While there isn't much here, it's important to understand - what is. First, the script tag has a src attribute, which is the file to - load. This could be a full url or a relative path. In this case the browser is going - to look for a file named processing-1.0.0.min.js in the same directory as - your web page.

-

- The second thing in this web page is a <canvas> tag. Notice that it too has - an attribute, data-processing-sources. This is a list of filenames (or just - one filename if you only have 1 file) separated by spaces (filenames and URLs on - the web can't include spaces, so space is a safe choice for separating lists). In - this case, the browser is going to look for a file named hello-web.pde located - in the same directory as your page page.

-

- How does the browser know how to load a Processing *.pde file? Processing.js takes - care of this, and will download, parse (i.e., translate to JavaScript), then run - it automatically when the page is loaded.

-

- And that's it! Save this file to the same directory as hello-web.pde and - processing-1.0.0.min.js and call it hello-web.html.

-

- If you're the kind of person who doesn't like taking shortcuts, here's what a more - complete web page might look like:

-
-
-
-
-
-    Hello Web - Processing.js Test
-    <script src="processing-1.0.0.min.js"></script>
-
-
-    

- Processing.js Test

-

- This is my first Processing.js web-based sketch:

- <canvas data-processing-sources="hello-web.pde"></canvas> - - -
-
-

- Both ways work, and you shouldn't let yourself get burdened by HTML and other web - syntax until you feel you want to do other things with your web pages.

-

- Running your Processing.js Web Page

-

- In case it isn't obvious, you run your hello-web.pde sketch by loading your - hello-web.html web page in a compatible browser. Web browsers will provide - you a way to load a local file, usually using the File menu and then Open File.... - If you've saved the files above on a web server, you can use the remote URL instead.

-

- Things to Know as a Processing Developer using Processing.js

-

- While Processing.js is compatible with Processing, Java is not JavaScript, and canvas - has some differences from Java's graphics classes. Here are some tricks and tips - as you start working on more complex sketches in Processing.js.

-

- Processing.js has no data directory

-

- Processing uses the concept of a data directory, where images and other resources - are located. Processing.js does not include this. As a result, you should always - provide file pages (e.g., images) that are relative to your web page, which is the - norm on the web.

-

- Processing.js implements Processing, but not all of Java

-

- Processing.js is compatible with Processing, but is not, and will never be, fully - compatible with Java. If your sketch uses functions or classes not defined as part - of Processing, they are unlikely to work with Processing.js. Similarly, libraries - that are written for Processing, which are written in Java instead of Processing, - will most likely not work.

-

- Processing.js only has two rendering modes

-

- Processing has many rendering modes to choose from, depending on the desired quality - and speed for graphics (e.g., OPENGL, P3D, JAVA2D, etc.). Processing.js uses <canvas> - which provides either a 2D drawing context or a 3D context based on WebGL (a version - of OpenGL for the web). Therefore, whatever you choose, you will end-up with either - the 2D or 3D context.

-

- Division which is expected to produce an integer might need explicit casting

-

- There are a class of bugs that arise when converting Processing code to Processing.js - that involve integer vs. floating point division. What was straight-up integer division - in Processing code, when converted to Processing.js, can sometimes become problematic, - as numbers become doubles, and introduce a fractional part. The fix is to explicitly - cast any division to an integer that exhibits this behaviour:

-
-
-// before
-int g = mouseX / i;
-
-// after
-int g = (int)(mouseX / i);
-
-
-

- See - lighthouse bug

-

- Processing.js has to cheat to simulate Processing's synchronous I/O

-

- Processing uses a synchronous I/O model, which means that functions like loadImage() - take time to execute, and while they are running, nothing else happens: the program - waits until loadImage() is done before moving on to the next statement. This - means that you can count on the value returned by a function like loadImage() - being usable in the next line of code.

-

- Web browsers don't work like this. The web uses an asynchronous I/O model, which - means that functions which load external resources can't make the program wait until - they finish. In order to replicate Processing's load* functions, you have to use - a special Processing.js Directive.

-

- The Processing.js Directives are hints to the browser that are written in comments - rather than in the Processing code itself. Here's a typical Processing sketch that - loads an image synchronously and then draws it:

-
-
-PImage img;
-
-void setup() {
-  img = loadImage("picture.jpg");
-  image(img, 0, 0);
-}
-
-
-

- This code will not work in the browser with Processing.js, because the call to image() - will happen before the file picture.jpg has been downloaded. The fix is to - ask Processing.js to download the image before the sketch starts, and cache it--a - technique known as preloading. Here is the modified code:

-
-
-/* @pjs preload="picture.jpg"; */
-PImage img;
-
-void setup() {
-  img = loadImage("picture.jpg");
-  image(img, 0, 0);
-}
-
-
-

- Notice the extra comment line at the top of the code. The @pjs directive - is for Processing.js, and not the developer. Think of it as an extra line of code - that will be executed before the program begins.

-

- If you have multiple images to load, use a list like so:

-
-
-/* @pjs preload="picture.jpg,picture2.jpg,picture3.png"; */
-
-
-

- Processing.js requires more care with variable naming than Processing

-

- One of the powerful features of JavaScript is its dynamic, typeless nature. Where - typed languages like Java, and therefore Processing, can reuse names without fear - of ambiguity (e.g., method overloading), Processing.js cannot. Without getting into - the inner-workings of JavaScript, the best advice for Processing developers is to - not use function/class/etc. names from Processing as variable names. For example, - a variable named line might seem reasonable, but it will cause issues with - the similarly named line() function built-into Processing and Processing.js.

-

Calling color() with out-of-range values produces unpredictable colors

-

Also in the class of integer vs. floating point issues, color(number) and color(number, number) may not behave quite as expected. In native Processing, color(int) and color(float) behave differently in that the first is used for full color integers. Calling color(#FF0000) and color(16711680) are the same call, so they produce a red color. However, when using float values the color()/1 function treats the input as gray values, between 0 and the max indicated value (255, by default). Any value lower than 0 or higher than max is simply capped. Because of the integer vs. floating point issues with JavaScript, Processing.js does not perform any capping, and so even though the following code will show a black and a white line in Processing, it will show a yellow line, and an "invisible" line in Processing.js instead.

-
-void setup()
-{
-  size(100,100);
-  noLoop();
-}
-
-void draw()
-{
-  background(127);
-  stroke(-200.0);
-  line(0,25,width,25);
-  stroke(600.0);
-  line(0,75,width,75);
-}
-    
-

We recommend you always sanitize your inputs for color if you need colors to be "in range", and only use hex colors, using color(#RRGGBB), or rgb/rgba colors, using color(r,g,b) and color(r,g,b,a)

-

- It is possible to put Processing code directly in your web page

-

- Using the data-processing-sources attribute on the canvas, and having Processing.js - load an external file is the preferred and recommended way to include scripts in - a web page. However, it is also possible to write in-line Processing code.

-

- A few changes are necessary to make the example above work with inline Processing - code:

-
-
-<script src="processing-1.0.0.min.js"></script>
-<script type="application/javascript">
-/*
- * This code searches for all the <script type="application/processing" target="canvasid">
- * in your page and loads each script in the target canvas with the proper id.
- * It is useful to smooth the process of adding Processing code in your page and starting
- * the Processing.js engine.
- */
-
-if (window.addEventListener) {
-  window.addEventListener("load", function() {
-    var scripts = document.getElementsByTagName("script");
-    var canvasArray = Array.prototype.slice.call(document.getElementsByTagName("canvas"));
-    var canvas;
-    for (var i = 0, j = 0; i < scripts.length; i++) {
-      if (scripts[i].type == "application/processing") {
-        var src = scripts[i].getAttribute("target");
-        if (src && src.indexOf("#") > -1) {
-          canvas = document.getElementById(src.substr(src.indexOf("#") + 1));
-          if (canvas) {
-            new Processing(canvas, scripts[i].text);
-            for (var k = 0; k< canvasArray.length; k++)
-            {
-              if (canvasArray[k] === canvas) {
-                // remove the canvas from the array so we dont override it in the else
-                canvasArray.splice(k,1);
-              }
-            }
-          }
-        } else {    
-          if (canvasArray.length >= j) {
-            new Processing(canvasArray[j], scripts[i].text);          
-          }
-          j++;
-        }       
-      }
-    }
-  }, false);
-}
-</script>
-<script type="application/processing" target="processing-canvas">
-void setup() {
-  size(200, 200);
-  background(100);
-  stroke(255);
-  ellipse(50, 50, 25, 25);
-  println('hello web!');
-}
-</script>
-<canvas id="processing-canvas"> </canvas>
-
-
-

- This code is more complex because it has to figure out which canvas goes with which - script (i.e., you can have multiple Processing sketches living in the same page, - and therefore, multiple canvases). Also note that the scripts include a type - attribute, which distinguishes between JavaScript and Processing code (the browser - will ignore Processing scripts). Finally, note the use of the id and target - attributes to connect the Processing script with the associated canvas.

-

- Portions of the code above are from the Processing.js project's init.js file, - see the - file on git. This file will likely be going away in the future, and happen - automatically as part of Processing.js initialization.

-

- Whatever you can do with the web, you can do with Processing.js

-

- Now that your sketch is working, and you have a basic web page, you'll probably - start getting ideas about how to make this look more beautiful, how to better integrate - your sketch with the surrounding web page or site, and how to mix data from various - web services and APIs. Is it possible to mix images on Flickr and a Processing.js - sketch? Yes. Is it possible to link Twitter to Processing.js? Yes. Anything the - web can do, your Processing.js sketch can do.

-

- This is an important idea, and is worth restating: Processing.js turned your once - Java-based code into JavaScript, and your graphics into <canvas>. As a result, - anything you read on the web about dynamic web programming, AJAX, other JavaScript - libraries or APIs, all of it applies to your sketch now. You aren't running code - in a box, cut-off from the rest of the web. Your code is a first-class member of - the web, even though you didn't write it that way.

-

- If you're feeling adventurous and want to go learn more about how to do other thing - with HTML, JavaScript, CSS, etc. remember that everything they say applies to you - and your sketches.

-
diff --git a/articles/_posts/2011-12-04-jsQuickStart.html b/articles/_posts/2011-12-04-jsQuickStart.html deleted file mode 100644 index b6afc7e..0000000 --- a/articles/_posts/2011-12-04-jsQuickStart.html +++ /dev/null @@ -1,539 +0,0 @@ ---- -layout: default -desc: A guide to Processing.js for JavaScript developers -title: JavaScript Quick Start -permalink: /articles/jsQuickStart.html ---- -
-

- Processing.js Quick Start - JavaScript Developer Edition

-

- Introduction

-

- This quick start guide is written from the standpoint of a JavaScript developer. - The document assumes you know JavaScript and web programming, but only very basic - Processing knowledge is assumed.

-

- Index

-
    -
  1. For the Impatient
  2. -
  3. Why Processing.js? -
      -
    1. What is Processing?
    2. -
    3. What does Processing bring to the web?
    4. -
    5. How much work is it to learn Processing?
    6. -
    -
  4. -
  5. Ways to use Processing.js -
      -
    1. Writing Pure Processing Code
    2. -
    3. Pre-compiling Processing code to JavaScript
    4. -
    5. Writing JavaScript-only Processing.js code
    6. -
    7. Writing Documents that Combine Processing and JavaScript Code -
        -
      1. Accessing JavaScript Objects from Processing
      2. -
      3. Mixing JavaScript and Processing
      4. -
      5. Accessing Processing from JavaScript
      6. -
      -
    8. -
    -
  6. -
  7. Things to Know as a JavaScript Developer using Processing.js -
      -
    1. Processing.js provides access to various DOM/JavaScript objects via the externals property
    2. -
    3. Division which is expected to produce an integer might need explicit casting
    4. -
    5. Processing.js has to cheat to simulate Processing's synchronous I/O
    6. -
    7. Processing.js requires more care with variable naming than Processing
    8. -
    9. It is possible to put Processing code directly in your web page
    10. -
    -
  8. -
-

- For the Impatient

-

- If you're in a rush, here's what you need to know:

-
    -
  1. Processing.js converts Processing code to JavaScript and runs it in the browser, - using <canvas> for a drawing surface.
  2. -
  3. To use it, download Processing.js here: - downloads
  4. -
  5. Make your Processing *.pde files as you normally would, for example hello-web.pde
  6. -
  7. Create a web page that includes Processing.js as well as a <canvas> with info - about where to get your sketch file (you can specify multiple *.pde files, separating - them with spaces):
  8. -
-
-
-<script src="processing-1.0.0.min.js"></script>
-<canvas data-processing-sources="hello-web.pde"></canvas>
-
-
-

- Load your web page, and it will parse, translate, and run your sketch in the browser.

-

- Why Processing.js?

-

- What is Processing?

-

- The Processing language was originally created at MIT as part of the Media lab and - Aesthetics and Computation group. They needed a way to bridge the gap between software - developers, artists, data visualizers, etc., and to do so in a way that allowed - new programmers (or non-programmers) to do complex visual work easily. Processing - was built using Java, and can be thought of as a simplified Java, with a simplified - Java API for drawing and graphics.

-

- What does Processing bring to the web?

-

- Processing has a large and vibrant community, who are good at creating 2D and 3D - graphics, visualizing data sets, audio, video, etc. With HTML5 the web gained canvas, - audio, and video--things which had previously only been available via plugins like - Flash or Java. At the same time, advances in JavaScript engines have made it possible - to do things in script that were previously too slow.

-

- By porting the Processing language to the web, both the Processing and web communities - benefit. For Processing, this means that code which used to only work on the desktop - now "just works" in the browser. For the web, this means that a new but mature and - full-featured approach to graphics programming becomes available. The <canvas> - element is too low-level for most developers to use directly--JavaScript libraries - are necessary. Processing.js can be thought of as just such a library, simplifying - the use of the 2D and 3D canvas operations.

-

- How much work is it to learn Processing?

-

- The Processing language was designed to be small but complete, and easy to learn. - This document does not attempt to teach you Processing, and you are encouraged to - seek out Processing specific tutorials, books, and examples. Any Processing code - or concepts should map to Processing.js (the exceptions are listed below). You can - also use pure JavaScript to work with the Processing drawing API, skipping the Java - syntax of Processing in favour of JavaScript.

-

- Ways to Use Processing.js

-

- Processing.js was originally created in order to allow existing Processing developers - and existing Processing code (often referred to as sketches) to work unmodified - on the web. As a result, the recommend way to use Processing.js is to write Processing - code, and have Processing.js convert it to JavaScript before running it.

-

- Over time, many web developers have begun using Processing.js, and asked that we - design a way for the API to be used separate from the Processing language itself. - Therefore, we have provided a way for JavaScript developers to write pure JavaScript - code and still use the Processing.js functions and objects. NOTE: Processing.js - is first and foremost a port of Processing to the open web, with design decisions - favouring compatibility with Processing. It was not designed as a general purpose - HTML drawing library. Having said that, it can be used as a high-level drawing API - for canvas.

-

- Below we discuss the various methods for using Processing.js in your web pages.

-

- Writing Pure Processing Code

-

- This is the preferred method for using Processing.js, and has been dealt with at - length in the Processing.js - for Processing Devs quick start guide. To summarize:

-
    -
  1. Download Processing.js from here
  2. -
  3. Create a separate Processing file or files, naming them whatever you want, as long as they have a - *.pde extension.
  4. -
  5. Create a web page that includes Processing.js as well as a <canvas> with info - about where to get your sketch file(s), and include Processing filenames as a space-separated - list in a data-processing-sources attribute on the canvas:
  6. -
-
-
-
-
-
-    Hello Web - Processing.js Test
-    
-
-
-    

- Processing.js Test

-

- This is my first Processing.js web-based sketch:

- <canvas data-processing-sources="hello-web.pde"></canvas> - - -
-
-

- Processing.js will automatically scan the document on page load for <canvas> - elements with data-processing-sources attributes, download the files using - XMLHTTPRequest, and feed them to the Processing-to-JavaScript translator. The resulting - JavaScript is run using eval.

-

- Pre-compiling Processing code to JavaScript

-

- Processing.js automatically downloads and converts any Processing code to JavaScript. - It does this using the Processing.compile() method, and those interested in building - tools or utilities for Processing.js can do the same.

-

- In order to obtain "compiled" code (i.e., JavaScript suitable for use by the Processing.js - runtime) from Processing code, do the following:

-
-
-// hard-coded Processing code, text from an HTML widget, downloaded text, etc.
-var processingCode = "..."; 
-var jsCode = Processing.compile(processingCode).sourceCode;
-
-
-

- For example, converting the following Processing code produces the "compiled" JavaScript - underneath:

-
-
-// Processing code
-void setup() {
-  size(200, 200);
-  background(100);
-  stroke(255);
-  ellipse(50, 50, 25, 25);
-  println("hello web!");
-}
-
-// "Comiled" JavaScript code
-// this code was autogenerated from PJS
-(function(processing, $constants) {
-    function setup() {
-        processing.size(200, 200);
-        processing.background(100);
-        processing.stroke(255);
-        processing.ellipse(50, 50, 25, 25);
-        processing.println("hello web!");
-    }
-    processing.setup = setup;
-})
-
-

- Writing JavaScript-only Processing.js code

-

- The previous method produced JavaScript code from Processing, but you can also write - JavaScript on its own. The Processing.js parser turns Processing code into a JavaScript - function, then runs it. As a result, it's possible to skip the Processing code altogether, - and simply write a JavaScript function, passing this to your Processing instance. - Here's an example:

-
-
-function sketchProc(processing) {
-  // Override draw function, by default it will be called 60 times per second
-  processing.draw = function() {
-    // determine center and max clock arm length
-    var centerX = processing.width / 2, centerY = processing.height / 2;
-    var maxArmLength = Math.min(centerX, centerY);
-
-    function drawArm(position, lengthScale, weight) {
-      processing.strokeWeight(weight);
-      processing.line(centerX, centerY,
-        centerX + Math.sin(position * 2 * Math.PI) * lengthScale * maxArmLength,
-        centerY - Math.cos(position * 2 * Math.PI) * lengthScale * maxArmLength);
-    }
-
-    // erase background
-    processing.background(224);
-
-    var now = new Date();
-
-    // Moving hours arm by small increments
-    var hoursPosition = (now.getHours() % 12 + now.getMinutes() / 60) / 12;
-    drawArm(hoursPosition, 0.5, 5);
-
-    // Moving minutes arm by small increments
-    var minutesPosition = (now.getMinutes() + now.getSeconds() / 60) / 60;
-    drawArm(minutesPosition, 0.80, 3);
-
-    // Moving hour arm by second increments
-    var secondsPosition = now.getSeconds() / 60;
-    drawArm(secondsPosition, 0.90, 1);
-  };
-}
-
-var canvas = document.getElementById("canvas1");
-// attaching the sketchProc function to the canvas
-var processingInstance = new Processing(canvas, sketchProc);
-
-
-

- Here a sketch function is created, similar to what the parser would produce. This - function should take 1 argument, a reference to a processing object (i.e., the Processing - runtime), which will be created by the Processing constructor. Any Processing functions - or objects are accessible as properties of this object.

-

- Once that function is complete, pass it, along with a reference to a canvas, to - the Processing constructor (remember to use new).

-

- Writing Documents that Combine Processing and JavaScript Code

-

- One of the first questions people ask with Processing.js is whether they can read - values from the document in which the Processing sketch is running, or vice versa. - The answer is yes.

-

- Processing.js converts Processing code into JavaScript contained in a function closure. - The variables and functions you create are not attached to the global object (i.e., - window). However, you can still get access to them.

-

- Accessing JavaScript Objects from Processing

-

- Since Processing code gets converted to JavaScript and run like any other function, - all Processing code has access to the global object. This means that if you create - a variable or function in a global script block, they are automatically accessible - to Processing. Consider this example:

-

- First the Processing file, mixing.pde:

-
-
-String processingString = "Hello from Processing!";
-
-void setup() {
-  printMessage(jsString + " " + processingString);
-}
-
-
-

- Next the web page:

-
-
-
-
-
-    Hello Web - Accessing JavaScript from Processing
-    
-
-
-    
-
- <canvas data-processing-sources="mixing.pde"></canvas> - - - -
-
-

- Here Processing.js allows the use of a variable and function declared outside the - Processing code.

-

- Mixing JavaScript and Processing

-

- The previous example kept a clean separation between the JavaScript and Processing - code, while loosening the boundary between the two. Because Processing.js converts - Processing code to JavaScript, it's also possible to mix them directly. The Processing.js - parser will leave JavaScript it finds within the Processing code unaltered, allowing - developers to write a hybrid of Processing and JavaScript (NOTE: this is why we - don't use a pure Processing parser approach in processing.js). Here is the previous - example rewritten using this method:

-
-
-var jsString = "Hello from JavaScript!";
-var printMessage = function(msg) {
-  document.getElementById('msg').innerHTML = "Message: " + msg;
-};
-
-String processingString = "Hello from Processing!";
-
-void setup() {
-  printMessage(jsString + " " + processingString);
-}
-
-

- There is some JavaScript syntax that can't be easily mixed this way (e.g., regex - literals). In those cases you can simply move your pure JavaScript to a <script> - block and access it using the method described above.

-

- Accessing Processing from JavaScript

-

- Reaching out from the Processing code to JavaScript is easier than going the other - way, since the JavaScript created by the Processing.js parser is not exposed directly - on the global object. Instead, you gain access using the Processing.instances property.

-

- The Processing constructor keeps track of instances it creates, and makes them available - using the getInstanceById() method. By default, when a <canvas> has a data-processing-sources - attribute, its id is used as a unique identifier for the Processing instance. If - no id attribute is provided, you can use Processing.instances[0].

-

- After you have a reference to the appropriate Processing instance, you can call - into it like so:

-
-
-<!DOCTYPE html>
-<html>
-<head>
-    <title>Hello Web - Controlling Processing from JavaScript</title>
-    <script src="processing-1.0.0.min.js"></script>
-
-
-    <canvas id="sketch" data-processing-sources="controlling.pde"></canvas>
-    
-    
-    
-
-
-
-
-

- Here two buttons in the DOM are used to allow the user to start or stop a running - Processing sketch. They control the Processing instance (you might have several - in a page, or hidden in divs) directly from JavaScript, calling Processing functions: - loop() and noLoop(). The Processing functions are well documented elsewhere.

-

- Things to Know as a JavaScript Developer using Processing.js

-

- While Processing.js tries to be fully compatible with Processing, there are some - things which are different or require workarounds. We have also added some web-specific - features to make Processing.js easier to use. Here are some tricks and tips as you - start working on more complex sketches in Processing.js.

-

- Processing.js provides access to various DOM/JavaScript objects via the externals - property

-

- Each Processing instance (i.e., Processing.instances) has an externals property, - which is an object containing references to various non-Processing DOM/JavaScript - objects that can be useful. For example:

- -

- Division which is expected to produce an integer might need explicit casting

-

- There are a class of bugs that arise when converting Processing code to Processing.js - that involve integer vs. floating point division. What was straight-up integer division - in Processing code, when converted to Processing.js, can sometimes become problematic, - as numbers become doubles, and introduce a fractional part. The fix is to explicitly - cast any division to an integer that exhibits this behaviour:

-
-
-// before
-int g = mouseX / i;
-
-// after
-int g = (int)(mouseX / i);
-
-
-

- See - lighthouse bug

-

- Processing.js has to cheat to simulate Processing's synchronous I/O

-

- Processing uses a synchronous I/O model, which means that functions like loadImage() - take time to execute, and while they are running, nothing else happens: the program - waits until loadImage() is done before moving on to the next statement. This - means that you can count on the value returned by a function like loadImage() - being usable in the next line of code.

-

- Web browsers don't work like this. The web uses an asynchronous I/O model, which - means that functions which load external resources can't make the program wait until - they finish. In order to replicate Processing's load* functions, you have to use - a special Processing.js Directive.

-

- The Processing.js Directives are hints to the browser that are written in comments - rather than in the Processing code itself. Here's a typical Processing sketch that - loads an image synchronously and then draws it:

-
-
-PImage img;
-
-void setup() {
-  img = loadImage("picture.jpg");
-  image(img, 0, 0);
-}
-
-
-

- This code will not work in the browser with Processing.js, because the call to image() - will happen before the file picture.jpg has been downloaded. The fix is to - ask Processing.js to download the image before the sketch starts, and cache it--a - technique known as preloading. Here is the modified code:

-
-
-/* @pjs preload="picture.jpg"; */
-PImage img;
-
-void setup() {
-  img = loadImage("picture.jpg");
-  image(img, 0, 0);
-}
-
-
-

- Notice the extra comment line at the top of the code. The @pjs directive - is for Processing.js, and not the developer. Think of it as an extra line of code - that will be executed before the program begins.

-

- If you have multiple images to load, use a list like so:

-
-
-/* @pjs preload="picture.jpg,picture2.jpg,picture3.png"; */
-
-
-

- Processing.js requires more care with variable naming than Processing

-

- One of the powerful features of JavaScript is its dynamic, typeless nature. Where - typed languages like Java, and therefore Processing, can reuse names without fear - of ambiguity (e.g., method overloading), Processing.js cannot. Without getting into - the inner-workings of JavaScript, the best advice for Processing developers is to - not use function/class/etc. names from Processing as variable names. For example, - a variable named line might seem reasonable, but it will cause issues with - the similarly named line() function built-into Processing and Processing.js.

-

- It is possible to put Processing code directly in your web page

-

- Using the data-processing-sources attribute on the canvas, and having Processing.js - load an external file is the preferred and recommended way to include scripts in - a web page. However, it is also possible to write in-line Processing code.

-

- A few changes are necessary to make the example above work with inline Processing - code:

-
-
-<script src="processing-1.3.0.min.js"></script>
-<script type="application/processing" data-processing-target="pjs">
-void setup() {
-  size(200, 200);
-  background(100);
-  stroke(255);
-  ellipse(50, 50, 25, 25);
-  println('hello web!');
-}
-</script>
-<canvas id="pjs"> </canvas>
-
-
-

- This code is more complex because it has to figure out which canvas goes with which - script (i.e., you can have multiple Processing sketches living in the same page, - and therefore, multiple canvases). Also note that the scripts include a type - attribute, which distinguishes between JavaScript and Processing code (the browser - will ignore Processing scripts). Finally, note the use of the id and target - attributes to connect the Processing script with the associated canvas.

-
diff --git a/articles/index.html b/articles/index.html deleted file mode 100644 index 323accf..0000000 --- a/articles/index.html +++ /dev/null @@ -1,12 +0,0 @@ ---- -layout: default ---- -

Articles

- -

-

-

diff --git a/blog/_posts/2010-02-03-processingjs-04-released.html b/blog/_posts/2010-02-03-processingjs-04-released.html deleted file mode 100644 index 3dabe83..0000000 --- a/blog/_posts/2010-02-03-processingjs-04-released.html +++ /dev/null @@ -1,92 +0,0 @@ ---- -layout: post -title: Processing.js v0.4.0 Released ---- -

Download Processing.js 0.4

- -

We are very pleased to announce the release of Processing.js 0.4!

- -

The students at Seneca and the community at large, have been working hard to get some -awesome code into the repository. Many smaller fixes and features have been added as well -as larger functions like blend modes. Another landmark in 0.4, are the small fragments of -OpenGL code that have begun to land. If you were not aware that Processing.js is getting -3D hardware support in the browser, you are now!

- -

The whole development process has taken a few releases to get right, but the community -has gathered great momentum in the last few months and the "right people" have joined the -group, helping Processing.js to run like the well oiled machine it should be. We are seeing -some amazing innovation and creativity from community members, such the experimental -HTML5 audio stream reading and writing in -Firefox from David Humprey and co.

- -

Development Process

- -The GitHub flow has also shifted to a more organized state with Anna Sobiepanek heading up .NEXT branch control prior to super-review and release candidacy. This allows us to keep the repository clean, so the main branch jeresig/processing-js will only get updated when a new release ships. The code will bubble up through controlled channels that have had rigorous tests and checks applied by the community, keeping the library parallel with it's big sister Processing, while maintaining a degree of difference that makes Processing.js suitable for the web context in which it is deployed. - -github-04 - -

Linting

- -

From 0.4 onwards, release code is being linted, beautified and packed before release -using some excellent script-fu from David Humprey and tested by fellow release controller -(and GitHub master) Corban Brook. -This way we will be confident that new releases do not break old functionality, code will -be lightweight, ready for deployment and be easier-on-the-eye for future developers.

- -

Get involved!

- -

If you would like to get involved with Processing.js development, or have general usage -questions about Processing.js, we would love meet you on IRC: -irc://irc.mozilla.org/processing.js

- -

Changelog:

- - diff --git a/blog/_posts/2010-02-17-processingjs-v050-released.html b/blog/_posts/2010-02-17-processingjs-v050-released.html deleted file mode 100644 index 7c1262e..0000000 --- a/blog/_posts/2010-02-17-processingjs-v050-released.html +++ /dev/null @@ -1,89 +0,0 @@ ---- -layout: post -title: Processing.js v0.5.0 Released ---- -

Download Processing.js 0.5

- -

We are very pleased to announce the release of Processing.js 0.5!

- -

The students at Seneca and the community at large, have been working hard to get some -awesome code into the repository. Many smaller fixes and features have been added. However, -the most exiting addition is the implementation of camera functions and a more complete 3D -foundation that is now able to render and rotate a box.

- -

Linting

- -

From 0.4 onwards, release code is being linted, beautified and packed before release -using some excellent script-fu from David Humprey and tested by fellow release controller -(and GitHub master) Corban Brook. -This way we will be confident that new releases do not break old functionality, code will -be lightweight, ready for deployment and be easier-on-the-eye for future developers.

- -

Get involved!

- -

If you would like to get involved with Processing.js development, or have general usage -questions about Processing.js, we would love meet you on IRC: -irc://irc.mozilla.org/processing.js

- -

Changelog:

- - diff --git a/blog/_posts/2010-02-26-processingjs-v060-released.html b/blog/_posts/2010-02-26-processingjs-v060-released.html deleted file mode 100644 index 9a90723..0000000 --- a/blog/_posts/2010-02-26-processingjs-v060-released.html +++ /dev/null @@ -1,56 +0,0 @@ ---- -layout: post -title: Processing.js v0.6.0 Released ---- -

Download Processing.js 0.6

- -

We are very pleased to announce the release of Processing.js 0.6!

- -

The students at Seneca and the community at large, have been working hard to get some -awesome code into the repository. Many smaller fixes and features have been added. However, -the most exiting addition is the implementation of 3D functions like sphere, line, fill and -stroke. Also, we have set up OpenGrok to enable easy searching of the Java Processing.

- -

Get involved!

- -

If you would like to get involved with Processing.js development, or have general usage -questions about Processing.js, we would love meet you on IRC: -irc://irc.mozilla.org/processing.js

- -

Changelog

- - diff --git a/blog/_posts/2010-03-24-processingjs-v070-released.html b/blog/_posts/2010-03-24-processingjs-v070-released.html deleted file mode 100644 index db979ef..0000000 --- a/blog/_posts/2010-03-24-processingjs-v070-released.html +++ /dev/null @@ -1,73 +0,0 @@ ---- -layout: post -title: Processing.js v0.7.0 Released ---- -

Download Processing.js 0.7

- -

We are very pleased to announce the release of Processing.js 0.7!

- -

The students at Seneca and the community at large, have been working hard to get some -awesome code into the repository. Many smaller fixes and features have been added. Some -exiting addition to the implementation include PImage with asynchronous image loading, -reference (ref) tests, and lighting.

- -

Get involved!

- -

If you would like to get involved with Processing.js development, or have general usage -questions about Processing.js, we would love meet you on IRC: -irc://irc.mozilla.org/processing.js

- -

Changelog

- - diff --git a/blog/_posts/2010-03-26-processingjs-v071-released.html b/blog/_posts/2010-03-26-processingjs-v071-released.html deleted file mode 100644 index 62c8cb1..0000000 --- a/blog/_posts/2010-03-26-processingjs-v071-released.html +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: post -title: Processing.js v0.7.1 Released ---- -

Download Processing.js 0.7

- -

We are very pleased to announce the release of Processing.js 0.7.1!

- -

The students at Seneca and the community at large, have been working hard to get some -awesome code into the repository. After the release of 0.7 we realized that our implementation -of mouse wheel support actually broke the whole script in Chrome/Safari. We ask that anyone -that downloaded the 0.7 release upgrade to 0.7.1 as soon as possible.

- -

Get involved!

- -

If you would like to get involved with Processing.js development, or have general usage -questions about Processing.js, we would love meet you on IRC: -irc://irc.mozilla.org/processing.js

- -

Changelog

- - diff --git a/blog/_posts/2010-04-09-processingjs-v08-released.html b/blog/_posts/2010-04-09-processingjs-v08-released.html deleted file mode 100644 index 8bff86f..0000000 --- a/blog/_posts/2010-04-09-processingjs-v08-released.html +++ /dev/null @@ -1,71 +0,0 @@ ---- -layout: post -title: Processing.js v0.8 Released ---- -

Download Processing.js 0.8

- -

We are very pleased to announce the release of Processing.js 0.8!

- -

The students at Seneca and the community at large, have been working hard to get some -awesome code into the repository. We are proud to announce a full rewrite of p.color which -greatly increases performance. Also included in this release are lightning functions like -spotlight(), ambientLight(), and pointLight(), as well as material properties like -shininess(), and emissive().

- -

Get involved!

- -

If you would like to get involved with Processing.js development, or have general usage -questions about Processing.js, we would love meet you on IRC: -irc://irc.mozilla.org/processing.js

- -

Changelog

- - diff --git a/blog/_posts/2010-05-11-processingjs-v09-released.html b/blog/_posts/2010-05-11-processingjs-v09-released.html deleted file mode 100644 index aab01ae..0000000 --- a/blog/_posts/2010-05-11-processingjs-v09-released.html +++ /dev/null @@ -1,100 +0,0 @@ ---- -layout: post -title: Processing.js v0.9 Released ---- -

Download Processing.js 0.9

- -

We are very pleased to announce the release of Processing.js 0.9!

- -

The new 0.9 release is now available on the GitHub repository. We are proud to announce -new 3D functionality such as quad, triangle, and vertex. Also included in this release is -multiple file support and an optimized version on PImage.

- -

Get involved!

- -

If you would like to get involved with Processing.js development, or have general usage -questions about Processing.js, we would love meet you on IRC: -irc://irc.mozilla.org/processing.js You -can also get involved by helping with the testing or documentation phase.

- -

Changelog

- - diff --git a/blog/_posts/2010-05-20-processingjs-v091-released.html b/blog/_posts/2010-05-20-processingjs-v091-released.html deleted file mode 100644 index 5688ab3..0000000 --- a/blog/_posts/2010-05-20-processingjs-v091-released.html +++ /dev/null @@ -1,29 +0,0 @@ ---- -layout: post -title: Processing.js v0.9.1 Released ---- - -

Download Processing.js 0.9.1

- -

We are very pleased to announce the release of Processing.js 0.9.1!

- -

The new 0.9.1 release is now available for download -on the GitHub repository. This release is an architectural refactoring of the library to remove a legacy -performance issue. This rewrite will allow modern JavaScript engines to better optimize the libraries code -at runtime. For example, taking advantage of tracing in Firefox's SpiderMonkey engine. Of course, this -release would not be possible without -Scott.

- -

Get involved!

- -

If you would like to get involved with Processing.js development, or have general usage questions about -Processing.js, we would love meet you on IRC: -irc://irc.mozilla.org/processing.js You can also get -involved by helping with the testing or documentation phase. We are desperately seeking help with -documentation.

- -

Changelog

- - diff --git a/blog/_posts/2010-06-16-processingjs-v094-released.html b/blog/_posts/2010-06-16-processingjs-v094-released.html deleted file mode 100644 index 3a4b410..0000000 --- a/blog/_posts/2010-06-16-processingjs-v094-released.html +++ /dev/null @@ -1,86 +0,0 @@ ---- -layout: post -title: Processing.js v0.9.4 Released ---- -

Download Processing.js 0.9.4

- -

We are very pleased to announce the release of Processing.js 0.9.4!

- -

The new 0.9.4 release is now available for download -on the GitHub repository. This release features a brand new lightweight parser that improves flexibility. -But thats not all. We have added a lot of 3D features and are NOW supporting textures.  Check out the newly -added crisp @pjs directive for crisp lines and points.  Of course performance is always on the top of our -list, we are proud to say that processing.js is now faster than ever!

- -

Get involved!

- -

If you would like to get involved with Processing.js development, or have general usage questions about -Processing.js, we would love meet you on IRC: -irc://irc.mozilla.org/processing.js You can also get -involved by helping with the testing or documentation phase.

- -

We are desperately seeking help with documentation.

- -

Changelog

- - diff --git a/blog/_posts/2010-07-26-processingjs-v096-released.html b/blog/_posts/2010-07-26-processingjs-v096-released.html deleted file mode 100644 index 825c547..0000000 --- a/blog/_posts/2010-07-26-processingjs-v096-released.html +++ /dev/null @@ -1,66 +0,0 @@ ---- -layout: post -title: Processing.js v0.9.6 Released ---- -

Download Processing.js 0.9.6

- -

We are very pleased to announce the release of Processing.js 0.9.6!

- -

The new 0.9.6 release is now available for -download on the GitHub repository. -This release encompasses an early implementation of loading and displaying SVG (Scalable -Vector Graphics) shapes. It also includes additional 3D features such as hint() and -background transparency. For the optimization enthusiasts, we optimized our code by -removing recursion and removing temporary variables where possible.

- -

Get involved!

- -

If you would like to get involved with Processing.js development, or have general usage -questions about Processing.js, we would love meet you on IRC: -irc://irc.mozilla.org/processing.js You -can also get involved by helping with the testing or documentation phase. We are -desperately seeking help with documentation.

- -

Changelog

- - diff --git a/blog/_posts/2010-08-16-processingjs-v097-released.html b/blog/_posts/2010-08-16-processingjs-v097-released.html deleted file mode 100644 index 47d2bed..0000000 --- a/blog/_posts/2010-08-16-processingjs-v097-released.html +++ /dev/null @@ -1,66 +0,0 @@ ---- -layout: post -title: Processing.js v0.9.7 Released ---- -

Download Processing.js 0.9.7

- -

We are very pleased to announce the release of Processing.js 0.9.7!

- -

The new 0.9.7 release is now available for -download on the GitHub repository. -Release features include 3D implementation of PImage, updated SVG support, improved -PGraphics, and added functionality such as textDescent. For IE9 users we are proud to -finally offer you a processing-js version that will run in your browser (IE 9 preview 4). -Also, for those of you that like native JavaScript we have added the ability to run -processing-js sketches using straight JavaScript. Look at examples/js for a demonstration.

- -

Get involved!

- -

If you would like to get involved with Processing.js development, or have general usage -questions about Processing.js, we would love meet you on IRC: -irc://irc.mozilla.org/processing.js You -can also get involved by helping with the testing or documentation phase. We are -desperately seeking help with documentation.

- -

Changelog

- - diff --git a/blog/_posts/2010-11-18-processingjs-v10-released.html b/blog/_posts/2010-11-18-processingjs-v10-released.html deleted file mode 100644 index 1cbdf16..0000000 --- a/blog/_posts/2010-11-18-processingjs-v10-released.html +++ /dev/null @@ -1,73 +0,0 @@ ---- -layout: post -title: Processing.js v1.0 Released ---- -

This is the one you've been waiting for. The Processing.js team is pleased to announce -the release of Processing.js -version 1.0.  Since its original release by John Resig in 2008, over 1,000 bug fixes, -features, and under-the-hood improvements were made.  The goal of Processing.js is parity -with Processing, ease of use in the web environment, wide compatibility with modern web -browsers, and great performance.  Processing.js is now feature complete with Processing, -with a very few exceptions (see the Reference -page for details).

- -

This release represents years of work by a very dedicated developer and user community. -With Processing.js we hope to expand the reach of Processing on the web, and bring a new -generation of developers to this wonderful language.  The open web will be a much easier -place to do graphical programming, starting today.

- -We're proud of Processing.js and hope you'll enjoy using it as much as we do! - -

Download the code here -and get started learning -how to use Processing.js.

- -

ChangeLog

- - diff --git a/blog/_posts/2011-03-01-processingjs-v11-released.html b/blog/_posts/2011-03-01-processingjs-v11-released.html deleted file mode 100644 index c0bccde..0000000 --- a/blog/_posts/2011-03-01-processingjs-v11-released.html +++ /dev/null @@ -1,78 +0,0 @@ ---- -layout: post -title: Processing.js v1.1 Released ---- -

Release 1.1 is now available -for download and contains a whole host of new features!

- -

Our mission this release was to focus on tightening up on as many bugs as possible but -also to add a large set of new features to the library. Some of the highlights of the new -features for this release are:

- - - -

More than 60 other bugs were fixed this release including 3D fixes and a ton of fixes -to our testing platforms making our bug detection process much more efficient.

- -

Our exhibition page has also been updated with some of the newest Processing.js works -on the web. If you have some work, and would like us to showcase it all you have to do is -get in touch with us. You -can do so via IRC, twitter (@annasob, or -@dhhodgin), or the -processingjs google group. -We accept all exhibit requests as long as they are your own work.

- -

Download the new release -and experience a faster, more powerful Processing experience today!

- -

Changelog

- - diff --git a/blog/_posts/2011-05-31-processingjs-v12-released.html b/blog/_posts/2011-05-31-processingjs-v12-released.html deleted file mode 100644 index b6e8c5f..0000000 --- a/blog/_posts/2011-05-31-processingjs-v12-released.html +++ /dev/null @@ -1,168 +0,0 @@ ---- -layout: post -title: Processing.js v1.2 Released ---- -

The Processing.js team is pleased to announce the -release of Processing.js version 1.2. This -is one of our largest releases to date, and focuses on performance, compatibility, 3D, and -bug fixes. More people than ever are using Processing.js, from professional design houses -to video game developers to fashion designers, and as the demand and uses continue to -grow, we are excited to be able to bring you an even better Processing.js.

- -

Since our last release, exciting things have been happening in browser development. -WebGL, the 3D extension of the HTML5 canvas element, has now shipped in Firefox and Chrome, -and is being tested in nightly builds of Safari and Opera. Processing.js has been fully -WebGL compatible for more than a year, and version 1.2 includes some great 3D performance -and bug fixes. We've also -written a guide to -help explain how Processing.js uses canvas and WebGL to support the various Processing -render modes. Processing.js is a great way to get started with 2D and 3D graphics on the -web, without having to understand all of the underlying technologies. With several guides for -people new to Processing, -JavaScript developers -and Processing developers, -there has never been a better time to jump in!

- -

This release also includes some important changes to ensure better compatibility with -Processing 1.5. First, we've altered our default frame rate to match Processing's (i.e., -60 fps). Developers who are upgrading from previous versions of Processing.js, and who -don't explicitly set a frame rate, may notice that sketches seem to run more slowly. Don't -worry, Processing.js is faster than ever! Your sketch is just drawing at 60fps. It's -possible to make things as fast as the browsers will allow by setting a higher frame rate, -but this will of course consume more CPU, and actually -not -provide any real gain other than bigger deltas between visible frames.

- -

We had many requests from our users to follow Processing's lead and add support for Java -Generics, and we're happy to report that as of Processing 1.2 this is fully supported! -We've also improved our compatibility in key classes and functions like ArrayList and -XMLElement, and arc() and beginShape(), etc. If you find that your Processing code isn't -compatible with Processing.js, please make sure you tell us.

- -

While we've been developing 1.2, we've seen some great examples of Processing.js in the -wild. Here are some of our favorites:

- - - -

One of the things we love most is seeing all the creative and unexpected ways that -people use Processing.js. If you have a cool example, let us know about it, and we might -showcase it on the site and in our blog posts.

- -

Finally, we want to take this release as an opportunity to acknowledge one of our team -members who will be leaving us. Anna Sobiepanek -has been a full-time developer and researcher at -Seneca's Centre for -Development of Open Technology (CDOT) for more than a year. She's helped develop and -lead the Processing.js project, and been our main git master -(Anna's github graph is often -used as an example of a complex git project). Anna's been a passionate contributor and -great leader in the Processing.js project, and we'll miss her daily work with us. Lots of -people bemoan the lack of women in open source, and we've been blessed to have such a great -developer and amazing woman working on our team. We wish her well in her new job, and look -forward to her continued contributions as a volunteer.

- -

We hope you enjoy using Processing.js 1.2. We enjoyed making it for you, and are already -working on 1.3!

- -

Changelog

- - diff --git a/blog/_posts/2011-06-02-processingjs-v121-released.html b/blog/_posts/2011-06-02-processingjs-v121-released.html deleted file mode 100644 index 6361761..0000000 --- a/blog/_posts/2011-06-02-processingjs-v121-released.html +++ /dev/null @@ -1,22 +0,0 @@ ---- -layout: post -title: Processing.js v1.2.1 Released ---- -

Hot on the heels of 1.2.0 we're releasing a maintenance -release 1.2.1 to address a regression identified by Florian Jenett, relating to the -use of background() with 3 arguments. An associated issue broke the @pjs "transparent" -directive, and we fixed both issues in this maintenance release. We also took the -opportunity to update the gzipped version of processing.js in the release archive, which -was accidentally posted as a 0-byte file. This release is brought to you thanks to -Florian's quick post on our bug tracker, so: if you find issues with Processing.js, don't -hesitate to file a bug with us at -https://processing-js.lighthouseapp.com -- we hate them just as much as you do.

- -

Changelog

- -