CodeHSGraphics

CodeHSGraphics

new CodeHSGraphics(options)

Set up an instance of the graphics library.
Parameters:
Name Type Description
options dictionary Options, primarily .canvas, the selector string for the canvas. If multiple are returned, we'll take the first one. If none is passed, we'll look for any canvas tag on the page.
Source:

Methods

(static) getConstructorModificationString() → {string}

Generate strings for the public constructors to bring them to the public namespace without having to call them with the graphics instance.
Source:
Returns:
Line broken constructor declarations.
Type
string

(static) getNamespaceModifcationString() → {string}

Generate strings for the public methods to bring them to the public namespace without having to call them with the graphics instance.
Source:
Returns:
Line broken function definitions.
Type
string

(static) registerConstructorMethod(name)

Adds a constructor to the public constructors constant.
Parameters:
Name Type Description
name string Name of the object to be constructed.
Source:

(static) registerPublicMethod(name)

Adds a method to the public methods constant.
Parameters:
Name Type Description
name string Name of the method.
Source:

add(elem)

Add an element to the graphics instance.
Parameters:
Name Type Description
elem Thing A subclass of Thing to be added to the graphics instance.
Source:

audioChangeMethod(tag, fn)

Assign a function as a callback for when audio data changes for audio being played in a graphics program.
Parameters:
Name Type Description
tag object Audio element playing sound to analyze
fn function A callback to be triggered on audio data change.
Source:

canvasExists() → {boolean}

Return if the graphics canvas exists.
Source:
Returns:
Whether or not the canvas exists.
Type
boolean

canvasHasInstance()

Whether the selected canvas already has an instance associated.
Source:

clear()

Clear everything from the canvas.
Source:

deviceMotionMethod(fn)

Assign a function as a callback for device motion events.
Parameters:
Name Type Description
fn function A callback to be triggered device motion events.
Source:

deviceOrientationMethod(fn)

Assign a function as a callback for device orientation events.
Parameters:
Name Type Description
fn function A callback to be triggered on device orientation events.
Source:

drawBackground()

Draw the background color for the current object.
Source:

elementExistsWithParameters(params) → {boolean}

Check if an element exists with the given paramenters.
Parameters:
Name Type Description
params object Dictionary of parameters for the object. Includes x, y, heigh, width, color, radius, label and type.
Source:
Returns:
Type
boolean

fullReset()

Reset all timers to 0 and clear timers and canvas.
Source:

getCanvas() → {object}

Return the current canvas we are using. If there is no canvas on the page this will return null.
Source:
Returns:
The current canvas.
Type
object

getContext() → {context}

Return the 2D graphics context for this graphics object, or null if none exists.
Source:
Returns:
The 2D graphics context.
Type
context

getDistance(x1, y1, x2, y2) → {number}

Get the distance between two points, (x1, y1) and (x2, y2)
Parameters:
Name Type Description
x1 number
y1 number
x2 number
y2 number
Source:
Returns:
Distance between the two points.
Type
number

getElementAt(x, y) → {Thing|null}

Get an element at a specific point. If several elements are present at the position, return the one put there first.
Parameters:
Name Type Description
x number The x coordinate of a point to get element at.
y number The y coordinate of a point to get element at.
Source:
Returns:
The object at the point (x, y), if there is one (else null).
Type
Thing | null

getHeight() → {float}

Get the height of the entire graphics canvas.
Source:
Returns:
The height of the canvas.
Type
float

getWidth() → {float}

Get the width of the entire graphics canvas.
Source:
Returns:
The width of the canvas.
Type
float

isKeyPressed(keyCode) → {boolean}

Check if a key is currently pressed
Parameters:
Name Type Description
keyCode integer Key code of key being checked.
Source:
Returns:
Whether or not that key is being pressed.
Type
boolean

keyDownMethod(fn)

Assign a function as a callback for keydown events.
Parameters:
Name Type Description
fn function A callback to be triggered on keydown events.
Source:

keyUpMethod(fn)

Assign a function as a callback for key up events.
Parameters:
Name Type Description
fn function A callback to be triggered on key up events.
Source:

mouseClickMethod(fn)

Assign a function as a callback for click (mouse down, mouse up) events.
Parameters:
Name Type Description
fn function A callback to be triggered on click events.
Source:

mouseDownMethod(fn)

Assign a function as a callback for mouse down events.
Parameters:
Name Type Description
fn function A callback to be triggered on mouse down.
Source:

mouseDragMethod(fn)

Assign a function as a callback for drag events.
Parameters:
Name Type Description
fn function A callback to be triggered on drag events.
Source:

mouseMoveMethod(fn)

Assign a function as a callback for mouse move events.
Parameters:
Name Type Description
fn function A callback to be triggered on mouse move events.
Source:

mouseUpMethod(fn)

Assign a function as a callback for mouse up events.
Parameters:
Name Type Description
fn function A callback to be triggered on mouse up events.
Source:

redraw()

Redraw this graphics canvas.
Source:

remove(elem)

Remove a specific element from the canvas.
Parameters:
Name Type Description
elem Thing The element to be removed from the canvas.
Source:

removeAll()

Remove all elements from the canvas.
Source:

resetAllState()

Resets the graphics instance to a clean slate.
Source:

resetAllTimers()

Resets all the timers to time 0.
Source:

runCode(code)

This is how you run the code, but get access to the state of the graphics library. The current instance becomes accessible in the code.
Parameters:
Name Type Description
code string The code from the editor.
Source:

setBackgroundColor(color)

Set the background color of the canvas.
Parameters:
Name Type Description
color Color The desired color of the canvas.
Source:

setCurrentCanvas(canvasSelector)

Set the current canvas we are working with. If no canvas tag matches the selectorv then we will just have the current canvas set to null.
Parameters:
Name Type Description
canvasSelector string String representing canvas class or ID. Selected with jQuery.
Source:

setGraphicsTimer(fn, time, data, name)

Set a graphics timer.
Parameters:
Name Type Description
fn function The function to be executed on the timer.
time number The time interval for the function.
data object Any arguments to be passed into `fn`.
name string The name of the timer.
Source:

setMainTimer()

Set the main timer for graphics.
Source:

setSize(w, h)

Set the size of the canvas.
Parameters:
Name Type Description
w number Desired width of the canvas.
h number Desired height of the canvas.
Source:

setTimer(fn, time, data, name)

Create a new timer
Parameters:
Name Type Description
fn function Function to be called at intervals.
time integer Time interval to call function `fn`
data dictionary Any data associated with the timer.
name string Name of this timer.
Source:

setup()

Set up the graphics instance to prepare for interaction
Source:

stopAllTimers()

Stop all timers.
Source:

stopGlobalTimer()

Stop the global timer
Source:

stopTimer(fn)

Remove a timer associated with a function.
Parameters:
Name Type Description
fn function Function whose timer is removed. note 'fn' may also be the name of the function.
Source:

updateAudio()

This function is called on a timer. Calls the student's audioChangeCallback function and passes it the most recent audio data.
Source:

waitForClick()

Record a click.
Source:

waitingForClick() → {boolean}

Whether the graphics instance is waiting for a click.
Source:
Returns:
Whether or not the instance is waiting for a click.
Type
boolean