lmccart/p5.js — pull request #95 by bobholt (2014-01-04 04:41:39+00:00)
Title: Allow library to be used in either global or "instanced" modes

This PR fixes #78. The goal was to allow the library to be used either globally or via calling `new Processing(canvas, sketchProc);`. To accomplish this, I refactored the library into AMD-compatible modules. This will help keep the code organized, help prevent unwanted globals, help make unit testing easier, and hopefully allow modular builds without too much trouble (as requested in #94).

The library only exposes globals when used in "beginner mode." This beginner mode is triggered when a user creates the required setup function in the global namespace. If the user does not have a globally-exposed setup function and calls `new Processing(canvas, sketchProc);`, it will be in "advanced" instanced mode.

In the absence of unit tests, this library runs all examples in this repo and in the fall13 RISD class site in global/beginner mode without regression. There are likely regressions not covered by these examples. Please open issues for those as they are found. These examples run as-is, with one exception: the backwards-compatible example required 2 minor changes. Both cases relied on "undocumented" API features, and had better coding choices available. As the API solidifies, some of these older sketches will likely require minor changes of this sort.

Note: passing a canvas element as the first argument to the constructor does not currently do anything - the `createGraphics` method must be used. I will open a separate issue for this.

That's all I can think of for now.