Jump to content

Processing.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Hacker12321 (talk | contribs) at 22:02, 5 September 2015 (hihiihihihihihihihihhihihiiiihihiiikkkl). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

hihihihihhi

Versionshi

/* 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
}

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

Challenges

  • calling color() 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.

// before
int g = mouseX / j;

// after
int g = (int)(mouseX / j);

See also

References

  • Glassner, Andrew (August 9, 2010), Processing for Visual Artists: How to Create Expressive Images and Interactive Art (1st ed.), A K Peters/CRC Press, p. 955, ISBN 1-56881-716-9D
  • Reas, Casey; Fry, Ben (June 17, 2010), Getting Started with Processing (1st ed.), Make, p. 208, ISBN 1-4493-7980-X
  • Noble, Joshua (July 21, 2009), Programming Interactivity: A Designer's Guide to Processing, Arduino, and Openframeworks (1st ed.), O'Reilly Media, p. 736, ISBN 0-596-15414-3
  • Terzidis, Kostas (May 11, 2009), Algorithms for Visual Design Using the Processing Language (1st ed.), Wiley, p. 384, ISBN 0-470-37548-5
  • Reas, Casey; Fry, Ben; Maeda, John (September 30, 2007), Processing: A Programming Handbook for Visual Designers and Artists (1st ed.), The MIT Press, p. 736, ISBN 0-262-18262-9
  • Fry, Ben (January 11, 2008), Visualizing Data (1st ed.), O'Reilly Media, p. 382, ISBN 0-596-51455-7
  • Greenberg, Ira (May 28, 2007), Processing: Creative Coding and Computational Art (Foundation) (1st ed.), friends of ED, p. 840, ISBN 1-59059-617-X
  • Shiffman, Daniel (August 19, 2008), Learning Processing: A Beginner's Guide to Programming Images, Animation, and Interaction (1st ed.), Morgan Kaufmann, p. 450, ISBN 0-12-373602-1