colour icon indicating copy to clipboard operation
colour copied to clipboard

Color("lime").rgb returns (0.0, 1.0, 3.3306690738754696e-16) instead of (0.0, 1.0, 0.0)

Open vickipedia opened this issue 3 years ago • 1 comments

Trying to generate a Colour object using 0, 255, 0 RGB value and read back the rgb tuple. Getting a exponential negative value in place of blue.

Also tried,

Color("lime").rgb Color("#00FF00").rgb Color(rgb=(0,1,0)).rgb

vickipedia avatar May 13 '22 02:05 vickipedia

Strange, but seems to work. It needs to be implemented asap.

from colour import Color

# Function
def get_rgb(cols: Color) -> tuple:
    ret = []
    for Value in cols.rgb:
        ret += [round(Value * 255) // 1]
    return tuple(ret)

# List comprehension
tuple([round(Value * 255) // 1 for Value in Color(...).rgb])

Display

>>> Colors = "red", "green", "blue", "yellow", "#FACADE"
>>> Colors = [Color(c) for c in Colors]
>>> 
>>> for x in Colors:
...     print(
...         x.hex_l.upper(),
...         get_rgb(x)
...     )
...
#FF0000  (255, 0, 0)
#008000  (0, 128, 0)
#0000FF  (0, 0, 255)
#FFFF00  (255, 255, 0)
#FACADE  (250, 202, 222)

kubinka0505 avatar Jan 06 '23 17:01 kubinka0505