Illuminated.js Docs (v0.1)

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

illuminated.Lamp Class

A circular light rendered as a radial gradient. Lamps can also be "oriented" in a specific direction.

Constructor

illuminated.Lamp

(
  • [options]
)

Parameters:

  • [options] Object optional

    Options to be applied to this lamp.

    • [position] illuminated.Vec2 optional

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

    • [distance=100] Number optional

      Intensity of this lamp.

    • [diffuse=0.8] Number optional

      How diffuse this lamp is.

    • [color='rgba(250,220,150,0.8)'] String optional

      The color emitted by the lamp. The color can be specified in any CSS format.

    • [radius=0] Number optional

      The size of the lamp. Bigger lamps cast smoother shadows.

    • [samples=1] Number optional

      The number of points which will be used for shadow projection. It defines the quality of the rendering.

    • [angle=0] Number optional

      The angle of the orientation of the lamp.

    • [roughness=0] Number optional

      The roughness of the oriented effect.

Example:

new Lamp({
  position: new Vec2(12, 34),
  distance: 100,
  diffuse: 0.8,
  color: 'rgba(250,220,150,0.8)',
  radius: 0,
  samples: 1,
  angle: 0,
  roughness: 0
})

Methods

_getGradientCache

(
  • center
)
private

Renders this lamp's gradient onto a cached canvas at the given position.

Parameters:

_getHashCache

() String private

Return a string hash key representing this lamp.

Returns:

String: The hash key.

_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

Inherited from illuminated.Light but overwritten in src/illuminated.js:450

Calculate the boundaries of this lamp based on its properties.

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

Inherited from illuminated.Light but overwritten in src/illuminated.js:440

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

Returns:

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

forEachSample

(
  • f
)

Inherited from illuminated.Light but overwritten in src/illuminated.js:512

Invoke a function for every sample generated by this lamp. The samples for lamps are generated using a "spiral" algorithm.

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
)

Inherited from illuminated.Light but overwritten in src/illuminated.js:465

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

Parameters:

  • ctx CanvasRenderingContext2D

    The canvas context onto which the mask will be rendered.

render

(
  • ctx
)

Inherited from illuminated.Light but overwritten in src/illuminated.js:500

Render the lamp onto the given context (without any shadows).

Parameters:

  • ctx CanvasRenderingContext2D

    The canvas context onto which the light will be rendered.

Properties

angle

Number

The angle of the orientation of the lamp.

Default: 0

color

String

The color emitted by the lamp. The color can be specified in any CSS format.

Default: 'rgba(250,220,150,0.8)'

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)

radius

Number

The size of the lamp. Bigger lamps cast smoother shadows.

Default: 0

roughness

Number

The roughness of the oriented effect.

Default: 0

samples

Number

The number of points which will be used for shadow projection. It defines the quality of the rendering.

Default: 1