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
red or hue value in the current colorMode().
green or saturation value in the current colorMode().
blue, brightness, or lightness value in the current colorMode().
x-coordinate of the light.
y-coordinate of the light.
z-coordinate of the light.
x-component of light direction between -1 and 1.
y-component of light direction between -1 and 1.
z-component of light direction between -1 and 1.
angle of the light cone. Defaults to PI / 3
.
concentration of the light. Defaults to 100.
color as a p5.Color object, an array of color values, or a CSS string.
position of the light as a p5.Vector object.
direction of light as a p5.Vector object.