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.
66 .. class:: gradient(min=0, max=1)
68 This class provides the methods for the ``gradient``. Different initializations
69 can be found in ``lineargradient`` and ``functiongradient``.
71 *min* and *max* provide the valid range of the arguments for ``getcolor``.
74 .. function:: getcolor(parameter)
76 Returns the color that corresponds to *parameter* (must be between *min* and
80 .. function:: select(index, n_indices)
82 When a total number of *n_indices* different colors is needed from the gradient,
83 this method returns the *index*-th color.
86 .. class:: lineargradient(startcolor, endcolor, min=0, max=1)
88 This class provides a linear transition between two given colors. The linear
89 interpolation is performed on the color components of the specific color model.
91 *startcolor* and *endcolor* must be colors of the same color model.
94 .. class:: functiongradient(functions, type, min=0, max=1)
96 This class provides an arbitray transition between colors of the same color
99 *type* is a string indicating the color model (one of ``"cmyk"``, ``"rgb"``,
100 ``"hsb"``, ``"grey"``)
102 *functions* is a dictionary that maps the color components onto given functions.
103 E.g. for ``type="rgb"`` this dictionary must have the keys ``"r"``, ``"g"``, and
106 .. class:: class rgbgradient(gradient)
108 This class takes an arbitrary gradient and converts it into one in the RGB color model.
109 This is useful for instance in bitmap output, where only certain color models
110 are supported in Postscript/PDF.
112 .. class:: class cmykgradient(gradient)
114 This class takes an arbitrary gradient and converts it into one in the CMYK color mode.
115 This is useful for instance in bitmap output, where only certain color models
116 are supported in Postscript/PDF.
124 .. class:: transparency(value)
126 Instances of this class will make drawing operations (stroking, filling) to
127 become partially transparent. *value* defines the transparency factor in the
128 range ``0`` (opaque) to ``1`` (transparent).
130 Transparency is available in PDF output only since it is not supported by
131 PostScript. However, for certain ghostscript devices (for example the pdf
132 backend as used by ps2pdf) proprietary PostScript extension allows for
133 transparency in PostScript code too. PyX creates such PostScript proprietary
134 code, but issues a warning when doing so.