color or first color component
Optionalc1: numbersecond color component
Optionalc2: numberthird color component
Optionalc3: numberfourth color component (alpha)
a new Color object
await Canvas(200);
rect(-100, -100, 100, 200);
// ( r, g, b, a)
let bottle = color(0.35, 0.39, 1, 0.4);
fill(bottle);
stroke(bottle);
strokeWeight(30);
circle(0, 0, 155);
🎨 Creates a new
Colorobject, which is primarily useful for storing a color that your sketch will reuse or modify later.With the default color mode, RGB, colors have
r/red,g/green,b/blue, anda/alphacomponents.The
fill,stroke, andbackgroundfunctions accept the same wide range of color representations as this function.The default color format is "float", so set color components to values between 0 and 1.
Here are some examples of valid use:
color(1)(grayscale)color(1, 0.8)(grayscale, alpha)color(1, 0, 0)(r, g, b)color(1, 0, 0, 0.1)(r, g, b, a)color('red')(colorName)color('#ff0000')(hexColor)color([1, 0, 0])(colorComponents)