Reference pointLight()

pointLight()

Creates a light that shines from a point in all directions.

Point lights are like light bulbs that shine in all directions. They can be placed at different positions to achieve different lighting effects. A maximum of 5 point lights can be active at once.

There are four ways to call pointLight() with parameters to set the light’s color and position.

The first way to call pointLight() has six parameters. The first three parameters, v1, v2, and v3, set the light’s color using the current colorMode(). The last three parameters, x, y, and z, set the light’s position. For example, pointLight(255, 0, 0, 50, 0, 0) creates a red (255, 0, 0) light that shines from the coordinates (50, 0, 0).

The second way to call pointLight() has four parameters. The first three parameters, v1, v2, and v3, set the light’s color using the current colorMode(). The last parameter, position sets the light’s position using a p5.Vector object. For example, pointLight(255, 0, 0, lightPos) creates a red (255, 0, 0) light that shines from the position set by the lightPos vector.

The third way to call pointLight() has four parameters. The first parameter, color, sets the light’s color using a p5.Color object or an array of color values. The last three parameters, x, y, and z, set the light’s position. For example, directionalLight(myColor, 50, 0, 0) creates a light that shines from the coordinates (50, 0, 0) with the color value of myColor.

The fourth way to call pointLight() has two parameters. The first parameter, color, sets the light’s color using a p5.Color object or an array of color values. The second parameter, position, sets the light’s position using a p5.Vector object. For example, directionalLight(myColor, lightPos) creates a light that shines from the position set by the lightPos vector with the color value of myColor.

Examples

Syntax

pointLight(v1, v2, v3, x, y, z)
pointLight(v1, v2, v3, position)
pointLight(color, x, y, z)
pointLight(color, position)

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.

position
p5.Vector:

position of the light as a p5.Vector object.

color
p5.Color|Number[]|String:

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

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