Skip to content

Commit

Permalink
Restrict values to safe ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrobenolt committed May 16, 2012
1 parent c878dc7 commit 7625f26
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class HSVColor(Color):
""" Hue Saturation Value """

def __init__(self, h=0, s=0, v=0):
self._color = h, s, v
# No values can be greater than 1
self._color = map(lambda c: c - 1 if c >= 1 else c, (h, s, v))

@property
def rgb(self):
Expand All @@ -97,6 +98,9 @@ class RGBColor(Color):

def __init__(self, r=0, g=0, b=0):
self._color = r, g, b
for c in self._color:
if c < 0 or c > 255:
raise ValueError('Color values must be between 0 and 255')

@property
def rgb(self):
Expand Down Expand Up @@ -159,6 +163,9 @@ class ColorWheel(object):
"""
def __init__(self, start=0):
# A 1.1 shift is identical to 0.1
if start >= 1:
start -= 1
self._phase = start

def __iter__(self):
Expand All @@ -167,7 +174,7 @@ def __iter__(self):
def next(self):
shift = (random_.random() * 0.1) + 0.1
self._phase += shift
if self._phase > 1:
if self._phase >= 1:
self._phase -= 1
return HSVColor(self._phase, 1, 0.8)

Expand Down

0 comments on commit 7625f26

Please sign in to comment.