| 1 |
% Copyright 2019 by Mark Wibrow |
| 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 Public License. |
| 7 |
% |
| 8 |
% See the file doc/generic/pgf/licenses/LICENSE for more details. |
| 9 |
|
| 10 |
\usepgfmodule{decorations}% |
| 11 |
|
| 12 |
|
| 13 |
% |
| 14 |
% These decorations "morph" paths. That means that the |
| 15 |
% original characteristic of the path is kept and the number of |
| 16 |
% subpaths remains the same -- only, the lines are slightly offset or |
| 17 |
% changed by the decoration. For instance a line might be turned into |
| 18 |
% a squiggly line or a snaking line or a bumping line. |
| 19 |
% |
| 20 |
|
| 21 |
|
| 22 |
% |
| 23 |
% |
| 24 |
% Kind 1: Path morphing straight line decorations |
| 25 |
% |
| 26 |
% |
| 27 |
|
| 28 |
|
| 29 |
% zigzag decoration. |
| 30 |
% |
| 31 |
\pgfdeclaredecoration{zigzag}{up from center}{% |
| 32 |
\state{up from center}[width=+.5\pgfdecorationsegmentlength, next state=big down] |
| 33 |
{ |
| 34 |
\pgfpathlineto{\pgfqpoint{.25\pgfdecorationsegmentlength}{\pgfdecorationsegmentamplitude}} |
| 35 |
}% |
| 36 |
\state{big down}[switch if less than=+.5\pgfdecorationsegmentlength to center finish, |
| 37 |
width=+.5\pgfdecorationsegmentlength, |
| 38 |
next state=big up] |
| 39 |
{ |
| 40 |
\pgfpathlineto{\pgfqpoint{.25\pgfdecorationsegmentlength}{-\pgfdecorationsegmentamplitude}} |
| 41 |
}% |
| 42 |
\state{big up}[switch if less than=+.5\pgfdecorationsegmentlength to center finish, |
| 43 |
width=+.5\pgfdecorationsegmentlength, |
| 44 |
next state=big down] |
| 45 |
{ |
| 46 |
\pgfpathlineto{\pgfqpoint{.25\pgfdecorationsegmentlength}{\pgfdecorationsegmentamplitude}} |
| 47 |
}% |
| 48 |
\state{center finish}[width=0pt, next state=final]{ |
| 49 |
\pgfpathlineto{\pgfpointorigin} |
| 50 |
}% |
| 51 |
\state{final} |
| 52 |
{ |
| 53 |
\pgfpathlineto{\pgfpointdecoratedpathlast} |
| 54 |
}% |
| 55 |
}% |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
% saw decoration |
| 61 |
% |
| 62 |
% Parameters: \pgfdecorationsegmentamplitude, \pgfdecorationsegmentlength |
| 63 |
|
| 64 |
\pgfdeclaredecoration{saw}{initial} |
| 65 |
{% |
| 66 |
\state{initial}[auto end on length=+\pgfdecorationsegmentlength, |
| 67 |
auto corner on length=+\pgfdecorationsegmentlength, |
| 68 |
width=+\pgfdecorationsegmentlength] |
| 69 |
{ |
| 70 |
\pgfpathlineto{\pgfqpoint{\pgfdecorationsegmentlength}{\pgfdecorationsegmentamplitude}} |
| 71 |
\pgfpathlineto{\pgfqpoint{\pgfdecorationsegmentlength}{0pt}} |
| 72 |
}% |
| 73 |
\state{final} |
| 74 |
{}% |
| 75 |
}% |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
% random steps decoration |
| 81 |
% |
| 82 |
% A decoration that consists of random steps heading towards the target |
| 83 |
% |
| 84 |
% Parameters: \pgfdecorationsegmentamplitude, \pgfdecorationsegmentlength |
| 85 |
|
| 86 |
\pgfdeclaredecoration{random steps}{start} |
| 87 |
{% |
| 88 |
\state{start}[width=+0pt,next state=step,persistent precomputation=\pgfdecoratepathhascornerstrue]{}% |
| 89 |
\state{step}[auto end on length=1.5\pgfdecorationsegmentlength, |
| 90 |
auto corner on length=1.5\pgfdecorationsegmentlength, |
| 91 |
width=+\pgfdecorationsegmentlength] |
| 92 |
{ |
| 93 |
\pgfpathlineto{ |
| 94 |
\pgfpointadd |
| 95 |
{\pgfpoint{\pgfdecorationsegmentlength}{0pt}} |
| 96 |
{\pgfpoint{rand*\pgfdecorationsegmentamplitude}{rand*\pgfdecorationsegmentamplitude}} |
| 97 |
} |
| 98 |
}% |
| 99 |
\state{final} |
| 100 |
{}% |
| 101 |
}% |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
% Meta-decoration line zigzag |
| 106 |
|
| 107 |
\pgfdeclaremetadecoration{straight zigzag}{line to}{% |
| 108 |
\state{line to}[width=\pgfmetadecorationsegmentlength, next state=zigzag] |
| 109 |
{ |
| 110 |
\decoration{curveto} |
| 111 |
}% |
| 112 |
\state{zigzag}[width=\pgfmetadecorationsegmentlength, next state=line to] |
| 113 |
{ |
| 114 |
\decoration{zigzag} |
| 115 |
}% |
| 116 |
\state{final} |
| 117 |
{ |
| 118 |
\decoration{curveto} |
| 119 |
}% |
| 120 |
}% |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
% |
| 127 |
% |
| 128 |
% Kind 2: Path morphing curved decorations |
| 129 |
% |
| 130 |
% |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
% bent decoration |
| 135 |
% |
| 136 |
% A decoration that looks like someone bent the line a bit. |
| 137 |
% |
| 138 |
% Parameters: \pgfdecorationsegmentamplitude, \pgfdecorationsegmentaspect |
| 139 |
|
| 140 |
\pgfdeclaredecoration{bent}{bent} |
| 141 |
{% |
| 142 |
\state{bent}[width=+\pgfdecoratedinputsegmentremainingdistance] |
| 143 |
{ |
| 144 |
\pgfpathcurveto |
| 145 |
{\pgfqpoint{\pgfdecorationsegmentaspect\pgfdecoratedinputsegmentremainingdistance}{\pgfdecorationsegmentamplitude}} |
| 146 |
{\pgfpointadd{\pgfqpoint{\pgfdecoratedinputsegmentremainingdistance}{0pt}} |
| 147 |
{\pgfqpoint{-\pgfdecorationsegmentaspect\pgfdecoratedinputsegmentremainingdistance}{\pgfdecorationsegmentamplitude}}} |
| 148 |
{\pgfqpoint{\pgfdecoratedinputsegmentremainingdistance}{0pt}} |
| 149 |
}% |
| 150 |
\state{final} |
| 151 |
{}% |
| 152 |
}% |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
% decoration snake |
| 157 |
% |
| 158 |
% This decoration produces a hopefully optically pleasing squiggly snake. |
| 159 |
% |
| 160 |
% Parameters: \pgfdecorationsegmentamplitude, \pgfdecorationsegmentlength |
| 161 |
|
| 162 |
\pgfdeclaredecoration{snake}{initial} |
| 163 |
{% |
| 164 |
\state{initial}[switch if less than=+.625\pgfdecorationsegmentlength to final, |
| 165 |
width=+.3125\pgfdecorationsegmentlength, |
| 166 |
next state=down] |
| 167 |
{ |
| 168 |
\pgfpathcurveto |
| 169 |
{\pgfqpoint{.125\pgfdecorationsegmentlength}{0pt}} |
| 170 |
{\pgfqpoint{.1875\pgfdecorationsegmentlength}{\pgfdecorationsegmentamplitude}} |
| 171 |
{\pgfqpoint{.3125\pgfdecorationsegmentlength}{\pgfdecorationsegmentamplitude}} |
| 172 |
}% |
| 173 |
\state{down}[switch if less than=+.8125\pgfdecorationsegmentlength to end down, |
| 174 |
width=+.5\pgfdecorationsegmentlength, |
| 175 |
next state=up] |
| 176 |
{ |
| 177 |
\pgfpathcosine{\pgfqpoint{.25\pgfdecorationsegmentlength}{-1\pgfdecorationsegmentamplitude}} |
| 178 |
\pgfpathsine{\pgfqpoint{.25\pgfdecorationsegmentlength}{-1\pgfdecorationsegmentamplitude}} |
| 179 |
}% |
| 180 |
\state{up}[switch if less than=+.8125\pgfdecorationsegmentlength to end up, |
| 181 |
width=+.5\pgfdecorationsegmentlength, |
| 182 |
next state=down] |
| 183 |
{ |
| 184 |
\pgfpathcosine{\pgfqpoint{.25\pgfdecorationsegmentlength}{\pgfdecorationsegmentamplitude}} |
| 185 |
\pgfpathsine{\pgfqpoint{.25\pgfdecorationsegmentlength}{\pgfdecorationsegmentamplitude}} |
| 186 |
}% |
| 187 |
\state{end down}[width=+.3125\pgfdecorationsegmentlength, |
| 188 |
next state=final] |
| 189 |
{ |
| 190 |
\pgfpathcurveto |
| 191 |
{\pgfqpoint{.125\pgfdecorationsegmentlength}{\pgfdecorationsegmentamplitude}} |
| 192 |
{\pgfqpoint{.1875\pgfdecorationsegmentlength}{0pt}} |
| 193 |
{\pgfqpoint{.3125\pgfdecorationsegmentlength}{0pt}} |
| 194 |
}% |
| 195 |
\state{end up}[width=+.3125\pgfdecorationsegmentlength, |
| 196 |
next state=final] |
| 197 |
{ |
| 198 |
\pgfpathcurveto |
| 199 |
{\pgfqpoint{.125\pgfdecorationsegmentlength}{-\pgfdecorationsegmentamplitude}} |
| 200 |
{\pgfqpoint{.1875\pgfdecorationsegmentlength}{0pt}} |
| 201 |
{\pgfqpoint{.3125\pgfdecorationsegmentlength}{0pt}} |
| 202 |
}% |
| 203 |
\state{final} |
| 204 |
{ |
| 205 |
\pgfpathlineto{\pgfpointdecoratedpathlast} |
| 206 |
}% |
| 207 |
}% |
| 208 |
|
| 209 |
|
| 210 |
% coil decoration |
| 211 |
% |
| 212 |
% Parameters: \pgfdecorationsegmentamplitude, \pgfdecorationsegmentlength, |
| 213 |
|
| 214 |
\pgfdeclaredecoration{coil}{coil} |
| 215 |
{% |
| 216 |
\state{coil}[switch if less than=% |
| 217 |
1.5\pgfdecorationsegmentlength+% |
| 218 |
\pgfdecorationsegmentaspect\pgfdecorationsegmentamplitude+% |
| 219 |
\pgfdecorationsegmentaspect\pgfdecorationsegmentamplitude to last, |
| 220 |
width=+\pgfdecorationsegmentlength] |
| 221 |
{ |
| 222 |
\pgfpathcurveto |
| 223 |
{\pgfpoint@oncoil{0 }{ 0.555}{1}} |
| 224 |
{\pgfpoint@oncoil{0.445}{ 1 }{2}} |
| 225 |
{\pgfpoint@oncoil{1 }{ 1 }{3}} |
| 226 |
\pgfpathcurveto |
| 227 |
{\pgfpoint@oncoil{1.555}{ 1 }{4}} |
| 228 |
{\pgfpoint@oncoil{2 }{ 0.555}{5}} |
| 229 |
{\pgfpoint@oncoil{2 }{ 0 }{6}} |
| 230 |
\pgfpathcurveto |
| 231 |
{\pgfpoint@oncoil{2 }{-0.555}{7}} |
| 232 |
{\pgfpoint@oncoil{1.555}{-1 }{8}} |
| 233 |
{\pgfpoint@oncoil{1 }{-1 }{9}} |
| 234 |
\pgfpathcurveto |
| 235 |
{\pgfpoint@oncoil{0.445}{-1 }{10}} |
| 236 |
{\pgfpoint@oncoil{0 }{-0.555}{11}} |
| 237 |
{\pgfpoint@oncoil{0 }{ 0 }{12}} |
| 238 |
}% |
| 239 |
\state{last}[width=.5\pgfdecorationsegmentlength+% |
| 240 |
\pgfdecorationsegmentaspect\pgfdecorationsegmentamplitude+% |
| 241 |
\pgfdecorationsegmentaspect\pgfdecorationsegmentamplitude,next state=final] |
| 242 |
{ |
| 243 |
\pgfpathcurveto |
| 244 |
{\pgfpoint@oncoil{0 }{ 0.555}{1}} |
| 245 |
{\pgfpoint@oncoil{0.445}{ 1 }{2}} |
| 246 |
{\pgfpoint@oncoil{1 }{ 1 }{3}} |
| 247 |
\pgfpathcurveto |
| 248 |
{\pgfpoint@oncoil{1.555}{ 1 }{4}} |
| 249 |
{\pgfpoint@oncoil{2 }{ 0.555}{5}} |
| 250 |
{\pgfpoint@oncoil{2 }{ 0 }{6}} |
| 251 |
}% |
| 252 |
\state{final} |
| 253 |
{ |
| 254 |
\pgfpathlineto{\pgfpointdecoratedpathlast} |
| 255 |
}% |
| 256 |
}% |
| 257 |
|
| 258 |
\def\pgfpoint@oncoil#1#2#3{% |
| 259 |
\pgf@x=#1\pgfdecorationsegmentamplitude% |
| 260 |
\pgf@x=\pgfdecorationsegmentaspect\pgf@x% |
| 261 |
\pgf@y=#2\pgfdecorationsegmentamplitude% |
| 262 |
\pgf@xa=0.083333333333\pgfdecorationsegmentlength% |
| 263 |
\advance\pgf@x by#3\pgf@xa% |
| 264 |
}% |
| 265 |
|
| 266 |
|
| 267 |
% bumps decoration |
| 268 |
% |
| 269 |
% Parameters: \pgfdecorationsegmentamplitude, \pgfdecorationsegmentlength |
| 270 |
|
| 271 |
\pgfdeclaredecoration{bumps}{initial} |
| 272 |
{% |
| 273 |
\state{initial}[auto end on length=+.51\pgfdecorationsegmentlength, |
| 274 |
auto corner on length=+.51\pgfdecorationsegmentlength, |
| 275 |
width=+.5\pgfdecorationsegmentlength] |
| 276 |
{ |
| 277 |
\pgfpathcurveto |
| 278 |
{\pgfqpoint{0pt}{.555\pgfdecorationsegmentamplitude}} |
| 279 |
{\pgfqpoint{0.11125\pgfdecorationsegmentlength}{\pgfdecorationsegmentamplitude}} |
| 280 |
{\pgfqpoint{.25\pgfdecorationsegmentlength}{\pgfdecorationsegmentamplitude}} |
| 281 |
\pgfpathcurveto |
| 282 |
{\pgfqpoint{.38875\pgfdecorationsegmentlength}{\pgfdecorationsegmentamplitude}} |
| 283 |
{\pgfqpoint{.5\pgfdecorationsegmentlength}{.5\pgfdecorationsegmentamplitude}} |
| 284 |
{\pgfqpoint{.5\pgfdecorationsegmentlength}{0\pgfdecorationsegmentamplitude}} |
| 285 |
}% |
| 286 |
\state{final} |
| 287 |
{ |
| 288 |
\pgfpathlineto{\pgfpointdecoratedpathlast} |
| 289 |
}% |
| 290 |
}% |
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
\endinput |