Reference color()

color()

Creates a p5.Color object.

By default, the parameters are interpreted as RGB values. Calling color(255, 204, 0) will return a bright yellow color. The way these parameters are interpreted may be changed with the colorMode() function.

The version of color() with one parameter interprets the value one of two ways. If the parameter is a number, it's interpreted as a grayscale value. If the parameter is a string, it's interpreted as a CSS color string.

The version of color() with two parameters interprets the first one as a grayscale value. The second parameter sets the alpha (transparency) value.

The version of color() with three parameters interprets them as RGB, HSB, or HSL colors, depending on the current colorMode().

The version of color() with four parameters interprets them as RGBA, HSBA, or HSLA colors, depending on the current colorMode(). The last parameter sets the alpha (transparency) value.

Examples

Syntax

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

Parameters

gray
Number:

number specifying value between white and black.

alpha
Number:

alpha value relative to current color range (default is 0-255).

v1
Number:

red or hue value relative to the current color range.

v2
Number:

green or saturation value relative to the current color range.

v3
Number:

blue or brightness value relative to the current color range.

value
String:

a color string.

values
Number[]:

an array containing the red, green, blue, and alpha components of the color.

color
p5.Color:

Related References