Class Fz2D

Defined in: src/fz2d.coffee

Overview

Public: Fz2D

Constant Summary

VERSION =
Public: Version Number.
'0.0.6'
NONE =
Public: None.
0
FG =
Public: Default foreground color.
'#FFFFFF'
BG =
Public: Default background color.
'#3F7CB6'
SELECTOR =
Public: Default canvas selector.
'#canvas'
PATH =
Public: Default assets path.
'assets'

Class Method Summary

Class Method Details

.any(o) Source

Public: Returns true if an array, hash or string is not empty. o - array, hash or string

Parameters:

  • oarray, hash or string

.appendEl(el, parent = document.body) Source

Public: Adds a HTML DOM element to a parent HTML DOM element. el - HTML DOM element parent - parent HTML DOM element (default: document.body) Returns the element itself.

Parameters:

  • elHTML DOM element
  • parentparent HTML DOM element (default: document.body)

Returns:

  • Returns the element itself.

.callable(o) Source

Public: Returns true if the argument if a callable. o - argument

Parameters:

  • oargument

.clamp(d, min, max) Source

Public: Clamps a given number between two limits. d - number min - minimum limit max - maximum limit Returns the clamped number.

Parameters:

  • dnumber
  • minminimum limit
  • maxmaximum limit

Returns:

  • Returns the clamped number.

.collide(o1, o2, cb) Source

Public: Determines if there's a collision between two objects. o1 - object or group o2 - object or group cb - callback function to be called on each collision Unlike Fz2D.overlap, if `o1` and/or `o2` are groups, it *will* call `collide` against all of their children. Returns true or false.

Parameters:

  • o1object or group
  • o2object or group
  • cbcallback function to be called on each collision

Returns:

  • Returns true or false.

.contains(o, p) Source

Public: Determines if an object or group contains a point. o - object or group p - point Returns true or false.

Parameters:

  • oobject or group
  • ppoint

Returns:

  • Returns true or false.

.createEl(type, attrs = {}, styles = {}) Source

Public: Creates a new HTML DOM element. type - type of HTML DOM element attrs - Hash of attributes (optional) styles - Hash of style attributes (optional) Returns a new instance of a HTML DOM element of the given type.

Parameters:

  • typetype of HTML DOM element
  • attrsHash of attributes (optional)
  • stylesHash of style attributes (optional)

Returns:

  • Returns a new instance of a HTML DOM element of the given type.

.dist(o1, o2) Source

Public: Determines the distance between two objects. o1 - object o2 - object Returns the distance. See also Fz2D.distSqr for cases when you don't need the exact distance.

Parameters:

  • o1object
  • o2object

Returns:

  • Returns the distance.

.distSqr(o1, o2) Source

Public: Determines the squared distance between two objects. o1 - object o2 - object Returns the squared distance. See also Fz2D.dist for cases when you *need* the exact distance.

Parameters:

  • o1object
  • o2object

Returns:

  • Returns the squared distance.

.empty(o) Source

Public: Returns true if an array, hash or string is empty. o - array, hash or string

Parameters:

  • oarray, hash or string

.enumerable(o) Source

Public: Returns true if the argument is enumerable. o - argument

Parameters:

  • oargument

.getCollisionSide(o1, o2) Source

Public: Determines the side of a collision. o1 - object o2 - object Returns the sides of a collision.

Parameters:

  • o1object
  • o2object

Returns:

  • Returns the sides of a collision.

.getJSON(url, cb) Source

Public: Performs an asynchronous HTTP GET request. url - url to perform the request for cb - ready callback function Parses `responseText` as JSON before passing it to `callback`. Returns immediately with an undefined value.

Parameters:

  • urlurl to perform the request for
  • cbready callback function

Returns:

  • Returns immediately with an undefined value.

.object(o) Source

Public: Returns true if the argument is an object. o - argument

Parameters:

  • oargument

.overlap(o1, o2) Source

Public: Determines if an object or group overlaps with another object or group. o1 - object or group o2 - object or group If `o1` or `o2` is a group, it will not call `overlap` against all of their children. See also Fz2D.collide. Returns a true or false.

Parameters:

  • o1object or group
  • o2object or group

Returns:

  • Returns a true or false.

.present(o) Source

Public: Returns true if an array, hash or string is not empty. o - array, hash or string

Parameters:

  • oarray, hash or string

.require(file) Source

Public: Requires a single class of Fz2D, used by tests. file - filename

Parameters:

  • filefilename

.setStyleEl(el, styles = {}) Source

Public: Sets style properties of a HTML DOM element. el - HTML DOM element styles - Hash of style attributes (default: {}) Returns the element itself.

Parameters:

  • elHTML DOM element
  • stylesHash of style attributes (default: {})

Returns:

  • Returns the element itself.

.step(t, d, min, max) Source

Public: Linearly interpolates a number within two limits based on time. t - timestamp (step) d - number min - minimum limit max - maximum limit Returns the interpolated value for the given timestamp (step).

Parameters:

  • ttimestamp (step)
  • dnumber
  • minminimum limit
  • maxmaximum limit

Returns:

  • Returns the interpolated value for the given timestamp (step).

.string(o) Source

Public: Returns true if the argument is a string. o - argument

Parameters:

  • oargument

.swap(a, b) Source

Public: Swaps A with B. a - A b - B Returns A and B swapped.

Parameters:

  • aA
  • bB

Returns:

  • Returns A and B swapped.

.toRGB(color) Source

Public: Converts HTML color code into floating point RGB components. color - HTML color code (with # prefix) Returns RGB converted to floating point components.

Parameters:

  • colorHTML color code (with # prefix)

Returns:

  • Returns RGB converted to floating point components.