Reference spotLight()

spotLight()

Creates a light that shines from a point in one direction.

Spot lights are like flashlights that shine in one direction creating a cone of light. The shape of the cone can be controlled using the angle and concentration parameters. A maximum of 5 spot lights can be active at once.

There are eight ways to call spotLight() with parameters to set the light’s color, position, direction. For example, spotLight(255, 0, 0, 0, 0, 0, 1, 0, 0) creates a red (255, 0, 0) light at the origin (0, 0, 0) that points to the right (1, 0, 0).

The angle parameter is optional. It sets the radius of the light cone. For example, spotLight(255, 0, 0, 0, 0, 0, 1, 0, 0, PI / 16) creates a red (255, 0, 0) light at the origin (0, 0, 0) that points to the right (1, 0, 0) with an angle of PI / 16 radians. By default, angle is PI / 3 radians.

The concentration parameter is also optional. It focuses the light towards the center of the light cone. For example, spotLight(255, 0, 0, 0, 0, 0, 1, 0, 0, PI / 16, 50) creates a red (255, 0, 0) light at the origin (0, 0, 0) that points to the right (1, 0, 0) with an angle of PI / 16 radians at concentration of 50. By default, concentration is 100.

Examples

Syntax

spotLight(v1, v2, v3, x, y, z, rx, ry, rz, [angle], [concentration])
spotLight(color, position, direction, [angle], [concentration])
spotLight(v1, v2, v3, position, direction, [angle], [concentration])
spotLight(color, x, y, z, direction, [angle], [concentration])
spotLight(color, position, rx, ry, rz, [angle], [concentration])
spotLight(v1, v2, v3, x, y, z, direction, [angle], [concentration])
spotLight(v1, v2, v3, position, rx, ry, rz, [angle], [concentration])
spotLight(color, x, y, z, rx, ry, rz, [angle], [concentration])

Parameters

v1
Number:

red or hue value in the current colorMode().

v2
Number:

green or saturation value in the current colorMode().

v3
Number:

blue, brightness, or lightness value in the current colorMode().

x
Number:

x-coordinate of the light.

y
Number:

y-coordinate of the light.

z
Number:

z-coordinate of the light.

rx
Number:

x-component of light direction between -1 and 1.

ry
Number:

y-component of light direction between -1 and 1.

rz
Number:

z-component of light direction between -1 and 1.

angle
Number:

angle of the light cone. Defaults to PI / 3.

concentration
Number:

concentration of the light. Defaults to 100.

color
p5.Color|Number[]|String:

color as a p5.Color object, an array of color values, or a CSS string.

position
p5.Vector:

position of the light as a p5.Vector object.

direction
p5.Vector:

direction of light as a p5.Vector object.

Notice any errors or typos? Please let us know. Please feel free to edit src/webgl/light.js and open a pull request!

Related References