Color¶
Color¶
-
class
p5.
Color
(*args, color_mode=None, normed=False, **kwargs)¶ Represents a color.
-
alpha
¶ The alpha value for the color.
-
b
¶ The blue or the brightness value (depending on the color mode).
-
blue
¶ The blue component of the color
-
brightness
¶ The brightness component of the color
-
g
¶ The green component of the color
-
gray
¶ The gray-scale value of the color.
Performs a luminance conversion of the current color to grayscale.
-
green
¶ The green component of the color
-
h
¶ The hue component of the color
-
hex
¶ Returns: Color as a hex value Return type: str
-
hsb
¶ Returns: Color components in HSB. Return type: tuple
-
hsba
¶ Returns: Color components in HSBA. Return type: tuple
-
hue
¶ The hue component of the color
-
lerp
(target, amount)¶ Linearly interpolate one color to another by the given amount.
Parameters: - target (Color) – The target color to lerp to.
- amount (float) – The amount by which the color should be lerped (should be a float between 0 and 1).
Returns: A new color lerped between the current color and the other color.
Return type:
-
normalized
¶ Normalized RGBA color values
-
normalized_rgb
¶ Normalized RGB color values
-
r
¶ The red component of the color
-
red
¶ The red component of the color
-
rgb
¶ Returns: Color components in RGB. Return type: tuple
-
rgba
¶ Returns: Color components in RGBA. Return type: tuple
-
s
¶ The saturation component of the color
-
saturation
¶ The saturation component of the color
-
v
¶ The brightness component of the color
-
value
¶ The brightness component of the color
-
color_mode()¶
-
p5.
color_mode
(mode, max_1=255, max_2=None, max_3=None, max_alpha=255)¶ Set the color mode of the renderer.
Parameters: - mode (str) – One of {‘RGB’, ‘HSB’} corresponding to Red/Green/Blue or Hue/Saturation/Brightness
- max_1 (int) – Maximum value for the first color channel (default: 255)
- max_2 (int) – Maximum value for the second color channel (default: max_1)
- max_3 (int) – Maximum value for the third color channel (default: max_1)
- max_alpha (int) – Maximum value for the alpha channel (default: 255)
background()¶
-
p5.
background
(*args, **kwargs)¶ Set the background color for the p5.renderer.
Parameters: - args – positional arguments to be parsed as a color.
- kwargs (dict) – keyword arguments to be parsed as a color.
Note: Both args and color_kwargs are directly sent to color.parse_color
Note: When setting an image as the background, the dimensions of the image should be the same as that of the sketch window.
Returns: The background color or image.
Return type: p5.Color | p5.PImage
Raises: ValueError – When the dimensions of the image and the sketch do not match.
fill()¶
-
p5.
fill
(*fill_args, **fill_kwargs) Set the fill color of the shapes.
Parameters: - fill_args (tuple) – positional arguments to be parsed as a color.
- fill_kwargs (dict) – keyword arguments to be parsed as a color.
Returns: The fill color.
Return type:
no_fill()¶
-
p5.
no_fill
() Disable filling geometry.
stroke()¶
-
p5.
stroke
(*color_args, **color_kwargs) Set the color used to draw lines around shapes
Parameters: - color_args (tuple) – positional arguments to be parsed as a color.
- color_kwargs (dict) – keyword arguments to be parsed as a color.
Note: Both color_args and color_kwargs are directly sent to Color.parse_color
Returns: The stroke color.
Return type:
no_stroke()¶
-
p5.
no_stroke
() Disable drawing the stroke around shapes.