Static p5_sys::global::color[][src]

pub static color: ColorInternalType
Expand description

Creates colors for storing in variables of the color datatype. The parameters are interpreted as RGB or HSB values depending on the current colorMode(). The default mode is RGB values from 0 to 255 and, therefore, the function call color(255, 204, 0) will return a bright yellow color.

Note that if only one value is provided to color(), it will be interpreted as a grayscale value. Add a second value, and it will be used for alpha transparency. When three values are specified, they are interpreted as either RGB or HSB values. Adding a fourth value applies alpha transparency.

If a single string argument is provided, RGB, RGBA and Hex CSS color strings and all named color strings are supported. In this case, an alpha number value as a second argument is not supported, the RGBA form should be used.

Examples

let c = color(255, 204, 0);
fill(c);
noStroke();
rect(30, 20, 55, 55);
let c = color(255, 204, 0);
fill(c);
noStroke();
ellipse(25, 25, 80, 80); // Draw left circle
// Using only one value generates a grayscale value.
c = color(65);
fill(c);
ellipse(75, 75, 80, 80);
// You can use named SVG & CSS colors
let c = color('magenta');
fill(c);
noStroke();
rect(20, 20, 60, 60);
// Example of hex color codes
noStroke();
let c = color('#0f0');
fill(c);
rect(0, 10, 45, 80);
c = color('#00ff00');
fill(c);
rect(55, 10, 45, 80);
// RGB and RGBA color strings are also supported
// these all set to the same color (solid blue)
let c;
noStroke();
c = color('rgb(0,0,255)');
fill(c);
rect(10, 10, 35, 35); // Draw rectangle
c = color('rgb(0%, 0%, 100%)');
fill(c);
rect(55, 10, 35, 35); // Draw rectangle
c = color('rgba(0, 0, 255, 1)');
fill(c);
rect(10, 55, 35, 35); // Draw rectangle
c = color('rgba(0%, 0%, 100%, 1)');
fill(c);
rect(55, 55, 35, 35); // Draw rectangle
// HSL color can also be specified by value
let c = color('hsl(160, 100%, 50%)');
noStroke();
fill(c);
rect(0, 10, 45, 80); // Draw rectangle
c = color('hsla(160, 100%, 50%, 0.5)');
fill(c);
rect(55, 10, 45, 80); // Draw rectangle
// HSB color can also be specified
let c = color('hsb(160, 100%, 50%)');
noStroke();
fill(c);
rect(0, 10, 45, 80); // Draw rectangle
c = color('hsba(160, 100%, 50%, 0.5)');
fill(c);
rect(55, 10, 45, 80); // Draw rectangle
noStroke();
let c = color(50, 55, 100);
fill(c);
rect(0, 10, 45, 80); // Draw left rect
colorMode(HSB, 100);
c = color(50, 55, 100);
fill(c);
rect(55, 10, 45, 80);

Overloads

gray number specifying value between white and black.

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


v1 red or hue value relative to the current color range

v2 green or saturation value relative to the current color range

v3 blue or brightness value relative to the current color range

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


value a color string


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


color