Sandpit

Sandpit

A playground for creative coding

Constructor

new Sandpit(container, type, options)

Parameters:
Name Type Description
container string | object

The container for the canvas to be added to

type string

Defines whether the context is 2d or 3d

options object

Optionally decide to ignore rescaling for retina displays, disable putting settings into the query string, or add stats to the dom

Source:

Members

autoClear

Sets whether the canvas autoclears after each render

Source:

autoClear

Checks if autoclear is on

Source:

canvas

Returns the canvas object

Source:

context

Returns the canvas context

Source:

debug

Checks if debugger is active

Source:

debug

Defines whether or not to return debugger messages from Sandpit

Source:

focusTouchesOnCanvas

Sets whether to or not to ignore the touch events for multitouch, bypassing pinch to zoom, but meaning no other touch events will work

Source:

focusTouchesOnCanvas

Checks if touches are focused on the canvas

Source:

height

Returns the canvas height

Source:

height

Sets the canvas height

Source:

settings

Creates the settings GUI

Source:

settings

Returns the settings object

Source:

time

Returns the frame increment

Source:

width

Sets the canvas width

Source:

width

Returns the canvas width

Source:

Methods

clear(boolean)

Clears the canvas, and if change is set, fires change

Parameters:
Name Type Description
boolean boolean
Source:

clearQueryString()

Clear the query string

Source:

fill(color)

Fills the canvas with the provided colour

Parameters:
Name Type Description
color string

The color to fill with, in string format (for example, '#000', 'rgba(0, 0, 0, 0.5)')

Source:

get(url)

Returns a promise using fetch https://github.com/github/fetch

Parameters:
Name Type Description
url string

The url to fetch

Source:

random(seed) → {function}

Returns a random number generator based on a seed

Parameters:
Name Type Default Description
seed string 123456

The seed with which to create the random number

Source:
Returns:

A function that returns a random number

Type
function

resizeCanvas()

Resizes the canvas to the window width and height

Source:

setupStats(stats)

Handle the stats object

Parameters:
Name Type Description
stats object

a Stats.js object, which can be imported from Sandpit with import { Stats } from 'sandpit'

Source:

start()

Sets up resizing and input events and starts the loop

Source:

stop()

Stops the loop and removes event listeners

Source: