added __getitem__ for iterable behavior
This commit is contained in:
parent
d2401aaf5e
commit
8edbf4cffc
1 changed files with 30 additions and 0 deletions
|
|
@ -114,6 +114,21 @@ class CRGB(object):
|
|||
def __str__(self):
|
||||
return "(%s, %s, %s)" % (self.red, self.green, self.blue)
|
||||
|
||||
def __len__(self):
|
||||
"""Retrieve total number of color-parts available."""
|
||||
return 3
|
||||
|
||||
def __getitem__(self, key):
|
||||
"""Retrieve red, green or blue value as iterable."""
|
||||
if key is 0:
|
||||
return self.red
|
||||
elif key is 1:
|
||||
return self.green
|
||||
elif key is 2:
|
||||
return self.blue
|
||||
else:
|
||||
raise IndexError
|
||||
|
||||
def pack(self):
|
||||
"""'Pack' a `CRGB` color into a 24-bit RGB integer.
|
||||
|
||||
|
|
@ -164,6 +179,21 @@ class CHSV(object):
|
|||
def __str__(self):
|
||||
return "(%s, %s, %s)" % (self.hue, self.saturation, self.value)
|
||||
|
||||
def __len__(self):
|
||||
"""Retrieve total number of 'color-parts' available."""
|
||||
return 3
|
||||
|
||||
def __getitem__(self, key):
|
||||
"""Retrieve hue, saturation or value as iterable."""
|
||||
if key is 0:
|
||||
return self.hue
|
||||
elif key is 1:
|
||||
return self.saturation
|
||||
elif key is 2:
|
||||
return self.value
|
||||
else:
|
||||
raise IndexError
|
||||
|
||||
def pack(self):
|
||||
"""'Pack' a `CHSV` color into a 24-bit RGB integer.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue