Illuminated.js Docs (v0.1)

A 2D lights and shadows rendering engine for your HTML5 web applications and games.
Show:

illuminated.Light Class

Module: illuminated

Abstract class for light objects.

Constructor

illuminated.Light

(
  • [options]
)

Parameters:

  • [options] Object optional

    Options to be applied to this light.

    • [position] illuminated.Vec2 optional

      Position of this light. (0,0) by default.

    • [distance=100] Number optional

      Intensity of this light.

    • [diffuse=0.8] Number optional

      How diffuse this light is.

Methods

_getVisibleMaskCache

() CanvasRenderingContext2D private

Creates a canvas context with the visible mask rendered onto it.

Returns:

CanvasRenderingContext2D: A canvas context with the visible mask rendered onto it.

bounds

() Object

Calculate the boundaries of this light using the light's distance.

Returns:

Object: An anonymous object with the properties topleft and bottomright. The property values are illuminated.Vec2 objects representing the corners of the boundary.

center

() illuminated.Vec2

Return the center of this light. i.e. The position where the light intensity is the highest

Returns:

illuminated.Vec2: A new vector that represents the center of this light.

forEachSample

(
  • f
)

Invoke a function for every sample generated by this light.

Parameters:

  • f Function

    Function to be called for every sample. The function will be passed a vector representing the position of the sample.

mask

(
  • ctx
)

Render a mask representing the visibility. (Used by DarkMask.)

Parameters:

  • ctx CanvasRenderingContext2D

    The canvas context onto which the mask will be rendered.

render

(
  • ctx
)

Render the light onto the given context.

Parameters:

  • ctx CanvasRenderingContext2D

    The canvas context onto which the light will be rendered.

Properties

diffuse

Number

How diffuse this light is.

Default: 0.8

distance

Number

Intensity of this light.

Default: 100

position

Vec2

Position of this light. (0,0) by default.

Default: new Vec2(0, 0)