Open main menu

CDOT Wiki β

Changes

Processing.js/HowTo

2 bytes added, 15:12, 27 August 2010
no edit summary
** Simple drawing tutorial
==PJS P.JS Preloading directive==
Because of asynchronous loading in the browser, images used in sketches for processing.js should be preloaded using the @PJS pjs directive at the top line of the sketch. The PJS P.JS preloading directive forces the sketch to load specified images ahead of time before the sketch begins to run.
Not using the preloading functionality will cause the sketch to continue running after a loadImage() or requestImage() call and if you specify actions to happen on the images you will get unpredictable behavior if the image data isn’t fully loaded yet.
Sample code
loading one image
/* @PJS pjs preload=”image.jpg”; */
loading multiple images
/* @PJS pjs preload=”sun.jpg,moon.jpg,stars.jpg”; */
loading an image from a remote location
/* @PJS pjs preload=”http://www.urltoimage.com/image.jpg”; */
loadImage() example
1
edit