Skip to content

Commit

Permalink
Merge pull request #5 from s-light/add_getitem
Browse files Browse the repository at this point in the history
added __getitem__ for iterable behavior
  • Loading branch information
kattni authored Mar 18, 2019
2 parents be4917d + 13bb77f commit 37c7898
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions adafruit_fancyled/adafruit_fancyled.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ def __repr__(self):
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 == 0:
return self.red
elif key == 1:
return self.green
elif key == 2:
return self.blue
else:
raise IndexError

def pack(self):
"""'Pack' a `CRGB` color into a 24-bit RGB integer.
Expand Down Expand Up @@ -164,6 +179,21 @@ def __repr__(self):
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 == 0:
return self.hue
elif key == 1:
return self.saturation
elif key == 2:
return self.value
else:
raise IndexError

def pack(self):
"""'Pack' a `CHSV` color into a 24-bit RGB integer.
Expand Down

0 comments on commit 37c7898

Please sign in to comment.