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.

p5.strands is an experimental mode for writing shader code with p5.js-like syntax instead of GLSL. In p5.strands shader callbacks, color() accepts the same input formats but returns a vec4 instead of a p5.Color object, with RGBA components normalized to the 0–1 range. All colors in strands are RGB-based; colorMode() has no effect inside shader callbacks. Color utility functions such as red(), green(), blue(), alpha(), hue(), saturation(), brightness(), and lightness() also return values in the 0–1 range when used in strands.

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:

Returns

p5.Color: resulting color.

Related References