Skip to content
soulwire edited this page Oct 9, 2012 · 17 revisions

Options

Passed to the Sketch.create method.

  • fullscreen Default: true
  • autostart Default: true Otherwise call start()
  • autoclear Default: true Whether to clear the context before each call to draw. Otherwise call clear()
  • container Default: document.body Where to put the sketch context
  • interval Default: 1 The update / draw interval (2 will update every 2 frames, etc)
  • type Default Sketch.CANVAS Possible values: Sketch.CANVAS, Sketch.WEB_GL and Sketch.DOM

Class Methods

  • create Creates and returns a new sketch. Arguments: options Optional hash including any number of the above options

Instance Methods

  • start
  • stop
  • clear

Overridable Instance Methods

Implement these methods on your sketch instance (or pass them to create inside the options hash).

  • setup
  • update
  • draw
  • touchstart
  • touchmove
  • touchend
  • mouseover
  • mousedown
  • mousemove
  • mouseout
  • mouseup
  • click
  • keydown
  • keyup
  • resize

Instance Properties

  • mouse Contains x, y, ox, oy, dy and dy, representing the mouse or primary touch.
  • touches List of current touches with same structure as mouse. On the desktop, the 0th element represents the mouse.
  • dragging Whether the mouse is down / the user is dragging
  • running Whether the animation loop is running (modified by the start and stop methods)
  • width Current viewport width
  • height Current viewport height
  • keys A hash of booleans indicating whether each key is currently pressed, e.g sketch.keys.SPACE
  • millis The total runtime of the sketch in milliseconds
  • now The current time in milliseconds
  • dt The delta time between the current and previous frame in milliseconds

Constants

  • CANVAS Enumeration for the Canvas type
  • WEB_GL Enumeration for the WebGL type
  • DOM Enumeration for the DOM type

Global Properties

These are safely mixed into the window object for quick access, e.g: sin( random( TWO_PI ) )

Methods

  • random Accepts single values, ranges and Arrays, e.g: random( 10, 20 ) or random( colours )

Math Constants

  • PI
  • TWO_PI
  • HALF_PI
  • QUATER_PI

Math functions

  • sin
  • cos
  • tan
  • pow
  • exp
  • min
  • max
  • sqrt
  • atan
  • atan2
  • ceil
  • round
  • floor
Clone this wiki locally