Jump to content

Processing.js: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m Processing syntax: lang="arduino"
Tag: Redirect target changed
 
(40 intermediate revisions by 25 users not shown)
Line 1: Line 1:
#REDIRECT [[Processing#Processing.js]]
{{Infobox software
| name = Processing.js
| logo = [[File:Processing Logo Clipped.svg|180px|Processing logo]]
| author = [[John Resig]]
| developer = Processing.js team
| released = {{Start date and age|2008}}
| latest release version = 1.4.8
| latest release date = {{Start date and age|2014|3|25}}
| latest preview version =
| latest preview date =
| programming language = [[JavaScript]]
| status = Active
| genre = [[Web application framework]]
| license = [[MIT License|MIT]]
| website = {{url|http://processingjs.org}}
| size = {{Nowrap|61 [[Kilobyte|KB]] (gzipped)}} / {{Nowrap|209 KB (production)}} / {{Nowrap|754 KB (development)}}
}}
'''Processing.js''' is a [[JavaScript]] port of [[Processing (programming language)|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]].


{{r from merge}}
Processing.js was originally created to allow existing Processing developers and existing code to work unmodified on web. 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 (the latest versions of Mozilla [[Firefox]], [[Opera (web browser)|Opera]], [[Internet Explorer]], [[Safari (web browser)|Safari]] and [[Google Chrome]]).
{{r to section}}

The development of Processing.js was begun by [[John Resig]] and then picked up by students at [[Seneca College]] after its initial release in 2008. A team of students finished the port of Processing.js, fixing more than 900 bugs, shipping 12 releases, and creating a vibrant community in the process. The project was done through a partnership between the [[Mozilla Foundation]] and [[Seneca College]], led by David Humphrey, Al MacDonald, and Corban Brook. The students continue to maintain the project today.

==Versions==
* 1.4.0<br>The first version of Processing.js released in July 2010.
* 1.4.1<br>This version resolved bugs present in prior version.The key events for focusing the mouse are handled with global <code>keyEvent</code> instructions which execute only when they receive focus. The versions are exclusively for development and production with API option.
* Latest Upcoming Version(2.1)<br>Processing.org will be launching a series of "alpha" releases as they prepare for 2.0. Alpha means unstable and that function names and APIs will continue to change (mostly in PShape, XML, and other new bits like JSON and Table). It might be a bit like driving a sports car but with the hood removed and one of the tires might occasionally blow out. There will be beta releases. After the alpha releases which restricts the APIs changing, but the bugs might still be around. You'll have a proper set of tires and a hood, but you might still need a coat of paint and a radio.

Changes made in latest release: (2.1)
* Libraries of OpenGL are built into core,no need of installing separate library.
* Modified version of GSVideo library is used instead of java.
* It allows one to choose two modes of platform for executing like [[Android (operating system)|Android]] or [[JavaScript]] by selecting from a drop down list in the main window.
* Movie Maker class has been removed in that place an item tool which converts frames into video is added.
* For reading XMl and loading separate loadXMl is added and getXXXAttribute is now changed to getXXX.
* Exception handling is made as choice for advanced users.
* A new Table class is added which made easy to deal with punctuation in spreadsheets like comma,delimiter.

==IDE==

The Processing.js code is designed to be used with standalone text editors, or it may be built into an [[integrated development environment]] (IDE).

Following are the IDEs which support Processing.js:
* Sketchpad puts processing on [[Etherpad]], allowing authors to simultaneously edit a text document, and see all of the participants' edits in real-time, with the ability to display each author's text in their own color.
* The Processing.js code can be edited in Processing helper tool.
* Even the code can be designed by using [[Eclipse (software)|Eclipse]] by importing packages using [[GitHub]].

==Uses==
Following are the uses of Processing.js:
* iProcessing

iProcessing was built to help people develop native [[iPhone]] applications using the Processing language. It is an integration of the Processing.js library and a Javascript application framework for iPhone.
* It leverages the full spark of open web and gives additional benefits to users of Processing
* It serves as a forcing function for [[JavaScript]] performance and provides visual graphical effects.

==Processing syntax==
Processing.js syntax is almost identical to that of the Processing language, in that a <code>setup()</code> function is used to define general visualization properties like canvas size, frame rate and other variables, and a <code>draw()</code> function controls the behavior of each frame in the animation.

The Processing.js library can be included in head section of a web page as a single JavaScript file:
<source lang="html4strict">
<html>
<head>
<script type="text/javascript" src="processing.js"></script>
</head>
</source>

A <code>canvas</code> element is declared inside the body, with a <code>data-processing-sources</code> attribute, specifying the location of an external file holding the Processing code:

<source lang="xml">
<canvas data-processing-sources="example.pde"></canvas>
</source>

Any extension can be used in the external file, for example, the .pde extension used by the Processing language sketch files.

<source lang="arduino">
/* 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
}
</source>

Processing language has two ways of rendering a 2D or 3D in order to understand underlying graphic. It uses [[Java (programming language)|Java]] for 2D, and [[OpenGL]] for 3D.
This code demonstrates the rendering .
The <code>size()</code> function provide choice to choose 2D or 3D. To create a 2D sketch that is 100 by 100 pixels.
<code>size(100, 100, P2D);</code><br>
To draw a 3D sketch OpenGL is used:
<code>size(100, 100, OPENGL);</code>

==Challenges==

* calling <code>color()</code> function with out of range values produces unpredictable results
* It is recommended to use hexadecimal values for colors #FFFFFF
* overhead of handling dummy [[Method overriding]] for every method we use
* Variables declared in Processing.js require more care than Processing
* More chance of bugs when converting from Processing to Processing.js explicit typecasting is needed, otherwise it produces random results

The sample code below shows explicit casting of the integer datatype.
<syntaxhighlight lang="html4strict">
// before
int g = mouseX / j;

// after
int g = (int)(mouseX / j);
</syntaxhighlight>

==See also==
{{Portal|Free software}}
*[[D3.js]]
*[[JavaScript InfoVis Toolkit]]
*[[Protovis]]
*[[Processing (programming language)]]

==References==
{{Refbegin}}
*{{citation
| first1 = Andrew
| last1 = Glassner
| title = Processing for Visual Artists: How to Create Expressive Images and Interactive Art
| date = August 9, 2010
| edition = 1st
| publisher = A K Peters/CRC Press
| pages = 955
| isbn = 1-56881-716-9
| url = http://www.crcpress.com/ecommerce_product/product_detail.jsf?isbn=9781568817163
}}D
*{{citation
| first1 = Casey
| last1 = Reas
| first2 = Ben
| last2 = Fry
| title = Getting Started with Processing
| date = June 17, 2010
| edition = 1st
| publisher = Make
| pages = 208
| isbn = 1-4493-7980-X
| url =
}}
*{{citation
| first = Joshua
| last = Noble
| title = Programming Interactivity: A Designer's Guide to Processing, Arduino, and Openframeworks
| date = July 21, 2009
| edition = 1st
| publisher = [[O'Reilly Media]]
| pages = 736
| isbn = 0-596-15414-3
| url = http://oreilly.com/catalog/9780596154141/
}}
*{{citation
| first = Kostas
| last = Terzidis
| title = Algorithms for Visual Design Using the Processing Language
| date = May 11, 2009
| edition = 1st
| publisher = [[John Wiley & Sons|Wiley]]
| pages = 384
| isbn = 0-470-37548-5
| url = http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470375485.html
}}
*{{citation
| first1 = Casey
| last1 = Reas
| first2 = Ben
| last2 = Fry
| first3 = John
| last3 = Maeda
| title = Processing: A Programming Handbook for Visual Designers and Artists
| date = September 30, 2007
| edition = 1st
| publisher = The MIT Press
| pages = 736
| isbn = 0-262-18262-9
| url = http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=11251
}}
*{{citation
| first = Ben
| last = Fry
| title = Visualizing Data
| date = January 11, 2008
| edition = 1st
| publisher = [[O'Reilly Media]]
| pages = 382
| isbn = 0-596-51455-7
| url = http://oreilly.com/catalog/9780596514556/
}}
*{{citation
| first = Ira
| last = Greenberg
| title = Processing: Creative Coding and Computational Art (Foundation)
| date = May 28, 2007
| edition = 1st
| publisher = friends of ED
| pages = 840
| isbn = 1-59059-617-X
| url = http://friendsofed.com/book.html?isbn=159059617X
}}
*{{citation
| first = Daniel
| last = Shiffman
| title = Learning Processing: A Beginner's Guide to Programming Images, Animation, and Interaction
| date = August 19, 2008
| edition = 1st
| publisher = Morgan Kaufmann
| pages = 450
| isbn = 0-12-373602-1
| url = http://www.learningprocessing.com/
}}
{{Refend}}

==External links==
* {{Official website|http://processingjs.org/}}
* [http://wiki.mozilla.org/Education/Projects/ProcessingForTheWeb Processing for the Web (POW) project]
* [http://sketchpad.cc/ Studio Sketchpad, a browser-based IDE for Processing.js]
* [https://www.khanacademy.org/cs Computer Science at Khan Academy]
* [http://www.processing.org/ Processing homepage]
* [https://wiki.mozilla.org/Processing.js_for_JavaScript_Devs/ Different ways of executing ]
* [http://gsvideo.sourceforge.net/ GSvideo for playback music]

[[Category:JavaScript visualization toolkits]]
[[Category:Free computer libraries]]
[[Category:JavaScript libraries]]
[[Category:Free software programmed in JavaScript]]
[[Category:Software using the MIT license]]

Latest revision as of 23:58, 22 September 2022

  • From a merge: This is a redirect from a page that was merged into another page. This redirect was kept in order to preserve the edit history of this page after its content was merged into the content of the target page. Please do not remove the tag that generates this text (unless the need to recreate content on this page has been demonstrated) or delete this page.