add docs to the bitmap examples and move the julia bitmap example to the gallery
[PyX.git] / manual / color.tex
blob55a674206ce31e97dc15bb7a64272e9ea62eadb8
1 \chapter{Module color}
2 \label{color}
3 \section{Color models}
4 PostScript provides different color models. They are available to
5 \PyX{} by different color classes, which just pass the colors down to
6 the PostScript level. This implies, that there are no conversion
7 routines between different color models available. However, some color
8 model conversion routines are included in Python's standard library in
9 the module \texttt{colorsym}. Furthermore also the comparison of
10 colors within a color model is not supported, but might be added in
11 future versions at least for checking color identity and for ordering
12 gray colors.
14 There is a class for each of the supported color models, namely
15 \verb|gray|, \verb|rgb|, \verb|cmyk|, and \verb|hsb|. The constructors
16 take variables appropriate for the color model. Additionally, a list of
17 named colors is given in appendix~\ref{colorname}.
19 \section{Example}
20 \begin{quote}
21 \begin{verbatim}
22 from pyx import *
24 c = canvas.canvas()
26 c.fill(path.rect(0, 0, 7, 3), [color.gray(0.8)])
27 c.fill(path.rect(1, 1, 1, 1), [color.rgb.red])
28 c.fill(path.rect(3, 1, 1, 1), [color.rgb.green])
29 c.fill(path.rect(5, 1, 1, 1), [color.rgb.blue])
31 c.writeEPSfile("color")
32 \end{verbatim}
33 \end{quote}
35 The file \verb|color.eps| is created and looks like:
36 \begin{quote}
37 \includegraphics{color}
38 \end{quote}
40 \section{Color palettes}
42 The color module provides a class \verb|palette| for transitions between
43 colors. A list of named palettes is available in appendix~\ref{palettename}.
45 \begin{classdesc}{palette}{min=0, max=1}
46 This class provides the methods for the \verb|palette|. Different
47 initializations can be found in \verb|linearpalette| and \verb|functionpalette|.
49 \var{min} and \var{max} provide the valid range of the arguments for
50 \verb|getcolor|.
52 \begin{funcdesc}{getcolor}{parameter}
53 Returns the color that corresponds to \var{parameter} (must be between
54 \var{min} and \var{max}).
55 \end{funcdesc}
57 \begin{funcdesc}{select}{index, n\_indices}
58 When a total number of \var{n\_indices} different colors is needed from the
59 palette, this method returns the \var{index}-th color.
60 \end{funcdesc}
62 \end{classdesc}
65 \begin{classdesc}{linearpalette}{startcolor, endcolor, min=0, max=1}
66 This class provides a linear transition between two given colors. The linear
67 interpolation is performed on the color components of the specific color
68 model.
70 \var{startcolor} and \var{endcolor} must be colors of the same color model.
71 \end{classdesc}
73 \begin{classdesc}{functionpalette}{functions, type, min=0, max=1}
74 This class provides an arbitray transition between colors of the same
75 color model.
77 \var{type} is a string indicating the color model (one of \code{"cmyk"},
78 \code{"rgb"}, \code{"hsb"}, \code{"grey"})
80 \var{functions} is a dictionary that maps the color components onto given
81 functions. E.g. for \code{type="rgb"} this dictionary must have the keys
82 \code{"r"}, \code{"g"}, and \code{"b"}.
84 \end{classdesc}