12 PostScript provides different color models. They are available to PyX by
13 different color classes, which just pass the colors down to the PostScript
14 level. This implies, that there are no conversion routines between different
15 color models available. However, some color model conversion routines are
16 included in Python's standard library in the module ``colorsym``. Furthermore
17 also the comparison of colors within a color model is not supported, but might
18 be added in future versions at least for checking color identity and for
21 There is a class for each of the supported color models, namely ``gray``,
22 ``rgb``, ``cmyk``, and ``hsb``. The constructors take variables appropriate for
23 the color model. Additionally, a list of named colors is given in appendix
36 c.fill(path.rect(0, 0, 7, 3), [color.gray(0.8)])
37 c.fill(path.rect(1, 1, 1, 1), [color.rgb.red])
38 c.fill(path.rect(3, 1, 1, 1), [color.rgb.green])
39 c.fill(path.rect(5, 1, 1, 1), [color.rgb.blue])
41 c.writeEPSfile("color")
44 The file ``color.eps`` is created and looks like:
56 The color module provides a class :class:`gradient` for continous transitions between
57 colors. A list of named gradients is available in appendix :ref:`gradientname`.
59 Note that all predefined non-gray gradients are defined in the RGB color space,
60 except for `gradient.Rainbow`, `gradient.ReverseRainbow`, `gradient.Hue`, and
61 `gradient.ReverseHue`, which are naturally defined in the HSB color space. Converted
62 RGB and CMYK versions of these latter gradients are also defined under the names
63 `rgbgradient.Rainbow` and `cmykgradient.Rainbow`, etc.
68 This class defines the methods for the ``gradient``.
70 .. function:: getcolor(parameter)
72 Returns the color that corresponds to *parameter* (must be between *min* and
76 .. function:: select(index, n_indices)
78 When a total number of *n_indices* different colors is needed from the gradient,
79 this method returns the *index*-th color.
81 .. class:: functiongradient_cmyk(f_c, f_m, f_y, f_k)
82 .. class:: functiongradient_gray(f_gray)
83 .. class:: functiongradient_hsb(f_g, f_s, f_b)
84 .. class:: functiongradient_rgb(f_r, f_g, f_b)
86 This class provides an arbitray transition between colors of the same color
89 The functions *f_c*, etc. map the values [0, 1] to the respective components
92 .. function:: lineargradient_cmyk(mincolor, maxcolor)
93 .. function:: lineargradient_gray(mincolor, maxcolor)
94 .. function:: lineargradient_hsb(mincolor, maxcolor)
95 .. function:: lineargradient_rgb(mincolor, maxcolor)
97 These factory functors for the corresponding *functiongradient_* classes
98 provide a linear transition between two given instances of the same color
99 class. The linear interpolation is performed on the color components of the
100 specific color model.
102 *mincolor* and *maxcolor* must be colors of the corresponding color class.
104 .. class:: class rgbgradient(gradient)
106 This class takes an arbitrary gradient and converts it into one in the RGB color model.
107 This is useful for instance in bitmap output, where only certain color models
108 are supported in Postscript/PDF.
110 .. class:: class cmykgradient(gradient)
112 This class takes an arbitrary gradient and converts it into one in the CMYK color mode.
113 This is useful for instance in bitmap output, where only certain color models
114 are supported in Postscript/PDF.
122 .. class:: transparency(value)
124 Instances of this class will make drawing operations (stroking, filling) to
125 become partially transparent. *value* defines the transparency factor in the
126 range ``0`` (opaque) to ``1`` (transparent).
128 Transparency is available in PDF output only since it is not supported by
129 PostScript. However, for certain ghostscript devices (for example the pdf
130 backend as used by ps2pdf) proprietary PostScript extension allows for
131 transparency in PostScript code too. PyX creates such PostScript proprietary
132 code, but issues a warning when doing so.