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
number specifying value between white and black.
alpha value relative to current color range (default is 0-255).
red or hue value relative to the current color range.
green or saturation value relative to the current color range.
blue or brightness value relative to the current color range.
a color string.
an array containing the red, green, blue, and alpha components of the color.