Reference ambientLight()

ambientLight()

Creates a light that shines from all directions.

Ambient light does not come from one direction. Instead, 3D shapes are lit evenly from all sides. Ambient lights are almost always used in combination with other types of lights.

There are three ways to call ambientLight() with optional parameters to set the light’s color.

The first way to call ambientLight() has two parameters, gray and alpha. alpha is optional. Grayscale and alpha values between 0 and 255 can be passed to set the ambient light’s color, as in ambientLight(50) or ambientLight(50, 30).

The second way to call ambientLight() has one parameter, color. A p5.Color object, an array of color values, or a CSS color string, as in ambientLight('magenta'), can be passed to set the ambient light’s color.

The third way to call ambientLight() has four parameters, v1, v2, v3, and alpha. alpha is optional. RGBA, HSBA, or HSLA values can be passed to set the ambient light’s colors, as in ambientLight(255, 0, 0) or ambientLight(255, 0, 0, 30). Color values will be interpreted using the current colorMode().

Examples

Syntax

ambientLight(v1, v2, v3, [alpha])
ambientLight(gray, [alpha])
ambientLight(value)
ambientLight(values)
ambientLight(color)

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().

alpha
Number:

alpha (transparency) value in the current colorMode().

gray
Number:

grayscale value between 0 and 255.

value
String:

color as a CSS string.

values
Number[]:

color as an array of RGBA, HSBA, or HSLA values.

color
p5.Color:

color as a p5.Color 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