| 1 |
% Copyright 2019 by Till Tantau |
| 2 |
% |
| 3 |
% This file may be distributed and/or modified |
| 4 |
% |
| 5 |
% 1. under the LaTeX Project Public License and/or |
| 6 |
% 2. under the GNU Free Documentation License. |
| 7 |
% |
| 8 |
% See the file doc/generic/pgf/licenses/LICENSE for more details. |
| 9 |
|
| 10 |
|
| 11 |
\section{Shadings Library} |
| 12 |
\label{section-library-shadings} |
| 13 |
|
| 14 |
\begin{pgflibrary}{shadings} |
| 15 |
The package defines a number of shadings in addition to the ball and axis |
| 16 |
shadings that are available by default. |
| 17 |
\end{pgflibrary} |
| 18 |
|
| 19 |
In the following, the shadings defined in the library are listed in |
| 20 |
alphabetical order. The colors of some of these shadings can be configured |
| 21 |
using special options (like |left color|). These options implicitly select the |
| 22 |
shading. |
| 23 |
|
| 24 |
The three shadings |axis|, |ball|, and |radial| are always defined, even when |
| 25 |
this library is not used. |
| 26 |
|
| 27 |
\begin{shading}{axis} |
| 28 |
In this always-defined shading the colors change gradually between three |
| 29 |
horizontal lines. The top line is at the top (uppermost) point of the path, |
| 30 |
the middle is in the middle, the bottom line is at the bottom of the path. |
| 31 |
% |
| 32 |
\begin{key}{/tikz/top color=\meta{color}} |
| 33 |
This option sets the color to be used at the top in an |axis| shading. |
| 34 |
When this option is given, several things happen: |
| 35 |
% |
| 36 |
\begin{enumerate} |
| 37 |
\item The |shade| option is selected. |
| 38 |
\item The |shading=axis| option is selected. |
| 39 |
\item The middle color of the axis shading is set to the average of |
| 40 |
the given top color \meta{color} and of whatever color is |
| 41 |
currently selected for the bottom. |
| 42 |
\item The rotation angle of the shading is set to 0. |
| 43 |
\end{enumerate} |
| 44 |
% |
| 45 |
\begin{codeexample}[preamble={\usepgflibrary{shadings}}] |
| 46 |
\tikz \draw[top color=red] (0,0) rectangle (2,1); |
| 47 |
\end{codeexample} |
| 48 |
\end{key} |
| 49 |
|
| 50 |
\begin{key}{/tikz/bottom color=\meta{color}} |
| 51 |
This option works like |top color|, only for the bottom color. |
| 52 |
\end{key} |
| 53 |
|
| 54 |
\begin{key}{/tikz/middle color=\meta{color}} |
| 55 |
This option specifies the color for the middle of an axis shading. It |
| 56 |
also sets the |shade| and |shading=axis| options, but it does not |
| 57 |
change the rotation angle. |
| 58 |
|
| 59 |
\emph{Note:} Since both |top color| and |bottom color| change the |
| 60 |
middle color, this option should be given \emph{last} if all of these |
| 61 |
options need to be given: |
| 62 |
% |
| 63 |
\begin{codeexample}[preamble={\usepgflibrary{shadings}}] |
| 64 |
\tikz \draw[top color=white,bottom color=black,middle color=red] |
| 65 |
(0,0) rectangle (2,1); |
| 66 |
\end{codeexample} |
| 67 |
\end{key} |
| 68 |
|
| 69 |
\begin{key}{/tikz/left color=\meta{color}} |
| 70 |
This option does exactly the same as |top color|, except that the |
| 71 |
shading angle is set to $90^\circ$. |
| 72 |
\end{key} |
| 73 |
|
| 74 |
\begin{key}{/tikz/right color=\meta{color}} |
| 75 |
Works like |left color|. |
| 76 |
\end{key} |
| 77 |
\end{shading} |
| 78 |
|
| 79 |
\begin{shading}{ball} |
| 80 |
This always-defined shading fills the path with a shading that ``looks like |
| 81 |
a ball''. The default ``color'' of the ball is blue (for no particular |
| 82 |
reason). |
| 83 |
|
| 84 |
\begin{key}{/tikz/ball color=\meta{color}} |
| 85 |
This option sets the color used for the ball shading. It sets the |
| 86 |
|shade| and |shading=ball| options. Note that the ball will never |
| 87 |
``completely'' have the color \meta{color}. At its ``highlight'' spot a |
| 88 |
certain amount of white is mixed in, at the border a certain amount of |
| 89 |
black. Because of this, it also makes sense to say |ball color=white| |
| 90 |
or |ball color=black| |
| 91 |
% |
| 92 |
\begin{codeexample}[preamble={\usepgflibrary{shadings}}] |
| 93 |
\begin{tikzpicture} |
| 94 |
\shade[ball color=white] (0,0) circle (2ex); |
| 95 |
\shade[ball color=red] (1,0) circle (2ex); |
| 96 |
\shade[ball color=black] (2,0) circle (2ex); |
| 97 |
\end{tikzpicture} |
| 98 |
\end{codeexample} |
| 99 |
\end{key} |
| 100 |
\end{shading} |
| 101 |
|
| 102 |
\begin{shading}{bilinear interpolation} |
| 103 |
This shading fills a rectangle with colors that a bilinearly interpolated |
| 104 |
between the colors in the four corners of the rectangle. These four colors |
| 105 |
are called |lower left|, |lower right|, |upper left|, and |upper right|. By |
| 106 |
changing these color, you can change the way the shading looks. The library |
| 107 |
also defines four options, called the same way, that can be used to set |
| 108 |
these colors and select the shading implicitly. |
| 109 |
% |
| 110 |
\begin{codeexample}[preamble={\usepgflibrary{shadings}}] |
| 111 |
\tikz |
| 112 |
\shade[upper left=red,upper right=green, |
| 113 |
lower left=blue,lower right=yellow] |
| 114 |
(0,0) rectangle (3,2); |
| 115 |
\end{codeexample} |
| 116 |
|
| 117 |
\begin{key}{/tikz/lower left=\meta{color} (initially white)} |
| 118 |
Sets the color to be used in a |bilinear interpolation| shading for the |
| 119 |
lower left corner. Also, this options selects this shading and sets the |
| 120 |
|shade| option. |
| 121 |
\end{key} |
| 122 |
|
| 123 |
\begin{key}{/tikz/upper left=\meta{color} (initially white)} |
| 124 |
Works like |lower left|. |
| 125 |
\end{key} |
| 126 |
|
| 127 |
\begin{key}{/tikz/upper right=\meta{color} (initially white)} |
| 128 |
Works like |lower left|. |
| 129 |
\end{key} |
| 130 |
|
| 131 |
\begin{key}{/tikz/lower right=\meta{color} (initially white)} |
| 132 |
Works like |lower left|. |
| 133 |
\end{key} |
| 134 |
\end{shading} |
| 135 |
|
| 136 |
\begin{shading}{color wheel} |
| 137 |
\label{shading-color-wheel}% |
| 138 |
This shading fills the path with a color wheel. |
| 139 |
% |
| 140 |
\begin{codeexample}[preamble={\usepgflibrary{shadings}}] |
| 141 |
\tikz \shade[shading=color wheel] (0,0) circle (1.5); |
| 142 |
\end{codeexample} |
| 143 |
% |
| 144 |
To produce a color ring, cut out a circle from the color wheel: |
| 145 |
% |
| 146 |
\begin{codeexample}[preamble={\usepgflibrary{shadings}}] |
| 147 |
\tikz \shade[shading=color wheel] [even odd rule] |
| 148 |
(0,0) circle (1.5) |
| 149 |
(0,0) circle (1); |
| 150 |
\end{codeexample} |
| 151 |
% |
| 152 |
\end{shading} |
| 153 |
|
| 154 |
\begin{shading}{color wheel black center} |
| 155 |
This shading looks like a color wheel, but the brightness drops to zero in |
| 156 |
the center. |
| 157 |
% |
| 158 |
\begin{codeexample}[preamble={\usepgflibrary{shadings}}] |
| 159 |
\tikz \shade[shading=color wheel black center] (0,0) circle (1.5); |
| 160 |
\end{codeexample} |
| 161 |
% |
| 162 |
\end{shading} |
| 163 |
|
| 164 |
\begin{shading}{color wheel white center} |
| 165 |
This shading looks like a color wheel, but the saturation drops to zero in |
| 166 |
the center. |
| 167 |
% |
| 168 |
\begin{codeexample}[preamble={\usepgflibrary{shadings}}] |
| 169 |
\tikz \shade[shading=color wheel white center] (0,0) circle (1.5); |
| 170 |
\end{codeexample} |
| 171 |
% |
| 172 |
\end{shading} |
| 173 |
|
| 174 |
\makeatletter |
| 175 |
\begin{shading}{Mandelbrot set} |
| 176 |
This shading is just for fun. It fills the path with a zoomable Mandelbrot |
| 177 |
set. Note that this is \emph{not} a bitmap graphic. Rather, the Mandelbrot |
| 178 |
set is \emph{computed by the \textsc{pdf} renderer} and can be zoomed |
| 179 |
arbitrarily (give it a try, if you have a fast computer). |
| 180 |
% |
| 181 |
\begin{codeexample}[preamble={\usepgflibrary{shadings}}] |
| 182 |
\tikz \shade[shading=Mandelbrot set] (0,0) rectangle (2,2); |
| 183 |
\end{codeexample} |
| 184 |
% |
| 185 |
\end{shading} |
| 186 |
\makeatother |
| 187 |
|
| 188 |
\begin{shading}{radial} |
| 189 |
This always-defined shading fills the path with a gradual sweep from a |
| 190 |
certain color in the middle to another color at the border. If the path is |
| 191 |
a circle, the outer color will be reached exactly at the border. If the |
| 192 |
shading is not a circle, the outer color will continue a bit towards the |
| 193 |
corners. The default inner color is gray, the default outer color is white. |
| 194 |
% |
| 195 |
\begin{key}{/tikz/inner color=\meta{color}} |
| 196 |
This option sets the color used at the center of a |radial| shading. |
| 197 |
When this option is used, the |shade| and |shading=radial| options are |
| 198 |
set. |
| 199 |
% |
| 200 |
\begin{codeexample}[preamble={\usepgflibrary{shadings}}] |
| 201 |
\tikz \draw[inner color=red] (0,0) rectangle (2,1); |
| 202 |
\end{codeexample} |
| 203 |
\end{key} |
| 204 |
|
| 205 |
\begin{key}{/tikz/outer color=\meta{color}} |
| 206 |
This option sets the color used at the border and outside of a |radial| |
| 207 |
shading. |
| 208 |
% |
| 209 |
\begin{codeexample}[preamble={\usepgflibrary{shadings}}] |
| 210 |
\tikz \draw[outer color=red,inner color=white] |
| 211 |
(0,0) rectangle (2,1); |
| 212 |
\end{codeexample} |
| 213 |
\end{key} |
| 214 |
\end{shading} |
| 215 |
|
| 216 |
|
| 217 |
%%% Local Variables: |
| 218 |
%%% mode: latex |
| 219 |
%%% TeX-master: "pgfmanual-pdftex-version" |
| 220 |
%%% End: |