alpha()#

Extracts the alpha value from a color, scaled to match current color_mode().

Examples#

example picture for alpha()
1def setup():
2    py5.no_stroke()
3    c = py5.color(0, 126, 255, 102)
4    py5.fill(c)
5    py5.rect(15, 15, 35, 70)
6    value = py5.alpha(c)  # sets 'value' to 102
7    py5.fill(value)
8    py5.rect(50, 15, 35, 70)

Description#

Extracts the alpha value from a color, scaled to match current color_mode().

The alpha() function is easy to use and understand, but it is slower than a technique called bit shifting. When working in color_mode(RGB, 255), you can achieve the same results as alpha() but with greater speed by using the right shift operator (>>) with a bit mask. For example, alpha(c) and c >> 24 & 0xFF both extract the alpha value from a color variable c but the later is faster.

Underlying Processing method: alpha

Syntax#

alpha(rgb: int, /) -> float

Parameters#

  • rgb: int - any value of the color datatype

Updated on November 12, 2021 11:30:58am UTC