Skip to content

Commit

Permalink
add rgba property
Browse files Browse the repository at this point in the history
  • Loading branch information
xav committed Aug 14, 2016
1 parent fb7bda2 commit 41ab79e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions grapefruit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1530,6 +1530,16 @@ def rgb(self, value):
self.__rgb = tuple([float(v) for v in value])
self.__hsl = rgb_to_hsl(*self.__rgb)

@property
def rgba(self):
"""The RGBA values of this Color."""
return (self.__rgb + (self.__a,))
@rgba.setter
def rgba(self, value):
self.__rgb = tuple([float(v) for v in value[:3]])
self.__a = float(value[3])
self.__hsl = rgb_to_hsl(*self.__rgb)

@property
def red(self):
return self.__rgb[0]
Expand Down
10 changes: 10 additions & 0 deletions grapefruit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ def test_set_rgb(self):
assert_equal(col.rgb, (0.1, 0.2, 0.3))
assert_equal(col.hsl, grapefruit.rgb_to_hsl(0.1, 0.2, 0.3))

def test_get_rgba(self):
col = grapefruit.Color.from_rgb(1.0, 0.5, 0.0)
assert_equal(col.rgba, (1, 0.5, 0, 1))
def test_set_rgba(self):
col = grapefruit.Color.from_rgb(1.0, 0.5, 0.0)
col.rgba = (0.1, 0.2, 0.3, 0.5)
assert_equal(col.rgb, (0.1, 0.2, 0.3))
assert_equal(col.alpha, 0.5)
assert_equal(col.hsl, grapefruit.rgb_to_hsl(0.1, 0.2, 0.3))

def test_get_red(self):
col = grapefruit.Color.from_rgb(0.1, 0.2, 0.3)
assert_equal(col.red, 0.1)
Expand Down

0 comments on commit 41ab79e

Please sign in to comment.