| 1 |
%\iffalse -*-mode:Latex;tex-command:"latex *;dvips pst-slpe -o"-*- \fi |
| 2 |
%\iffalse |
| 3 |
% |
| 4 |
% Copyright 1998-2008 Martin Giese, [email protected] |
| 5 |
% Herbert Voss (using xkeyval,\psBall,fading) |
| 6 |
% |
| 7 |
%% This program can be redistributed and/or modified under the terms |
| 8 |
%% of the LaTeX Project Public License Distributed from CTAN archives |
| 9 |
%% in directory macros/latex/base/lppl.txt. |
| 10 |
%% |
| 11 |
%\fi |
| 12 |
% \changes{v1.31}{2011/10/25}{ fix bug in psball (hv)} |
| 13 |
% \changes{v1.3}{2008/09/20}{ fading option (hv)} |
| 14 |
% \changes{v1.2}{2008/06/19}{ \textbackslash psBall (hv)} |
| 15 |
% \changes{v1.1}{2006/06/19}{% |
| 16 |
% using the extended pst-xkey instead of the old pst-key package; |
| 17 |
% creating a dtx file (hv)} |
| 18 |
% \changes{v1.0}{2005/03/05}{More compatible to the other PStricks |
| 19 |
% packages. (RN)} |
| 20 |
% |
| 21 |
% |
| 22 |
% \DoNotIndex{\!,\",\#,\$,\%,\&,\',\(,\+,\*,\,,\-,\.,\/,\:,\;,\<,\=,\>,\?} |
| 23 |
% \DoNotIndex{\@,\@B,\@K,\@cTq,\@f,\@fPl,\@ifnextchar,\@nameuse,\@oVk} |
| 24 |
% \DoNotIndex{\[,\\,\],\^,\_,\ } |
| 25 |
% \DoNotIndex{\^,\\^,\\\^,$\^$,$\\^$,$\\^$} |
| 26 |
% \DoNotIndex{\0,\2,\4,\5,\6,\7,\8,} |
| 27 |
% \DoNotIndex{\A,\a} |
| 28 |
% \DoNotIndex{\B,\b,\Bc,\begin,\Bq,\Bqc} |
| 29 |
% \DoNotIndex{\C,\c,\catcode,\cJA,\CodelineIndex,\csname} |
| 30 |
% \DoNotIndex{\D,\def,\define@key,\Df,\divide,\DocInput,\documentclass,\pst@addfams} |
| 31 |
% \DoNotIndex{\eCN,\edef,\else,\eHd,\eMcj,\EnableCrossrefs,\end,\endcsname} |
| 32 |
% \DoNotIndex{\endCenterExample,\endExample,\endinput,\endpsclip} |
| 33 |
% \DoNotIndex{\PrintIndex,\PrintChanges,\ProvidesFile} |
| 34 |
% \DoNotIndex{\endpspicture,\endSideBySideExample,\Example} |
| 35 |
% \DoNotIndex{\F,\f,\FdUrr,\fi,\filedate,\fileversion,\FV@Environment} |
| 36 |
% \DoNotIndex{\FV@UseKeyValues,\FV@XRightMargin,\FVB@Example,\fvset} |
| 37 |
% \DoNotIndex{\G,\g,\GetFileInfo,\gr,\GradientLoaded,\gsFKrbK@o,\gsj,\gsOX} |
| 38 |
% \DoNotIndex{\hbadness,\hfuzz,\HLEmphasize,\HLMacro,\HLMacro@i} |
| 39 |
% \DoNotIndex{\HLReverse,\HLReverse@i,\hqcu,\HqY} |
| 40 |
% \DoNotIndex{\I,\i,\ifx,\input,\Ir,\IU} |
| 41 |
% \DoNotIndex{\j,\jl,\JT,\JVodH} |
| 42 |
% \DoNotIndex{\K,\k,\kfSlL} |
| 43 |
% \DoNotIndex{\L,\let} |
| 44 |
% \DoNotIndex{\message,\mHNa,\mIU} |
| 45 |
% \DoNotIndex{\N,\nB,\newcmykcolor,\newdimen,\newif,\nW} |
| 46 |
% \DoNotIndex{\O,\oCDJDo,\ocQhVI,\OnlyDescription,\oRKJ} |
| 47 |
% \DoNotIndex{\P,\p,\ProvidesPackage,\psframe,\pslinewidth,\psset} |
| 48 |
% \DoNotIndex{\PstAtCode,\PSTricksLoaded} |
| 49 |
% \DoNotIndex{\q,\Qr,\qssRXq,\qu,\qXjFQp,\qYL} |
| 50 |
% \DoNotIndex{\R,\r,\RecordChanges,\relax,\RlaYI,\rN,\Rp,\rp,\RPDXNn,\rput} |
| 51 |
% \DoNotIndex{\S,\scalebox,\SgY,\SideBySide@Example,\SideBySideExample} |
| 52 |
% \DoNotIndex{\SgY,\sk,\Sp,\space,\sZb} |
| 53 |
% \DoNotIndex{\T,\the,\tw@} |
| 54 |
% \DoNotIndex{\u,\UiSWGEf@,\uJi,\usepackage,\uVQdMM,\UYj} |
| 55 |
% \DoNotIndex{\VerbatimEnvironment,\VerbatimInput,\VrC@} |
| 56 |
% \DoNotIndex{\WhZ,\WjKCYb,\WNs} |
| 57 |
% \DoNotIndex{\XkN,\XW} |
| 58 |
% \DoNotIndex{\Z,\ZCM,\Ze} |
| 59 |
% \DoNotIndex{\addtocounter,\advance,\alph,\arabic,\AtBeginDocument,\AtEndDocument} |
| 60 |
% \DoNotIndex{\AtEndOfPackage,\begingroup,\bfseries,\bgroup,\box,\csname} |
| 61 |
% \DoNotIndex{\else,\endcsname,\endgroup,\endinput,\expandafter,\fi} |
| 62 |
% \DoNotIndex{\TeX,\z@,\p@,\@one,\xdef,\thr@@,\string,\sixt@@n,\reset,\or,\multiply,\repeat,\RequirePackage} |
| 63 |
% \DoNotIndex{\@cclvi,\@ne,\@ehpa,\@nil,\copy,\dp,\global,\hbox,\hss,\ht,\ifodd,\ifdim,\ifcase,\kern} |
| 64 |
% \DoNotIndex{\chardef,\loop,\leavevmode,\ifnum,\lower} |
| 65 |
% \setcounter{IndexColumns}{2} |
| 66 |
% |
| 67 |
%\iffalse |
| 68 |
%<*!prolog> |
| 69 |
\def\pstslpefileversion{1.31} |
| 70 |
\def\pstslpefiledate{2011/10/25} |
| 71 |
%</!prolog> |
| 72 |
%\fi |
| 73 |
% |
| 74 |
% \title{\textsf{pst-slpe} package \\ version \pstslpefileversion} |
| 75 |
% \author{Martin Giese\footnote{\texttt{[email protected]}} and |
| 76 |
% Herbert Vo\ss\footnote{\texttt{[email protected]}}} |
| 77 |
% \date{\pstslpefiledate} |
| 78 |
% \maketitle |
| 79 |
% |
| 80 |
%\section{Introduction} |
| 81 |
%As of the 97 release, PSTricks contains the |pst-grad| |
| 82 |
%package, which provides a gradient fill style for arbitrary shapes. |
| 83 |
%Although it often produces nice results, it has a number of |
| 84 |
%deficiencies: |
| 85 |
%\begin{enumerate} |
| 86 |
%\item It is not possible to go from a colour $A$ to $B$ to $C$, |
| 87 |
%etc. The most evident application of such a multi-colour gradient are |
| 88 |
%of course rainbow effects. But they can also be useful in informative |
| 89 |
%contexts, eg to identify modes of operation in a scale of values |
| 90 |
%(normal/danger/overload). |
| 91 |
%\item Colours are interpolated linearly in the RGB space. This is |
| 92 |
%often OK, but when you want to go from red $(1,0,0)$ to green |
| 93 |
%$(0,1,0)$, it looks much better to get there via yellow $(1,1,0)$ than |
| 94 |
%via brown $(0.5,0.5,0)$. The point is, that to get from one saturated |
| 95 |
%colour to another, the colours on the way should also be saturated to |
| 96 |
%produce an optically pleasing result. |
| 97 |
%\item |pst-grad| is limited to {\em linear} gradients, ie~there |
| 98 |
%is a (possibly rotated) rectilinear coordinate system, such that the |
| 99 |
%colour at every point depends only on the $x$ coordinate of the |
| 100 |
%point. In particular, there is no way to get circular patterns. |
| 101 |
%\end{enumerate} |
| 102 |
%|pst-slpe| solves {\em all} of the mentioned |
| 103 |
%problems in {\em one} package. |
| 104 |
% |
| 105 |
%Problems 1.~is addressed by permitting the user to specify an |
| 106 |
%arbitrary number of colours, along with the points at which these are |
| 107 |
%to be reached. A special form of each of the fill styles is provided, |
| 108 |
%which just needs two colours as parameters, and goes from one to the |
| 109 |
%other. This makes the fill styles easier to use in that simple case. |
| 110 |
% |
| 111 |
%Problem 2.~is solved by interpolating in the hue-saturation-value |
| 112 |
%colour space. Conversion between RGB and HSV is done behind the |
| 113 |
%scenes. The user specifies colours in RGB. |
| 114 |
% |
| 115 |
%Finally, |pst-slpe| provides {\em concentric} and {\em radial} |
| 116 |
%gradients. What these mean is best explained with a polar coordinate |
| 117 |
%system: In a concentric pattern, the colour of a point depends on the |
| 118 |
%radius coordinate, while in a radial pattern, it depends on the angle |
| 119 |
%coordinate. |
| 120 |
% |
| 121 |
%As a special bonus, the PostScript part of |pst-slpe| is somewhat |
| 122 |
%optimized for speed. In |ghostscript|, rendering is about 30\% faster |
| 123 |
%than with |pst-grad|. |
| 124 |
%\medskip |
| 125 |
% |
| 126 |
%For most of these problems, solutions have been posted in the |
| 127 |
%appropriate \TeX\ newsgroup over the years. |pst-slpe| has however |
| 128 |
%been developed independently from these proposals. It is based on |
| 129 |
%the original PSTricks 0.93 |gradient| code, most of which has been |
| 130 |
%changed or replaced. The |
| 131 |
%author is indebted to Denis Girou, whose encouragement triggered the |
| 132 |
%process of making this a shipable package instead of a private |
| 133 |
%experiment. |
| 134 |
%\medskip |
| 135 |
% |
| 136 |
%The new fill styles and the |
| 137 |
%graphics parameters provided to use them are described in |
| 138 |
%section 2 of this document. Section 3, if present, documents the |
| 139 |
%implementation consisting of a generic \TeX\ file and a PostScript |
| 140 |
%header for the |dvi|-to-PostScript converter. You can get section 3 |
| 141 |
%by calling \LaTeX\ as follows on most relevant systems: |
| 142 |
%\begin{verbatim} |
| 143 |
%latex '\AtBeginDocument{\AlsoImplementation}\input{pst-slpe.dtx}' |
| 144 |
%\end{verbatim} |
| 145 |
%\section{Package Usage} |
| 146 |
% To use |pst-slpe|, you have to say |
| 147 |
% \begin{verbatim} |
| 148 |
% \usepackage{pst-slpe} |
| 149 |
% \end{verbatim} |
| 150 |
% in the document prologue for \LaTeX, and |
| 151 |
% \begin{verbatim} |
| 152 |
% \input pst-slpe.tex |
| 153 |
% \end{verbatim} |
| 154 |
% in ``plain'' \TeX. |
| 155 |
% |
| 156 |
% \section{New macro and fill styles} |
| 157 |
% \DescribeMacro{\psBall} |
| 158 |
% It takes the (optional) coordinates of the ball center, the color |
| 159 |
% and the radius as parameter and uses |\pscircle| for painting |
| 160 |
% the bullet. |
| 161 |
% |
| 162 |
% \vspace{1cm} |
| 163 |
% \psBall{black}{2ex} |
| 164 |
% \psBall(1,0){blue}{3ex} |
| 165 |
% \psBall(2.5,0){red}{4ex} |
| 166 |
% \psBall(4,0){green!50!blue!60}{5ex} |
| 167 |
% |
| 168 |
% \vspace{1cm} |
| 169 |
% \begin{verbatim} |
| 170 |
% \psBall{black}{2ex} |
| 171 |
% \psBall(1,0){blue}{3ex} |
| 172 |
% \psBall(2.5,0){red}{4ex} |
| 173 |
% \psBall(4,0){green!50!blue!60}{5ex} |
| 174 |
% \end{verbatim} |
| 175 |
% |
| 176 |
% The predinied options can be overwritten in the usual way: |
| 177 |
% |
| 178 |
% \vspace{1cm} |
| 179 |
% \psBall{black}{2ex} |
| 180 |
% \psBall[sloperadius=10pt](1,0){blue}{3ex} |
| 181 |
% \psBall(2.5,0){red}{4ex} |
| 182 |
% \psBall[slopebegin=red](4,0){green!50!blue!60}{5ex} |
| 183 |
% |
| 184 |
% \vspace{1cm} |
| 185 |
% \begin{verbatim} |
| 186 |
% \psBall{black}{2ex} |
| 187 |
% \psBall[sloperadius=10pt](1,0){blue}{3ex} |
| 188 |
% \psBall(2.5,0){red}{4ex} |
| 189 |
% \psBall[slopebegin=red](4,0){green!50!blue!60}{5ex} |
| 190 |
% \end{verbatim} |
| 191 |
% |
| 192 |
% \DescribeMacro{slope} |
| 193 |
% \DescribeMacro{slopes} |
| 194 |
% \DescribeMacro{ccslope} |
| 195 |
% \DescribeMacro{ccslopes} |
| 196 |
% \DescribeMacro{radslope} |
| 197 |
% \DescribeMacro{radslopes} |
| 198 |
% |pst-slpe| provides six new fill styles called |slope|, |slopes|, |
| 199 |
% |ccslope|, |ccslopes|, |radslope| and |radslopes|. These obviously |
| 200 |
% come in pairs: The $\ldots$|slope|-styles are simplified versions of |
| 201 |
% the general $\ldots$|slopes|-styles.\footnote{By the way, I use slope |
| 202 |
% as a synonym for gradient. It sounds less pretentious and avoids |
| 203 |
% name clashes.} The |cc|$\ldots$ styles paint concentric patterns, |
| 204 |
% and the |rad|$\ldots$ styles do radial ones. |
| 205 |
% |
| 206 |
% Here is a little |
| 207 |
% overview of what they look like: |
| 208 |
% \newcommand{\st}{$\vcenter to30pt{}$} |
| 209 |
% \begin{quote}\LARGE |
| 210 |
% \begin{tabular}{cc} |
| 211 |
% \psframebox[fillstyle=slope]{\st|slope|} &\qquad |
| 212 |
% \psframebox[fillstyle=slopes]{\st|slopes|} \\[2ex] |
| 213 |
% \psframebox[fillstyle=ccslope]{\st|ccslope|} &\qquad |
| 214 |
% \psframebox[fillstyle=ccslopes]{\st|ccslopes|} \\[2ex] |
| 215 |
% \psframebox[fillstyle=radslope]{\st|radslope|} &\qquad |
| 216 |
% \psframebox[fillstyle=radslopes]{\st|radslopes|} \\[2ex] |
| 217 |
% \end{tabular} |
| 218 |
% \end{quote} |
| 219 |
% These examples were produced by saying simply |
| 220 |
% \begin{verbatim} |
| 221 |
% \psframebox[fillstyle=slope]{...} |
| 222 |
% \end{verbatim} |
| 223 |
% etc.~without setting any further graphics parameters. The package |
| 224 |
% provides a number of parameters that can be used to control |
| 225 |
% the way these patterns |
| 226 |
% are painted. |
| 227 |
% \medskip |
| 228 |
% |
| 229 |
% \DescribeMacro{slopebegin} |
| 230 |
% \DescribeMacro{slopeend} |
| 231 |
% The graphics parameters |slopebegin| and |slopeend| set the colours |
| 232 |
% between which the three $\ldots$|slope| styles should interpolate. |
| 233 |
% Eg, |
| 234 |
% \begin{verbatim} |
| 235 |
% \psframebox[fillstyle=slope,slopebegin=red,slopeend=green]{...} |
| 236 |
% \end{verbatim} |
| 237 |
% produces: |
| 238 |
% \begin{quote}\Large |
| 239 |
% \psframebox[fillstyle=slope,slopebegin=red,slopeend=green]{\st slopes!} |
| 240 |
% \end{quote} |
| 241 |
% The same settings of |slopebegin| and |slopeend| for the |ccslope| |
| 242 |
% and |radslope| fillstyles produce |
| 243 |
% \begin{quote}\Large |
| 244 |
% \psframebox[fillstyle=ccslope,slopebegin=red,slopeend=green]{\st slopes!} |
| 245 |
% \quad{\normalsize resp.}\quad |
| 246 |
% \psframebox[fillstyle=radslope,slopebegin=red,slopeend=green]{\st slopes!} |
| 247 |
% \end{quote} |
| 248 |
% The default settings go from a greenish yellow to pure blue. |
| 249 |
% \medskip |
| 250 |
% |
| 251 |
% \DescribeMacro{slopecolors} |
| 252 |
% If you want to interpolate between more than two colours, you have |
| 253 |
% to use the $\ldots$|slopes| styles, which are controlled by the |
| 254 |
% |slopecolors| parameter instead of |slopebegin| and |slopeend|. The |
| 255 |
% idea is to specify the colour to use at certain points `on the |
| 256 |
% way'. To fill a shape with |slopes|, imagine a linear scale |
| 257 |
% from its left edge to its right edge. The left edge must lie at |
| 258 |
% coordinate 0. Pick an arbitrary value for the right edge, say 23. |
| 259 |
% Now you want to get light yellow at the left edge, a pastel green at $17/23$ |
| 260 |
% of the way and dark cyan at the right edge, like this: |
| 261 |
% \begin{quote}\psset{unit=0.45cm} |
| 262 |
% \begin{pspicture}(-1,0)(24,6) |
| 263 |
% \pscustom[fillstyle=slopes, |
| 264 |
% slopecolors=0 1 1 .9 17 .5 1 .5 23 0 0.5 0.5 3]{ |
| 265 |
% \psccurve(0,2.5)(12,3.5)(20,4)(23,2)(17,2.5)} |
| 266 |
% \psaxes(0,5)(-0.01,5)(23.01,5) |
| 267 |
% \psline(0,5)(0,1) |
| 268 |
% \psline(17,5)(17,1) |
| 269 |
% \psline(23,5)(23,1) |
| 270 |
% \end{pspicture} |
| 271 |
% \end{quote} |
| 272 |
% The RGB values for the three colours are $(1,1,0.9)$, $(0.5,1,0.5)$ |
| 273 |
% and $(0,0.5,0.5)$. The value for the |slopecolors| parameter is a list |
| 274 |
% of `colour infos' followed by the number of `colour infos'. |
| 275 |
% Each `colour info' consists |
| 276 |
% of the coordinate value where a colour is to be specified, followed by |
| 277 |
% the RGB values of that colour. All these values are separated by |
| 278 |
% white space. The correct setting for the example is thus: |
| 279 |
% \begin{verbatim} |
| 280 |
% slopecolors=0 1 1 .9 17 .5 1 .5 23 0 .5 .5 3 |
| 281 |
% \end{verbatim} |
| 282 |
% For |ccslopes|, specify the colours from the center outward. |
| 283 |
% For |radslopes| (with no rotation specified), 0 represents the ray |
| 284 |
% going `eastward'. Specify the colours anti-clockwise. If you want a |
| 285 |
% smooth gradient at the beginning and starting ray of |radslopes|, you |
| 286 |
% should pick the first and last colours identical. |
| 287 |
% |
| 288 |
% Please note, that the |slopecolors| parameter is not subject to any |
| 289 |
% parsing on the \TeX\ side. If you forget a number or specify the wrong |
| 290 |
% number of segments, the PostScript interpreter will probably crash. |
| 291 |
% |
| 292 |
% The default value for |slopecolors| specifies a rainbow. |
| 293 |
% |
| 294 |
% \medskip |
| 295 |
% |
| 296 |
% \DescribeMacro{slopesteps} |
| 297 |
% The parameter |slopesteps| controls the number of distinct colour steps |
| 298 |
% rendered. Higher values for this parameter result in better quality |
| 299 |
% but proportionally slower rendering. Eg, setting |
| 300 |
% |slopesteps| to 5 with the |slope| fill style results in |
| 301 |
% \begin{quote}\Large |
| 302 |
% \psframebox[fillstyle=slope,slopesteps=5]{\st slopes!} |
| 303 |
% \end{quote} |
| 304 |
% |
| 305 |
% The default value is 100, which |
| 306 |
% suffices for most purposes. Remember that the number of distinct colours |
| 307 |
% reproducible by a given device is limited. Pushing |slopesteps| to |
| 308 |
% high will result only in loss of performance at no gain in quality. |
| 309 |
% \medskip |
| 310 |
% |
| 311 |
% \DescribeMacro{slopeangle} |
| 312 |
% The |slope(s)| and |radslope(s)| patterns may be rotated. As usual, |
| 313 |
% the angles are given anti-clockwise. Eg, an angle of 30 degrees |
| 314 |
% gives |
| 315 |
% \begin{quote}\Large\psset{slopeangle=30} |
| 316 |
% \psframebox[fillstyle=slope]{\st slopes!} |
| 317 |
% \quad{\normalsize and}\quad |
| 318 |
% \psframebox[fillstyle=radslope]{\st slopes!} |
| 319 |
% \end{quote} |
| 320 |
% with the |slope| and |radslope| fillstyles. |
| 321 |
% \medskip |
| 322 |
% |
| 323 |
% \DescribeMacro{slopecenter} |
| 324 |
% For the |cc|$\ldots$ and |rad|$\ldots$ styles, it is possible to |
| 325 |
% set the center of the pattern. The |slopecenter| parameter is set to |
| 326 |
% the coordinates of that center relative to the bounding box of the |
| 327 |
% current path. The following effect: |
| 328 |
% \begin{quote}\psset{unit=0.45cm} |
| 329 |
% \begin{pspicture}(-1,-1)(24,5) |
| 330 |
% \pscustom[fillstyle=radslope,slopecenter=0.2 0.4]{ |
| 331 |
% \pspolygon(0,2.5)(12,2.5)(20,4)(23,2)(17,2.5)(3,0)} |
| 332 |
% \psaxes[axesstyle=frame,Dx=0.1,dx=2.2999,Dy=0.2,dy=0.7999](0,0)(23,4) |
| 333 |
% \psline(4.6,0)(4.6,4) |
| 334 |
% \psline(0,1.6)(23,1.6) |
| 335 |
% \end{pspicture} |
| 336 |
% \end{quote} |
| 337 |
% was achieved with |
| 338 |
% \begin{verbatim} |
| 339 |
% fillstyle=radslope,slopecenter=0.2 0.4 |
| 340 |
% \end{verbatim} |
| 341 |
% The default value for |slopecenter| is |0.5 0.5|, which is the |
| 342 |
% center for symmetrical shapes. Note that this parameter is not |
| 343 |
% parsed by \TeX, so setting it to anything else than two numbers |
| 344 |
% between 0 and 1 might crash the PostScript interpreter. |
| 345 |
% \medskip |
| 346 |
% |
| 347 |
% \DescribeMacro{sloperadius} |
| 348 |
% Normally, the |cc|$\ldots$ and |rad|$\ldots$ styles distribute the |
| 349 |
% given colours so that the center is painted in the first colour given, |
| 350 |
% and the points of the shape furthest from the center are painted in |
| 351 |
% the last colour. In other words the maximum radius to which the |
| 352 |
% |slopecolors| parameter refers is the maximum distance from the |
| 353 |
% center (defined by |slopecenter|) to any point on the periphery |
| 354 |
% of the shape. This radius can be explicitly set with |sloperadius|. |
| 355 |
% Eg, setting |sloperadius=0.5cm| gives |
| 356 |
% \begin{quote}\Large\psset{sloperadius=0.5cm} |
| 357 |
% \psframebox[fillstyle=ccslope]{\st slopes!} |
| 358 |
% \end{quote} |
| 359 |
% Any point further from the center than the given |sloperadius| is |
| 360 |
% painted with the last colour in |slopeclours|, resp.~|slopeend|. |
| 361 |
% |
| 362 |
% The default value for |sloperadius| is 0, which invokes the default |
| 363 |
% behaviour of automatically calculating the radius. |
| 364 |
% |
| 365 |
% \DescribeMacro{fading} |
| 366 |
% \DescribeMacro{startfading} |
| 367 |
% \DescribeMacro{endfading} |
| 368 |
% The optional boolean keyword |fading| allows a transparency effect of |
| 369 |
% the filled area, starting with the opacity value |startfading| and |
| 370 |
% ending with the value of |endfading|. Both values must be of the |
| 371 |
% intervall [0\ldots1], with 0 for total opacity and 1 for no |
| 372 |
% opacity. The values are preset by 0 and 1. |
| 373 |
% |
| 374 |
% Here is a little |
| 375 |
% overview of what they look like: |
| 376 |
% \begin{quote}\LARGE\color{white} |
| 377 |
% \begin{tabular}{cc} |
| 378 |
% \psframe*(-0.3,-0.25)(3,20pt)\psframebox[fading,fillstyle=slope]{\st| slope |} &\qquad |
| 379 |
% \psframe*(-0.3,-0.25)(3,20pt)\psframebox[fading,fillstyle=slopes]{\st| slopes |} \\[2ex] |
| 380 |
% \psframe*(-0.3,-0.25)(3,20pt)\psframebox[fading,fillstyle=ccslope]{\st|ccslope |} &\qquad |
| 381 |
% \psframe*(-0.3,-0.25)(3,20pt)\psframebox[fading,fillstyle=ccslopes]{\st|ccslopes|} \\[2ex] |
| 382 |
% \psframe*(-0.3,-0.25)(3,20pt)\psframebox[fading,fillstyle=radslope]{\st|radslope|} &\qquad |
| 383 |
% \psframe*(-0.3,-0.25)(3,20pt)\psframebox[fading,fillstyle=radslopes]{\st|radslopes|} \\[2ex] |
| 384 |
% \end{tabular} |
| 385 |
% \end{quote} |
| 386 |
% \color{black} |
| 387 |
% |
| 388 |
% These examples were produced by saying simply |
| 389 |
% \begin{verbatim} |
| 390 |
% \psframebox[fading,fillstyle=...]{...} |
| 391 |
% \end{verbatim} |
| 392 |
% |
| 393 |
% \begin{quote}\LARGE\color{white} |
| 394 |
% \psset{fading,startfading=0.3,endfading=0.8} |
| 395 |
% \begin{tabular}{cc} |
| 396 |
% \psframe*(-0.3,-0.25)(3,20pt)\psframebox[fillstyle=slope]{\st| slope |} &\qquad |
| 397 |
% \psframe*(-0.3,-0.25)(3,20pt)\psframebox[fillstyle=slopes]{\st| slopes |} \\[2ex] |
| 398 |
% \psframe*(-0.3,-0.25)(3,20pt)\psframebox[fillstyle=ccslope]{\st|ccslope |} &\qquad |
| 399 |
% \psframe*(-0.3,-0.25)(3,20pt)\psframebox[fillstyle=ccslopes]{\st|ccslopes|} \\[2ex] |
| 400 |
% \psframe*(-0.3,-0.25)(3,20pt)\psframebox[fillstyle=radslope]{\st|radslope|} &\qquad |
| 401 |
% \psframe*(-0.3,-0.25)(3,20pt)\psframebox[fillstyle=radslopes]{\st|radslopes|} \\[2ex] |
| 402 |
% \end{tabular} |
| 403 |
% \end{quote} |
| 404 |
% \color{black} |
| 405 |
% |
| 406 |
% These examples were produced by saying simply |
| 407 |
% \begin{verbatim} |
| 408 |
% \psframebox[fading,startfading=0.3,endfading=0.8,fillstyle=...]{...} |
| 409 |
% \end{verbatim} |
| 410 |
% |
| 411 |
% \StopEventually{} |
| 412 |
% |
| 413 |
%\section{The Code} |
| 414 |
% \subsection{Producing the documentation} |
| 415 |
% |
| 416 |
% A short driver is provided that can be extracted if necessary by |
| 417 |
% the \textsc{docstrip} program provided with \LaTeXe. |
| 418 |
% \begin{macrocode} |
| 419 |
%<*driver> |
| 420 |
\NeedsTeXFormat{LaTeX2e} |
| 421 |
\documentclass{ltxdoc} |
| 422 |
\usepackage{pst-slpe} |
| 423 |
\usepackage{pst-plot} |
| 424 |
\DisableCrossrefs |
| 425 |
\MakeShortVerb{\|} |
| 426 |
\newcommand\Lopt[1]{\textsf{#1}} |
| 427 |
\newcommand\file[1]{\texttt{#1}} |
| 428 |
\AtEndDocument{ |
| 429 |
\PrintChanges |
| 430 |
\PrintIndex |
| 431 |
} |
| 432 |
%\OnlyDescription |
| 433 |
\begin{document} |
| 434 |
\DocInput{pst-slpe.dtx} |
| 435 |
\end{document} |
| 436 |
%</driver> |
| 437 |
% \end{macrocode} |
| 438 |
% |
| 439 |
% \subsection{The \file{pst-slpe.sty} file} |
| 440 |
% The \file{pst-slpe.sty} file is very simple. It just loads |
| 441 |
% the generic \file{pst-slpe.tex} file. |
| 442 |
% \begin{macrocode} |
| 443 |
%<*stylefile> |
| 444 |
\RequirePackage{pstricks} |
| 445 |
\ProvidesPackage{pst-slpe}[2005/03/05 package wrapper for `pst-slpe.tex'] |
| 446 |
\input{pst-slpe.tex} |
| 447 |
\ProvidesFile{pst-slpe.tex} |
| 448 |
[\pstslpefiledate\space v\pstslpefileversion\space |
| 449 |
`pst-slpe' (mg,hv)] |
| 450 |
\IfFileExists{pst-slpe.pro}{% |
| 451 |
\ProvidesFile{pst-slpe.pro} |
| 452 |
[2008/06/19 v. 0.01, PostScript prologue file (hv)] |
| 453 |
\@addtofilelist{pst-slpe.pro}}{}% |
| 454 |
%</stylefile> |
| 455 |
% \end{macrocode} |
| 456 |
% |
| 457 |
% \subsection{The \file{pst-slpe.tex} file} |
| 458 |
% \file{pst-slpe.tex} contains the \TeX-side of things. We begin |
| 459 |
% by identifying ourselves and setting things up, the same as in |
| 460 |
% other PSTricks packages. |
| 461 |
% \begin{macrocode} |
| 462 |
%<*texfile> |
| 463 |
\message{ v\pstslpefileversion, \pstslpefiledate} |
| 464 |
\csname PstSlopeLoaded\endcsname |
| 465 |
\let\PstSlopeLoaded\endinput |
| 466 |
\ifx\PSTricksLoaded\endinput\else |
| 467 |
\def\next{\input pstricks.tex }\expandafter\next |
| 468 |
\fi |
| 469 |
\ifx\PSTXKeyLoaded\endinput\else\input pst-xkey \fi % --> hv |
| 470 |
\edef\TheAtCode{\the\catcode`\@} |
| 471 |
\catcode`\@=11 |
| 472 |
\pst@addfams{pst-slpe} % --> hv |
| 473 |
\pstheader{pst-slpe.pro} |
| 474 |
% \end{macrocode} |
| 475 |
% \begin{macro}{slopebegin} |
| 476 |
% \begin{macro}{slopeend} |
| 477 |
% \begin{macro}{slopesteps} |
| 478 |
% \begin{macro}{slopeangle} |
| 479 |
% |
| 480 |
% \subsubsection{New graphics parameters} |
| 481 |
% We now define the various new parameters needed by the |slope| |
| 482 |
% fill styles and install default values. First come the colours, |
| 483 |
% ie~graphics parameters |slopebegin| and |slopeend|, followed |
| 484 |
% by the number of steps, |slopesteps|, and the rotation angle, |
| 485 |
% |slopeangle|. |
| 486 |
% \begin{macrocode} |
| 487 |
\newrgbcolor{slopebegin}{0.9 1 0} |
| 488 |
\define@key[psset]{pst-slpe}{slopebegin}{\pst@getcolor{#1}\psslopebegin}% --> hv |
| 489 |
\psset[pst-slpe]{slopebegin=slopebegin} % --> hv |
| 490 |
|
| 491 |
\newrgbcolor{slopeend}{0 0 1} |
| 492 |
\define@key[psset]{pst-slpe}{slopeend}{\pst@getcolor{#1}\psslopeend}% --> hv |
| 493 |
\psset[pst-slpe]{slopeend=slopeend}% --> hv |
| 494 |
|
| 495 |
\define@key[psset]{pst-slpe}{slopesteps}{\pst@getint{#1}\psslopesteps}% --> hv |
| 496 |
\psset[pst-slpe]{slopesteps=100}% --> hv |
| 497 |
|
| 498 |
\define@key[psset]{pst-slpe}{slopeangle}{\pst@getangle{#1}\psx@slopeangle}% --> hv |
| 499 |
\psset[pst-slpe]{slopeangle=0}% --> hv |
| 500 |
% \end{macrocode} |
| 501 |
% \end{macro} |
| 502 |
% \end{macro} |
| 503 |
% \end{macro} |
| 504 |
% \end{macro} |
| 505 |
% \begin{macro}{slopecolors} |
| 506 |
% The value for |slopecolors| is not parsed. It is directly copied |
| 507 |
% to the PostScript output. This is certainly not the way it |
| 508 |
% should be, but it's simple. The default value is a rainbow from |
| 509 |
% red to magenta. |
| 510 |
% \begin{macrocode} |
| 511 |
\define@key[psset]{pst-slpe}{slopecolors}{\def\psx@slopecolors{#1}}% --> hv |
| 512 |
\psset[pst-slpe]{slopecolors={% --> hv |
| 513 |
0.0 1 0 0 |
| 514 |
0.4 0 1 0 |
| 515 |
0.8 0 0 1 |
| 516 |
1.0 1 0 1 |
| 517 |
4}} |
| 518 |
% \end{macrocode} |
| 519 |
% \end{macro} |
| 520 |
% \begin{macro}{slopecenter} |
| 521 |
% The argument to |slopecenter| isn't parsed either. But there's |
| 522 |
% probably not much that can go wrong with two decimal numbers. |
| 523 |
% \begin{macrocode} |
| 524 |
\define@key[psset]{pst-slpe}{slopecenter}{\def\psx@slopecenter{#1}}% --> hv |
| 525 |
\psset[pst-slpe]{slopecenter={0.5 0.5}}% --> hv |
| 526 |
% \end{macrocode} |
| 527 |
% \end{macro} |
| 528 |
% \begin{macro}{sloperadius} |
| 529 |
% The default value for |sloperadius| is 0, which makes the |
| 530 |
% PostScript procedure |PatchRadius| determine a value for the radius. |
| 531 |
% \begin{macrocode} |
| 532 |
\define@key[psset]{pst-slpe}{sloperadius}{\pst@getlength{#1}\psx@sloperadius}% --> hv |
| 533 |
\psset[pst-slpe]{sloperadius=0}% --> hv |
| 534 |
% \end{macrocode} |
| 535 |
% \end{macro} |
| 536 |
% \begin{macro}{fading} |
| 537 |
% The default value for |fading| is false, which is no transparency effect at all. |
| 538 |
% With |fading=true| the package takes the values |startfading| and |endfading| |
| 539 |
% into account for the opacity effect of the filled area. |
| 540 |
% \end{macro} |
| 541 |
% \begin{macrocode} |
| 542 |
\define@boolkey[psset]{pst-slpe}[PST@]{fading}[true]{}% --> hv |
| 543 |
\psset[pst-slpe]{fading=false}% --> hv |
| 544 |
% \end{macrocode} |
| 545 |
% \begin{macro}{startfading} |
| 546 |
% The relativ number for the starting value (0\ldots1), preset by 0. |
| 547 |
% \end{macro} |
| 548 |
% \begin{macrocode} |
| 549 |
\define@key[psset]{pst-slpe}{startfading}{\pst@checknum{#1}\psk@startfading }% --> hv |
| 550 |
% \end{macrocode} |
| 551 |
% \begin{macro}{endfading} |
| 552 |
% The relativ number for the end value (0\ldots1), preset by 1. |
| 553 |
% \end{macro} |
| 554 |
% \begin{macrocode} |
| 555 |
\define@key[psset]{pst-slpe}{endfading}{\pst@checknum{#1}\psk@endfading }% --> hv |
| 556 |
\psset[pst-slpe]{startfading=0,endfading=1}% --> hv |
| 557 |
% \end{macrocode} |
| 558 |
% |
| 559 |
% \subsubsection{Fill style macros} |
| 560 |
% |
| 561 |
% Now come the fill style definitions that use these parameters. |
| 562 |
% There is one macro for each fill style named |\psfs@|$style$. |
| 563 |
% PSTricks calls this macro whenever the current path needs to |
| 564 |
% be filled in that style. The current path should not be |
| 565 |
% clobbered by the PostScript code output by the macro. |
| 566 |
% |
| 567 |
% \begin{macro}{slopes} |
| 568 |
% For the slopes fill style we produce PostScript code that |
| 569 |
% first puts the |slopecolors| parameter onto the stack. Note that |
| 570 |
% the number of colours listed, which comes last in |slopecolors| is |
| 571 |
% now on the top of the stack. Next come the |slopesteps| and |
| 572 |
% |slopeangle| parameters. We switch to the dictionary established |
| 573 |
% by the \file{pst-slop.pro} Prolog and call |SlopesFill|, which |
| 574 |
% does the artwork and takes care to leave the path alone. |
| 575 |
% \begin{macrocode} |
| 576 |
\def\psfs@slopes{% |
| 577 |
\addto@pscode{ |
| 578 |
\psx@slopecolors\space |
| 579 |
\psslopesteps |
| 580 |
\psx@slopeangle |
| 581 |
\ifPST@fading \psk@startfading \psk@endfading true \else false \fi |
| 582 |
tx@PstSlopeDict begin SlopesFill end}} |
| 583 |
% \end{macrocode} |
| 584 |
% \end{macro} |
| 585 |
% |
| 586 |
% \begin{macro}{slope} |
| 587 |
% The |slope| style uses parameters |slopebegin| and |slopeend| |
| 588 |
% instead of |slopecolors|. So the produced PostScript uses these |
| 589 |
% parameters to build a stack in |slopecolors| format. The |
| 590 |
% |\pst@usecolor| generates PostScript to set the current colour. |
| 591 |
% We can query the RGB values with |currentrgbcolor|. |
| 592 |
% A |gsave|/|grestore| pair is used to avoid changing the |
| 593 |
% PostScript graphics state. Once the stack is set up, |
| 594 |
% |SlopesFill| is called as before. |
| 595 |
% \begin{macrocode} |
| 596 |
\def\psfs@slope{% |
| 597 |
\addto@pscode{% |
| 598 |
gsave |
| 599 |
0 \pst@usecolor\psslopebegin currentrgbcolor |
| 600 |
1 \pst@usecolor\psslopeend currentrgbcolor |
| 601 |
2 |
| 602 |
grestore |
| 603 |
\psslopesteps \psx@slopeangle |
| 604 |
\ifPST@fading \psk@startfading \psk@endfading true \else false \fi |
| 605 |
tx@PstSlopeDict begin SlopesFill end}} |
| 606 |
% \end{macrocode} |
| 607 |
% \end{macro} |
| 608 |
% |
| 609 |
% \begin{macro}{ccslopes} |
| 610 |
% \begin{macro}{ccslope} |
| 611 |
% \begin{macro}{radslopes} |
| 612 |
% The code for the other fill styles is about the same, except for a few |
| 613 |
% parameters more or less and different PostScript procedures called |
| 614 |
% to do the work. |
| 615 |
% \begin{macrocode} |
| 616 |
\def\psfs@ccslopes{% |
| 617 |
\addto@pscode{% |
| 618 |
\psx@slopecolors\space |
| 619 |
\psslopesteps \psx@slopecenter\space \psx@sloperadius\space |
| 620 |
\ifPST@fading \psk@startfading \psk@endfading true \else false \fi |
| 621 |
tx@PstSlopeDict begin CcSlopesFill end}} |
| 622 |
\def\psfs@ccslope{% |
| 623 |
\addto@pscode{% |
| 624 |
gsave 0 \pst@usecolor\psslopebegin currentrgbcolor |
| 625 |
1 \pst@usecolor\psslopeend currentrgbcolor |
| 626 |
2 grestore |
| 627 |
\psslopesteps \psx@slopecenter\space \psx@sloperadius\space |
| 628 |
\ifPST@fading \psk@startfading \psk@endfading true \else false \fi |
| 629 |
tx@PstSlopeDict begin CcSlopesFill end}} |
| 630 |
\def\psfs@radslopes{% |
| 631 |
\addto@pscode{% |
| 632 |
\psx@slopecolors\space |
| 633 |
\psslopesteps\psx@slopecenter\space\psx@sloperadius\space\psx@slopeangle |
| 634 |
\ifPST@fading \psk@startfading \psk@endfading true \else false \fi |
| 635 |
tx@PstSlopeDict begin RadSlopesFill end}} |
| 636 |
% \end{macrocode} |
| 637 |
% \end{macro} |
| 638 |
% \end{macro} |
| 639 |
% \end{macro} |
| 640 |
% \begin{macro}{radslope} |
| 641 |
% |radslope| is slightly different: Just going from one colour to |
| 642 |
% another in 360 degrees is usually not what is wanted. |radslope| just |
| 643 |
% does something pretty with the colours provided. |
| 644 |
% \begin{macrocode} |
| 645 |
\def\psfs@radslope{% |
| 646 |
\addto@pscode{% |
| 647 |
gsave 0 \pst@usecolor\psslopebegin currentrgbcolor |
| 648 |
1 \pst@usecolor\psslopeend currentrgbcolor |
| 649 |
2 \pst@usecolor\psslopebegin currentrgbcolor |
| 650 |
3 \pst@usecolor\psslopeend currentrgbcolor |
| 651 |
4 \pst@usecolor\psslopebegin currentrgbcolor |
| 652 |
5 grestore |
| 653 |
\psslopesteps\psx@slopecenter\space\psx@sloperadius\space\psx@slopeangle |
| 654 |
\ifPST@fading \psk@startfading \psk@endfading true \else false \fi |
| 655 |
tx@PstSlopeDict begin RadSlopesFill end}} |
| 656 |
% \end{macrocode} |
| 657 |
% \end{macro} |
| 658 |
% |
| 659 |
% \begin{macro}{\psBall} |
| 660 |
% \begin{macrocode} |
| 661 |
\def\psBall{\pst@object{psBall}} |
| 662 |
\def\psBall@i{\@ifnextchar(\psBall@ii{\psBall@ii(0,0)}} |
| 663 |
\def\psBall@ii(#1,#2)#3#4{{% |
| 664 |
\pst@killglue |
| 665 |
\pssetlength\pst@dima{#4}%%%%% 20111025 hv |
| 666 |
\pst@dimb=\pst@dima%%%%%%%%%%% 20111025 hv |
| 667 |
\advance\pst@dima by 0.075\pst@dimb% |
| 668 |
\addbefore@par{sloperadius=\the\pst@dima,fillstyle=ccslope, |
| 669 |
slopebegin=white,slopeend=#3,slopecenter=0.4 0.6,linestyle=none}% |
| 670 |
\use@par% |
| 671 |
\pscircle(#1,#2){#4}% |
| 672 |
}\ignorespaces% |
| 673 |
} |
| 674 |
% \end{macrocode} |
| 675 |
% \end{macro} |
| 676 |
% |
| 677 |
% |
| 678 |
% \begin{macrocode} |
| 679 |
\catcode`\@=\TheAtCode\relax |
| 680 |
%</texfile> |
| 681 |
% \end{macrocode} |
| 682 |
% |
| 683 |
% \subsection{The \file{pst-slpe.pro} file} |
| 684 |
% The file \file{pst-slpe.pro} contains PostScript definitions |
| 685 |
% to be included in the PostScript output by the |
| 686 |
% |dvi|-to-PostScript converter, eg |dvips|. |
| 687 |
% First thing is to define a |
| 688 |
% dictionary to keep definitions local. |
| 689 |
% \begin{macrocode} |
| 690 |
%<*prolog> |
| 691 |
/tx@PstSlopeDict 60 dict def tx@PstSlopeDict begin |
| 692 |
% \end{macrocode} |
| 693 |
% |
| 694 |
% \begin{macro}{Opacity++} |
| 695 |
% This macro increments the Opacity index |
| 696 |
% \begin{macrocode} |
| 697 |
/Opacity 1 def % preset, no transparency |
| 698 |
/Opacity++ { Opacity dOpacity add /Opacity ED } def |
| 699 |
% \end{macrocode} |
| 700 |
% \end{macro} |
| 701 |
% \begin{macro}{max} |
| 702 |
% $x1 \quad x2 \quad \mathtt{max}\quad max$\\ |
| 703 |
% |max| is a utility function that calculates the maximum |
| 704 |
% of two numbers. |
| 705 |
% \begin{macrocode} |
| 706 |
/max {2 copy lt {exch} if pop} bind def |
| 707 |
% \end{macrocode} |
| 708 |
% \end{macro} |
| 709 |
% |
| 710 |
% \begin{macro}{Iterate} |
| 711 |
% $p_1\quad r_1\quad g_1\quad b_1\quad\ldots\quad |
| 712 |
% p_n\quad r_n\quad g_n\quad b_n\quad n\quad \mathtt{Iterate}\quad -$\\ |
| 713 |
% This is the actual iteration, which goes through the colour |
| 714 |
% information and plots the segments. |
| 715 |
% It uses the value of |NumSteps| which is set by the wrapper |
| 716 |
% procedures. |DrawStep| is called all of |NumSteps| times, so |
| 717 |
% it had better be fast. |
| 718 |
% |
| 719 |
% First, the number of colour infos is read from the |
| 720 |
% top of the stack and decremented, to get the number of segments. |
| 721 |
% \begin{macrocode} |
| 722 |
/Iterate { |
| 723 |
1 sub /NumSegs ED |
| 724 |
% \end{macrocode} |
| 725 |
% Now we get the first colour. This is really the {\em last} |
| 726 |
% colour given in the |slopecolors| argument. We have to work |
| 727 |
% {\em down} the stack, so we shall be careful to plot the segments |
| 728 |
% in reverse order. The |dup mul| stuff squares the RGB |
| 729 |
% components. This does a kind-of-gamma correction, without |
| 730 |
% which primary colours tend to take up too much space in the |
| 731 |
% slope. This is nothing deep, it just looks better in my opinion. |
| 732 |
% The following lines convert RGB to HSB and store the resulting |
| 733 |
% components, as well as the |Pt| coordinate in four variables. |
| 734 |
% \begin{macrocode} |
| 735 |
dup mul 3 1 roll dup mul 3 1 roll dup mul 3 1 roll |
| 736 |
setrgbcolor currenthsbcolor |
| 737 |
/ThisB ED |
| 738 |
/ThisS ED |
| 739 |
/ThisH ED |
| 740 |
/ThisPt ED |
| 741 |
% \end{macrocode} |
| 742 |
% To avoid gaps, we fill the whole path in that first colour. |
| 743 |
% \begin{macrocode} |
| 744 |
Opacity .setopacityalpha |
| 745 |
gsave |
| 746 |
fill |
| 747 |
grestore |
| 748 |
% \end{macrocode} |
| 749 |
% The body of the following outer loop is executed |
| 750 |
% once for each segment. |
| 751 |
% It expects a current colour and |Pt| coordinate in the |This*| |
| 752 |
% variables and pops the next colour and point from the stack. It |
| 753 |
% then draws the single steps of that segment. |
| 754 |
% \begin{macrocode} |
| 755 |
NumSegs { |
| 756 |
dup mul 3 1 roll dup mul 3 1 roll dup mul 3 1 roll |
| 757 |
setrgbcolor currenthsbcolor |
| 758 |
/NextB ED |
| 759 |
/NextS ED |
| 760 |
/NextH ED |
| 761 |
/NextPt ED |
| 762 |
% \end{macrocode} |
| 763 |
% |NumSteps| always contains the remaining number of steps available. |
| 764 |
% These are evenly distributed between |Pt| coordinates |ThisPt| |
| 765 |
% to 0, so for the current segment we may use |
| 766 |
% $|NumSteps|*(|ThisPt|-|NextPt|)/|ThisPt|$ steps. |
| 767 |
% \begin{macrocode} |
| 768 |
ThisPt NextPt sub ThisPt div NumSteps mul cvi /SegSteps exch def |
| 769 |
/NumSteps NumSteps SegSteps sub def |
| 770 |
% \end{macrocode} |
| 771 |
% |SegSteps| may be zero. In that case there is nothing to do for |
| 772 |
% this segment. |
| 773 |
% \begin{macrocode} |
| 774 |
SegSteps 0 eq not { |
| 775 |
% \end{macrocode} |
| 776 |
% If one of the colours is gray, ie~0 saturation, its hue is |
| 777 |
% useless. In this case, instead of starting of with a random hue, |
| 778 |
% we take the hue of the other endpoint. (If both have saturation |
| 779 |
% 0, we have a pure gray scale and no harm is done) |
| 780 |
% \begin{macrocode} |
| 781 |
ThisS 0 eq {/ThisH NextH def} if |
| 782 |
NextS 0 eq {/NextH ThisH def} if |
| 783 |
% \end{macrocode} |
| 784 |
% To interpolate between two colours of different hue, we want to |
| 785 |
% go the shorter way around the colour circle. The following code |
| 786 |
% assures that this happens if we go linearly from |This*| to |
| 787 |
% |Next*| by conditionally adding 1.0 to one of the hue values. |
| 788 |
% The new hue values can lie between 0.0 and 2.0, so we will later |
| 789 |
% have to subtract 1.0 from values greater than one. |
| 790 |
% \begin{macrocode} |
| 791 |
ThisH NextH sub 0.5 gt |
| 792 |
{/NextH NextH 1.0 add def} |
| 793 |
{ NextH ThisH sub 0.5 ge {/ThisH ThisH 1.0 add def} if } |
| 794 |
ifelse |
| 795 |
% \end{macrocode} |
| 796 |
% We define three variables to hold the current colour coordinates |
| 797 |
% and calculate the corresponding increments per step. |
| 798 |
% \begin{macrocode} |
| 799 |
/B ThisB def |
| 800 |
/S ThisS def |
| 801 |
/H ThisH def |
| 802 |
/BInc NextB ThisB sub SegSteps div def |
| 803 |
/SInc NextS ThisS sub SegSteps div def |
| 804 |
/HInc NextH ThisH sub SegSteps div def |
| 805 |
% \end{macrocode} |
| 806 |
% The body of the following inner loop sets the current colour, |
| 807 |
% according to |H|, |S| and |B| and |
| 808 |
% undoes the kind-of-gamma correction by converting to RGB colour. |
| 809 |
% It then calls |DrawStep|, which draws one step and maybe updates |
| 810 |
% the current point or user space, or variables of its own. Finally, |
| 811 |
% it increments the three colour variables. |
| 812 |
% \begin{macrocode} |
| 813 |
SegSteps { |
| 814 |
H dup 1. gt {1. sub} if S B sethsbcolor |
| 815 |
currentrgbcolor |
| 816 |
sqrt 3 1 roll sqrt 3 1 roll sqrt 3 1 roll |
| 817 |
setrgbcolor |
| 818 |
DrawStep |
| 819 |
/H H HInc add def |
| 820 |
/S S SInc add def |
| 821 |
/B B BInc add def |
| 822 |
} bind repeat |
| 823 |
% \end{macrocode} |
| 824 |
% The outer loop ends by moving on to the |Next| colour and point. |
| 825 |
% |
| 826 |
% \begin{macrocode} |
| 827 |
/ThisH NextH def |
| 828 |
/ThisS NextS def |
| 829 |
/ThisB NextB def |
| 830 |
/ThisPt NextPt def |
| 831 |
} if |
| 832 |
} bind repeat |
| 833 |
} def |
| 834 |
% \end{macrocode} |
| 835 |
% \end{macro} |
| 836 |
% |
| 837 |
% \begin{macro}{PatchRadius} |
| 838 |
% $-\quad\mathtt{PatchRadius}\quad-$\\ |
| 839 |
% This macro inspects the value of the variable |Radius|. If it is |
| 840 |
% 0, it is set to the maximum distance of any point in the |
| 841 |
% current path from the origin of user space. This has the effect |
| 842 |
% that the current path will be totally filled. To find the maximum |
| 843 |
% distance, we flatten the path and call |UpdRR| for each endpoint |
| 844 |
% of the generated polygon. The current maximum square distance is |
| 845 |
% gathered in |RR|. |
| 846 |
% \begin{macrocode} |
| 847 |
/PatchRadius { |
| 848 |
Radius 0 eq { |
| 849 |
/UpdRR { dup mul exch dup mul add RR max /RR ED } bind def |
| 850 |
gsave |
| 851 |
flattenpath |
| 852 |
/RR 0 def |
| 853 |
{UpdRR} {UpdRR} {} {} pathforall |
| 854 |
grestore |
| 855 |
/Radius RR sqrt def |
| 856 |
} if |
| 857 |
} def |
| 858 |
% \end{macrocode} |
| 859 |
% \end{macro} |
| 860 |
% |
| 861 |
% \begin{macro}{SlopesFill} |
| 862 |
% $p_1\quad r_1\quad g_1\quad b_1\quad\ldots\quad |
| 863 |
% p_n\quad r_n\quad g_n\quad b_n\quad n\quad s\quad\alpha\quad |
| 864 |
% \mathtt{SlopesFill}\quad -$\\ |
| 865 |
% Fill the current path with a slope described by $p_1,\ldots,b_n,n$. |
| 866 |
% Use a total of $s$ single steps. Rotate the slope by $\alpha$ |
| 867 |
% degrees, 0 meaning $r_1,g_1,b_1$ left to $r_n,g_n,b_n$ right. |
| 868 |
% |
| 869 |
% After saving the current path, we do the rotation and get the |
| 870 |
% number of steps, which is later needed by |Iterate|. Remember, |
| 871 |
% that iterate calls |DrawStep| in the reverse order, ie~from |
| 872 |
% right to left. We work around this by adding 180 degrees to |
| 873 |
% the rotation. Filling |
| 874 |
% works by clipping to the path and painting an appropriate sequence |
| 875 |
% of rectangles. |DrawStep| is set up for |Iterate| to draw a |
| 876 |
% rectangle of width |XInc| high enough to cover the whole |
| 877 |
% clippath (we use the Level 2 operator |rectfill| for speed) and |
| 878 |
% translate the user system by |XInc|. |
| 879 |
% \begin{macrocode} |
| 880 |
/SlopesFill { |
| 881 |
/Fading ED % do we have fading? |
| 882 |
Fading { |
| 883 |
/FadingEnd ED % the last opacity value |
| 884 |
dup /FadingStart ED % the first opacity value |
| 885 |
/Opacity ED % the opacity start value |
| 886 |
} if |
| 887 |
gsave |
| 888 |
180 add rotate |
| 889 |
/NumSteps ED |
| 890 |
Fading { /dOpacity FadingEnd FadingStart sub NumSteps div def } if |
| 891 |
clip |
| 892 |
pathbbox |
| 893 |
/h ED /w ED |
| 894 |
2 copy translate |
| 895 |
h sub neg /h ED |
| 896 |
w sub neg /w ED |
| 897 |
/XInc w NumSteps div def |
| 898 |
/DrawStep { |
| 899 |
Fading { % do we have a fading? |
| 900 |
Opacity .setopacityalpha % set opacity value |
| 901 |
Opacity++ % increase opacity |
| 902 |
} if |
| 903 |
0 0 XInc h rectfill |
| 904 |
XInc 0 translate |
| 905 |
} bind def |
| 906 |
Iterate |
| 907 |
grestore |
| 908 |
} def |
| 909 |
% \end{macrocode} |
| 910 |
% \end{macro} |
| 911 |
% |
| 912 |
% \begin{macro}{CcSlopesFill} $p_1\quad r_1\quad g_1\quad |
| 913 |
% b_1\quad\ldots\quad p_n\quad r_n\quad g_n\quad b_n\quad n\quad |
| 914 |
% c_x\quad c_y \quad r\quad \mathtt{CcSlopesFill}\quad -$\\ Fills |
| 915 |
% the current path with a concentric pattern, |
| 916 |
% ie~in a polar coordinate system, the colour depends on the |
| 917 |
% radius and not on the angle. |
| 918 |
% Centered around a point with coordinates $(c_x,c_y)$ relative to |
| 919 |
% the bounding box of the path, ie~for a rectangle, $(0,0)$ will |
| 920 |
% center the pattern around the lower left corner of the rectangle, |
| 921 |
% $(0.5,0.5)$ around its center. The largest circle has a radius of |
| 922 |
% $r$. If $r=0$, $r$ is taken to be the maximum distance of any |
| 923 |
% point on the current path from the center defined by $(c_x,c_y)$. |
| 924 |
% The colours are given from the center outwards, |
| 925 |
% ie~$(r_1,g_1,b_1)$ describe the colour at the center. |
| 926 |
% |
| 927 |
% The code is similar to that of |SlopesFill|. The main differences |
| 928 |
% are the call to |PatchRadius|, which catches the case that $r=0$ |
| 929 |
% and the different definition for |DrawStep|, Which now fills a |
| 930 |
% circle of radius |Rad| and decreases that Variable. Of course, |
| 931 |
% drawing starts on the outside, so we work down the stack and circles |
| 932 |
% drawn later partially cover those drawn first. Painting |
| 933 |
% non-overlapping, `donut-shapes' would be slower. |
| 934 |
% \begin{macrocode} |
| 935 |
/CcSlopesFill { |
| 936 |
/Fading ED % do we have fading? |
| 937 |
Fading { |
| 938 |
/FadingEnd ED % the last opacity value |
| 939 |
dup /FadingStart ED % the first opacity value |
| 940 |
/Opacity ED % the opacity start value |
| 941 |
} if |
| 942 |
gsave |
| 943 |
/Radius ED |
| 944 |
/CenterY ED |
| 945 |
/CenterX ED |
| 946 |
/NumSteps ED |
| 947 |
Fading { /dOpacity FadingEnd FadingStart sub NumSteps div def } if |
| 948 |
clip |
| 949 |
pathbbox |
| 950 |
/h ED /w ED |
| 951 |
2 copy translate |
| 952 |
h sub neg /h ED |
| 953 |
w sub neg /w ED |
| 954 |
w CenterX mul h CenterY mul translate |
| 955 |
PatchRadius |
| 956 |
/RadPerStep Radius NumSteps div neg def |
| 957 |
/Rad Radius def |
| 958 |
/DrawStep { |
| 959 |
Fading { % do we have a fading? |
| 960 |
Opacity .setopacityalpha % set opacity value |
| 961 |
Opacity++ % increase opacity |
| 962 |
} if |
| 963 |
0 0 Rad 0 360 arc |
| 964 |
closepath fill |
| 965 |
/Rad Rad RadPerStep add def |
| 966 |
} bind def |
| 967 |
Iterate |
| 968 |
grestore |
| 969 |
} def |
| 970 |
% \end{macrocode} |
| 971 |
% \end{macro} |
| 972 |
% |
| 973 |
% \begin{macro}{RadSlopesFill} |
| 974 |
% $p_1\quad r_1\quad g_1\quad b_1\quad\ldots |
| 975 |
% \quad p_n\quad r_n\quad g_n\quad b_n\quad n\quad |
| 976 |
% c_x\quad c_y \quad r\quad\alpha\quad \mathtt{CcSlopesFill}\quad -$\\ |
| 977 |
% This fills the current path with a radial pattern, ie~in a |
| 978 |
% polar coordinate system the colour depends on the angle and not on |
| 979 |
% the radius. All this is very similar to |CcSlopesFill|. There |
| 980 |
% is an extra parameter $\alpha$, which rotates the pattern. |
| 981 |
% |
| 982 |
% The only new thing in the code is the |DrawStep| procedure. |
| 983 |
% This does {\em not} draw a circular arc, but a triangle, which is |
| 984 |
% considerably faster. One of the short sides of the triangle is |
| 985 |
% determined by |Radius|, the other one by |dY|, which is calculated |
| 986 |
% as $|dY|:=|Radius|\times\tan(|AngleIncrement|)$. |
| 987 |
% \begin{macrocode} |
| 988 |
/RadSlopesFill { |
| 989 |
/Fading ED % do we have fading? |
| 990 |
Fading { |
| 991 |
/FadingEnd ED % the last opacity value |
| 992 |
dup /FadingStart ED % the first opacity value |
| 993 |
/Opacity ED % the opacity start value |
| 994 |
} if |
| 995 |
gsave |
| 996 |
rotate |
| 997 |
/Radius ED |
| 998 |
/CenterY ED |
| 999 |
/CenterX ED |
| 1000 |
/NumSteps ED |
| 1001 |
Fading { /dOpacity FadingEnd FadingStart sub NumSteps div def } if |
| 1002 |
clip |
| 1003 |
pathbbox |
| 1004 |
/h ED /w ED |
| 1005 |
2 copy translate |
| 1006 |
h sub neg /h ED |
| 1007 |
w sub neg /w ED |
| 1008 |
w CenterX mul h CenterY mul translate |
| 1009 |
PatchRadius |
| 1010 |
/AngleIncrement 360 NumSteps div neg def |
| 1011 |
/dY AngleIncrement sin AngleIncrement cos div Radius mul def |
| 1012 |
/DrawStep { |
| 1013 |
Fading { % do we have a fading? |
| 1014 |
Opacity .setopacityalpha % set opacity value |
| 1015 |
Opacity++ % increase opacity |
| 1016 |
} if |
| 1017 |
0 0 moveto |
| 1018 |
Radius 0 rlineto |
| 1019 |
0 dY rlineto |
| 1020 |
closepath fill |
| 1021 |
AngleIncrement rotate |
| 1022 |
} bind def |
| 1023 |
Iterate |
| 1024 |
grestore |
| 1025 |
} def |
| 1026 |
% \end{macrocode} |
| 1027 |
% \end{macro} |
| 1028 |
% |
| 1029 |
% Last, but not least, we have to close the private dictionary. |
| 1030 |
% \begin{macrocode} |
| 1031 |
end |
| 1032 |
%</prolog> |
| 1033 |
% \end{macrocode} |
| 1034 |
% \Finale |
| 1035 |
% |