vaab / colour

Python color representations manipulation library (RGB, HSL, web, ...)
BSD 2-Clause "Simplified" License
319 stars 41 forks source link

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

Open vickipedia opened 2 years ago

vickipedia commented 2 years ago

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

kubinka0505 commented 1 year ago

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)