Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vickipedia opened this issue May 13, 2022 · 1 comment

Comments

@vickipedia
Copy link

vickipedia commented May 13, 2022

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 vickipedia changed the title Colour("lime").rgb returns (0.0, 1.0, 3.3306690738754696e-16) instead of (0.0, 1.0, 0.0) Color("lime").rgb returns (0.0, 1.0, 3.3306690738754696e-16) instead of (0.0, 1.0, 0.0) May 13, 2022
@kubinka0505
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants