# 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:
  - graphics/graphics.js, line 36

### 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:
  - graphics/graphics.js, line 109

##### 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:
  - graphics/graphics.js, line 85

##### 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:
  - graphics/graphics.js, line 76

#### (static) registerPublicMethod(name)

Adds a method to the public methods constant.

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | string | Name of the method.

Source:
  - graphics/graphics.js, line 68

#### 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:
  - graphics/graphics.js, line 125

#### canvasExists() → {boolean}

Return if the graphics canvas exists.

Source:
  - graphics/graphics.js, line 528

##### Returns:

Whether or not the canvas exists.

Type
  boolean

#### canvasHasInstance()

Whether the selected canvas already has an instance associated.

Source:
  - graphics/graphics.js, line 650

#### clear()

Clear everything from the canvas.

Source:
  - graphics/graphics.js, line 301

#### drawBackground()

Draw the background color for the current object.

Source:
  - graphics/graphics.js, line 578

#### 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:
  - graphics/graphics.js, line 329

##### Returns:

Type
  boolean

#### fullReset()

Reset all timers to 0 and clear timers and canvas.

Source:
  - graphics/graphics.js, line 512

#### getCanvas() → {object}

Return the current canvas we are using. If there is no canvas on the page this will return null.

Source:
  - graphics/graphics.js, line 537

##### Returns:

The current canvas.

Type
  object

#### getContext() → {context}

Return the 2D graphics context for this graphics object, or null if none exists.

Source:
  - graphics/graphics.js, line 594

##### 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:
  - graphics/graphics.js, line 670

##### 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:
  - graphics/graphics.js, line 314

##### 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:
  - graphics/graphics.js, line 227

##### Returns:

The height of the canvas.

Type
  float

#### getWidth() → {float}

Get the width of the entire graphics canvas.

Source:
  - graphics/graphics.js, line 217

##### 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:
  - graphics/graphics.js, line 208

##### 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:
  - graphics/graphics.js, line 189

#### 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:
  - graphics/graphics.js, line 198

#### 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:
  - graphics/graphics.js, line 144

#### 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:
  - graphics/graphics.js, line 162

#### 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:
  - graphics/graphics.js, line 180

#### 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:
  - graphics/graphics.js, line 153

#### 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:
  - graphics/graphics.js, line 171

#### redraw()

Redraw this graphics canvas.

Source:
  - graphics/graphics.js, line 608

#### remove(elem)

Remove a specific element from the canvas.

##### Parameters:

Name | Type | Description
--- | --- | ---
`elem` | Thing | The element to be removed from the canvas.

Source:
  - graphics/graphics.js, line 385

#### removeAll()

Remove all elements from the canvas.

Source:
  - graphics/graphics.js, line 376

#### resetAllState()

Resets the graphics instance to a clean slate.

Source:
  - graphics/graphics.js, line 488

#### resetAllTimers()

Resets all the timers to time 0.

Source:
  - graphics/graphics.js, line 479

#### 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:
  - graphics/graphics.js, line 447

#### setBackgroundColor(color)

Set the background color of the canvas.

##### Parameters:

Name | Type | Description
--- | --- | ---
`color` | Color | The desired color of the canvas.

Source:
  - graphics/graphics.js, line 293

#### 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:
  - graphics/graphics.js, line 548

#### 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:
  - graphics/graphics.js, line 776

#### setMainTimer()

Set the main timer for graphics.

Source:
  - graphics/graphics.js, line 619

#### 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:
  - graphics/graphics.js, line 400

#### 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:
  - graphics/graphics.js, line 265

#### setup()

Set up the graphics instance to prepare for interaction

Source:
  - graphics/graphics.js, line 677

#### stopAllTimers()

Stop all timers.

Source:
  - graphics/graphics.js, line 250

#### stopGlobalTimer()

Stop the global timer

Source:
  - graphics/graphics.js, line 571

#### 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:
  - graphics/graphics.js, line 240

#### waitForClick()

Record a click.

Source:
  - graphics/graphics.js, line 134

#### waitingForClick() → {boolean}

Whether the graphics instance is waiting for a click.

Source:
  - graphics/graphics.js, line 643

##### Returns:

Whether or not the instance is waiting for a click.

Type
  boolean