Merge pull request #487 from stefanfrick/separate_rgb

Added red, green and blue properties to Color class.
This commit is contained in:
dylan 2020-02-20 18:55:23 +02:00 committed by GitHub
commit 94b0ca5806
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -58,6 +58,21 @@ class Color:
"""Strip '#' from color."""
return self.hex_color[1:]
@property
def red(self):
"""Red value as float between 0 and 1."""
return "%.3f" % (hex_to_rgb(self.hex_color)[0]/255.)
@property
def green(self):
"""Green value as float between 0 and 1."""
return "%.3f" % (hex_to_rgb(self.hex_color)[1]/255.)
@property
def blue(self):
"""Blue value as float between 0 and 1."""
return "%.3f" % (hex_to_rgb(self.hex_color)[2]/255.)
def lighten(self, percent):
"""Lighten color by percent"""
percent = float(re.sub(r'[\D\.]', '', str(percent)))