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 optionalOptions to be applied to this lamp.
-
[position]
illuminated.Vec2 optionalPosition of this lamp. (0,0) by default.
-
[distance=100]
Number optionalIntensity of this lamp.
-
[diffuse=0.8]
Number optionalHow diffuse this lamp is.
-
[color='rgba(250,220,150,0.8)']
String optionalThe color emitted by the lamp. The color can be specified in any CSS format.
-
[radius=0]
Number optionalThe size of the lamp. Bigger lamps cast smoother shadows.
-
[samples=1]
Number optionalThe number of points which will be used for shadow projection. It defines the quality of the rendering.
-
[angle=0]
Number optionalThe angle of the orientation of the lamp.
-
[roughness=0]
Number optionalThe 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
})
Item Index
Methods
Methods
_getGradientCache
-
center
Renders this lamp's gradient onto a cached canvas at the given position.
Parameters:
-
center
illuminated.Vec2The position of the center of the gradient to render.
_getHashCache
()
String
private
Return a string hash key representing this lamp.
Returns:
_getVisibleMaskCache
()
CanvasRenderingContext2D
private
Creates a canvas context with the visible mask rendered onto it.
Returns:
bounds
()
Object
Calculate the boundaries of this lamp based on its properties.
Returns:
center
()
illuminated.Vec2
Return the center of this lamp. i.e. The position where the lamp intensity is the highest
Returns:
forEachSample
-
f
Invoke a function for every sample generated by this lamp. The samples for lamps are generated using a "spiral" algorithm.
Parameters:
-
f
FunctionFunction 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
CanvasRenderingContext2DThe canvas context onto which the mask will be rendered.
render
-
ctx
Render the lamp onto the given context (without any shadows).
Parameters:
-
ctx
CanvasRenderingContext2DThe 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