This method takes care of translating float-type arguments for color components into the standard integer range.
# - - - C o l o r . _ _ s t a n d a r d i z e
def __standardize ( self, rawValue ):
"""Standardize representation of a color component.
[ if rawValue is a float in [0.0, 1.0] ->
return int ( rawValue * MAX_PARAM )
if rawValue is an int in [0, MAX_PARAM] ->
return rawValue
else -> raise ValueError ]
"""
if type(rawValue) is float:
if not 0.0 <= rawValue <= 1.0:
raise ValueError, ( "Float color value %.4f "
"out of bounds." % rawValue )
return int ( rawValue * MAX_PARAM )
elif type(rawValue) is int:
if not 0 <= rawValue <= MAX_PARAM:
raise ValueError, ( "Int color value %d "
"out of bounds." % rawValue )
return rawValue
else:
raise ValueError, ( "Color component %s "
"not int or float." % rawValue )