The various color model we support will be concrete classes that share an interface defined in this base class.
# - - - - - c l a s s C o l o r M o d e l
class ColorModel:
"""Base class for color models.
Exports:
ColorModel ( modelName, labelList ):
[ (modelName is the name of this model as a string) and
(labelList is a sequence of three strings naming
the parameters of this model) ->
return a ColorModel object with those names ]
.modelName: [ as passed to constructor, read-only ]
.labelList: [ as passed to constructor, read-only ]
Functionally, a color model translates between a Color object (which internally uses RGB color
space) and a trio of parameters that describe that color in
the given model. The next two methods are the two
conversions; see Section 7.2, “ColorModel.paramsToColor()” and Section 7.3, “ColorModel.colorToParams()”.
.paramsToColor ( params ):
[ params is a sequence of three numbers in [0,MAX_PARAM] ->
return that color in self's model as a Color instance ]
.colorToParams ( color ):
[ color is a Color instance ->
return color's parameters in self's model as a
sequence of three numbers in [0,MAX_PARAM] ]
The class also contains two static methods used to
convert between numbers in [0,MAX_PARAM] and floats
in [0.0, 1.0]. See Section 7.4, “ColorModel.normalize(): Normalize an integer
color parameter”
and Section 7.5, “ColorModel.discretize(): Discretize an
integer color parameter”.
ColorModel.normalize(n):
[ n is an int in [0,MAX_PARAM] ->
return float(n)/MAX_PARAM ]
ColorModel.discretize(n):
[ n is a float in [0.0, 1.0] ->
return int(n*MAX_PARAM) ]
"""