Processing.js: Difference between revisions
Andy Dingley (talk | contribs) m wls. |
No edit summary |
||
Line 14: | Line 14: | ||
|data3 = [[MIT License|MIT]] |
|data3 = [[MIT License|MIT]] |
||
|label4 = Current Release |
|label4 = Current Release |
||
|data4 = 0. |
|data4 = 1.0.0 / November 18, 2010 |
||
|label5 = Website |
|label5 = Website |
||
|data5 = http://processingjs.org/ |
|data5 = http://processingjs.org/ |
Revision as of 22:13, 28 January 2011
Language | Javascript |
---|---|
Original Creator | John Resig |
License | MIT |
Current Release | 1.0.0 / November 18, 2010 |
Website | http://processingjs.org/ |
Processing.js is a JavaScript port of Processing, a programming language designed to write visualizations, images, and interactive content. It allows web browsers to display animations, visual applications, games and other graphical rich content without the need for a Java Applet or Flash plugin.
Processing.js uses JavaScript to render 2D and 3D content on the HTML canvas element, and is supported by browsers that have implemented this element (Currently the latest versions of Mozilla Firefox, Opera, Safari and Google Chrome).
Use
The Processing.js syntax is almost identical to that of the Processing language, a setup()
function is used to define general visualization properties like canvas size, frame rate and other variables, and the draw()
function controls the behavior of each frame in the animation.
The Processing.js library can be included in the head section of a web page as a single JavaScript file:
<html>
<head>
<script type="text/javascript" src="processing.js"></script>
</head>
A canvas
element is declared inside the body, with a data-processing-sources
attribute, specifying the location of an external file holding the Processing code:
<canvas data-processing-sources="example.pde"></canvas>
Any extension can be used in the external file, for example the .pde extension used by the Processing language sketch files.
/* example.pde */
// The statements in the setup() function
// execute once when the program begins
void setup()
{
size(200, 200); // Sets the canvas size to 200 by 200 pixels
stroke(255); // Set line drawing color to monochrome white
frameRate(30); // Set up draw() to be called 30 times per second
}
float y = 100;
// The statements in draw() are executed until the
// program is stopped. The function is called as many
// times per second as the frameRate. If no explicit
// rate is set, this is 45 times per second.
void draw()
{
background(0); // Set the background to monochrome black
y = y - 1;
if (y < 0) { y = height; }
line(0, y, width, y); // draw a horizontal line at height y
}