Class Lamp

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

Hierarchy

Constructors

  • Parameters

    • options: Partial<Pick<Lamp, "angle" | "id" | "color" | "samples" | "radius" | "roughness"> & Partial<Pick<Light, "position" | "hidden" | "distance" | "diffuse" | "samples">>> = {}

      Options to be applied to the lamp.

    Returns Lamp

    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
    })

Properties

#cacheHashcode?: string
#gradientCache?: CanvasAndContext
#vismaskCache?: CanvasAndContext
#vismaskHash?: string
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

The intensity of the light penetration in objects.

Default

0.8
distance: number

Intensity of the light.

Default

100
hidden: boolean

Whether the light is hidden or not.

Default

false
id: number

The id of the light object.

Default

0
position: Vec2

Position of the light object.

Default

new Vec2()
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
#uniqueId: number = 0

Methods

  • Calculate the boundaries of the lamp based on its properties.

    Returns Bounds

    An anonymous object with the properties topLeft and bottomRight. The property values are Vec2 objects representing the corners of the boundary.

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

    Returns Vec2

    A new vector that represents the center of the lamp.

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

    Parameters

    • callback: ((position) => void)

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

        • (position): void
        • Parameters

          Returns void

    Returns void

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

    Parameters

    • center: Vec2

      The position of the center of the gradient to render.

    Returns undefined | CanvasAndContext

  • Return a string hash key representing the lamp.

    Returns string

    The hash key.

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

    Parameters

    • context: CanvasRenderingContext2D

      The canvas context onto which the mask will be rendered.

    Returns void

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

    Parameters

    • context: CanvasRenderingContext2D

      The canvas context onto which the light will be rendered.

    Returns void