Util module from "Playing with Chaos"
This is the util module from Keith Peters' wonderful book "Playing with Chaos" adapted to a node-style module.
var keycode = require'keycode'chaosjs = require'../../chaosjs';windowonload = initvar chaos = chaosjsdocumentbodyaddEventListener"keyup"var key = keycodeeventkeyCodeif key === 'space' drawelse if key === 'p' chaospopImagevar x = Mathrandom * chaoswidth - 100y = Mathrandom * chaosheight - 100w = 20 + Mathrandom * 100h = 20 + Mathrandom * 100r = MathfloorMathrandom * 256g = MathfloorMathrandom * 256b = MathfloorMathrandom * 256;chaoscontextfillStyle = "rgb(" + r + "," + g + "," + b + ")"chaoscontextfillRectx y w h
The biggest difference is that the "init" method is gone and the module itself intializes an object it returns. This is so that you can use this against multiple canvas elements on a single page.
Intializes and returns the util API for
element which can be a canvas element or an element id to lookup. If no element is passed one with an id
canvas is used. By default the element is resized to the full height and width of the window, you can disable this by passing
false as the second argument.