Debian Codegraph @

texmf-dist/source/latex/easing/easing.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2021 Lo̍h Ka-tsùn
4 %
5 % This file may be distributed and/or modified under the conditions of
6 % the LaTeX Project Public License, either version 1.3 of this license
7 % or (at your option) any later version. The latest version of this
8 % license is in:
9 %
10 % http://www.latex-project.org/lppl.txt
11 %
12 % and version 1.3 or later is part of all distributions of LaTeX version
13 % 2005/12/01 or later.
14 %
15 % \fi
16 % \iffalse
17 %<*driver>
18 \documentclass{ltxdoc}
19 \usepackage{parskip}
20 \usepackage{pgfplots}
21 \usepgflibrary{easing}
22 % \usepackage{hyperref}
23 \newcommand{\pgf}{\textsc{pgf}}
24 \EnableCrossrefs
25 \CodelineIndex
26 \RecordChanges
27 \CheckSum{594}
28 \changes{0.1}{2021/07/18}{Initial version}
29 \begin{document}
30 \DocInput{easing.dtx}
31 \end{document}
32 %</driver>
33 % \fi
34 % ^^A for drawing nice little graphs of the functions. pgfplots is
35 % ^^A probably overkill for this, so here's some ad-hoc TikZ-ing;
36 % ^^A hopefully to be tidied up substantially in a future version:
37 %
38 % \def\graphmargindefaulty{0.16}
39 % \def\graphmarginx{0.12}
40 % \edef\graphmarginy{\graphmargindefaulty}
41 % \newenvironment{easinggraph}{%
42 % \begin{tikzpicture}[x=2.8cm,y=2.8cm]
43 % \fill[white!97!black, use as bounding box]
44 % (-\graphmarginx,-\graphmarginy) rectangle
45 % ({1+\graphmarginx},{1+\graphmarginy});
46 % \draw[white!60!black]
47 % ({1+\graphmarginx},0) -- (-\graphmarginx,0) node[left] {$0$}
48 % ({1+\graphmarginx},1) -- (-\graphmarginx,1) node[left] {$1$};
49 % \draw[white!60!black,dashed]
50 % (0,1) -- (0,-\graphmarginy) node[below] {$a$}
51 % (1,1) -- (1,-\graphmarginy) node[below] {$b$};
52 % }{\end{tikzpicture}}
53 % \newcommand{\easinggraphplot}[2]{%
54 % \pgfmathparse{#2}
55 % \draw[white!\pgfmathresult!black,thick]
56 % (-\graphmarginx,0) -- (0,0)
57 % \foreach\x in{0,0.01,...,1}{--(\x,{#1(0,1,\x)})}
58 % -- (1,1) -- ({1+\graphmarginx},1);
59 % }
60 % \newcommand{\easinggraphplotfive}[4]{%
61 % \easinggraphlabel{#1\easingtype}{
62 % \foreach[count=\countv]\paramv
63 % in{#4}{\pgfmathparse{
64 % 18*(5-\countv)}{\color{
65 % white!\pgfmathresult!black}\ifnum\countv=1\relax
66 % #3=\else,\fi\paramv}}}
67 % \foreach[count=\countv]\paramv in{#4}{%
68 % \pgfkeys{/easing/#1/#2=\paramv}
69 % \easinggraphplot{#1\easingtype}{18*(5-\countv)}
70 % }
71 % }
72 % \newcommand{\easinggraphlabel}[2]{%
73 % \node[anchor=text] at (-\graphmarginx,{1+\graphmarginy})
74 % {\footnotesize\tt\raisebox{\baselineskip}{\parbox{3.5cm}{#1\\[-0.4ex]#2}}};
75 % }
76 % \newcommand{\foreachtypeeasinggraph}[1]{%
77 % \vspace{2\baselineskip}
78 % \foreach[count=\easingtypen]\easingtype in{easein,step,easeout}{%
79 % \ifnum\easingtypen>1\hspace{\fill}\fi
80 % \begin{easinggraph}#1\end{easinggraph}
81 % }
82 % \vspace{\baselineskip}
83 % }
84 %
85 % ^^A for printing code listings. again, there's probably a "proper"
86 % ^^A way to do this, but this is good enough i guess
87 %
88 % \newenvironment{fakelisting}{
89 % \begingroup\parskip 0pt\par\hrulefill}{
90 % \vspace{-1.3\baselineskip}\hrulefill\endgroup
91 % \vspace{\parskip}}
92 %
93 % ^^A body of documentation proper begins here.
94 %
95 % \title{The \textsf{easing}\thanks{version 0.1, dated
96 % 2021/07/18. This version was tested with \pgf{} version 3.1.9a}
97 % \ Library for \pgf}
98 %
99 % \author{Loh Ka-tsun\thanks{\texttt{[email protected]}}}
100 % \date{}
101 % \maketitle
102 %
103 % \thispagestyle{empty}
104 % \vspace{-2em}
105 % \begin{center}
106 % \begin{easinggraph}
107 % \easinggraphplot{smootherstep}{46}
108 % \easinggraphplot{smoothstep}{0}
109 % \end{easinggraph}
110 % \end{center}
111 %
112 % \tableofcontents\pagebreak
113 %
114 % \section{Introduction}
115 % This library adds easing functions to the \pgf{} mathematical engine.
116 %
117 % \section{Installation}
118 %
119 % The \textsf{easing} library is a \pgf{} library; it works both with
120 % \LaTeX{} and with plain \TeX{}. Once the file
121 % |pgflibraryeasing.code.tex| is in a directory searched by \TeX, the
122 % library can be loaded as follows:
123 %
124 % with plain \TeX:
125 % \begin{fakelisting}\begin{verbatim}
126 % \input pgf
127 % \usepgflibrary{easing}
128 % \end{verbatim}\end{fakelisting}
129 %
130 % with \LaTeX:
131 % \begin{fakelisting}\begin{verbatim}
132 % \usepackage{pgf}
133 % \usepgflibrary{easing}
134 % \end{verbatim}\end{fakelisting}
135 %
136 % The \textsf{easing} library is compatible with, but does not depend
137 % on, the floating point unit library provided by \pgf{}. To use both
138 % \textsf{easing} and the FPU, the FPU (or any packages/libraries
139 % which use the FPU, such as \textsf{pgfplots}) must be loaded
140 % before the \textsf{easing} library.
141 %
142 % \section{Usage}
143 %
144 % The routines implemented by the \textsf{easing} library are added to
145 % \pgf{}'s mathematical engine with |\pgfmathdeclarefunction|, so that
146 % they are recognised by by |\pgfmathparse| and can be used in any
147 % expression which is processed by the parser.
148 % As a first example, the following code produces plots of the
149 % function |smoothstep(|$a$|,|$b$|,|$x$|)| against the argument $x$,
150 % with one endpoint $a=0$ and the other endpoint $b$ ranging through
151 % the integers $-1$ to $3$:
152 %
153 % \vspace{\parskip}
154 % \hspace{-0.05\textwidth}
155 % \begin{minipage}[h]{0.55\textwidth}
156 % \tikzpicture
157 % \axis[
158 % width=\textwidth, ^^A we lie a little and omit this from the source listing
159 % domain=-1.2:3.2, samples=64,
160 % xmin=-1.2, xmax=3.2,
161 % cycle list={[samples of colormap=6 of viridis]},
162 % no marks, thick]
163 % \pgfplotsinvokeforeach{-1,...,3}{\addplot{smoothstep(0,#1,x)};}
164 % \endaxis
165 % \endtikzpicture
166 % \end{minipage}%
167 % \begin{minipage}[h]{0.5\textwidth}
168 % \begin{fakelisting}\begin{verbatim}
169 % \input pgfplots
170 % \usepgflibrary{easing}
171 % \tikzpicture
172 % \axis[
173 % domain=-1.2:3.2, samples=64,
174 % xmin=-1.2, xmax=3.2,
175 % cycle list={
176 % [samples of colormap=6 of viridis]},
177 % no marks, thick]
178 % \pgfplotsinvokeforeach{-1,...,3}{
179 % \addplot{smoothstep(0,#1,x)};}
180 % \endaxis
181 % \endtikzpicture
182 % \end
183 % \end{verbatim}\end{fakelisting}
184 % \end{minipage}
185 % \vspace{\parskip}
186 %
187 % (This example also demonstrates the behaviour of the easing
188 % functions in some special cases: when the endpoints $b\le a$, and in
189 % particular the degenerate case where $a=b$, in which the library
190 % chooses to consider the function that is $1$ for all $x\ge 0$ and
191 % $0$ otherwise.)
192 %
193 % Like all functions declared in this way, the functions implemented
194 % by \textsf{easing} are also available as ``public'' macros, such as
195 % |\pgfmathsmoothstep|:
196 %
197 % \vspace{\parskip}
198 % \begin{minipage}[h]{0.5\textwidth}
199 % \foreach\x in{0,0.25,...,1}{
200 % \pgfmathsmoothstep{0}{1}{\x}
201 % $S_1(\x)=\pgfmathresult$\par
202 % }
203 % \end{minipage}%
204 % \begin{minipage}[h]{0.5\textwidth}
205 % \begin{fakelisting}\begin{verbatim}
206 % \input pgf
207 % \usepgflibrary{easing}
208 % \foreach\x in{0,0.25,...,1}{
209 % \pgfmathsmoothstep{0}{1}{\x}
210 % $S_1(\x)=\pgfmathresult$\par
211 % }
212 % \end
213 % \end{verbatim}\end{fakelisting}
214 % \end{minipage}
215 % \vspace{\parskip}
216 %
217 % See Part VIII of the \pgf{} manual for more details on the
218 % mathematical engine.
219 %
220 % \subsection{Naming conventions}
221 %
222 % For each shape, three functions are declared, all of which take
223 % three arguments $a,b$, and $x$. Where $a<b$, all of these function
224 % take value $0$ whenever $x\le a$ and $1$ whenever $x\ge b$. The
225 % names of the functions adhere to the following pattern:
226 %
227 % \begin{itemize}
228 %
229 % \item The \emph{ease-in} form \meta{shape}|easein(|$a$|,|$b$|,|$x$|)| has easing
230 % applied near the endpoint $a$.
231 %
232 % \item The \emph{ease-out} form \meta{shape}|easeout(|$a$|,|$b$|,|$x$|)| has
233 % easing applied near the endpoint $b$. Its graph is that of the
234 % ease-in form reflected about both axes.
235 %
236 % \item The \emph{step function} form \meta{shape}|step(|$a$|,|$b$|,|$x$|)| has
237 % easing applied near both endpoints. Its graph is that of the ease-in
238 % and ease-out forms concatenated then appropriately scaled.
239 %
240 % \end{itemize}
241 %
242 % \vspace{\parskip}
243 % \begin{minipage}[h]{0.5\textwidth}
244 % \tikzpicture
245 % \foreach\x in{0,...,12}{
246 % \draw[gray,dashed]
247 % (0,-1) -- (0,4) (5,-1) -- (5,4);
248 % \draw[thick]
249 % ({5*smootheasein(0,12,\x)},3)
250 % circle (0.25)
251 % ({5*smoothstep(0,12,\x)},1.5)
252 % circle (0.25)
253 % ({5*smootheaseout(0,12,\x)},0)
254 % circle (0.25);
255 % }
256 % \endtikzpicture
257 % \end{minipage}%
258 % \begin{minipage}[h]{0.5\textwidth}
259 % \begin{fakelisting}\begin{verbatim}
260 % \input tikz
261 % \usepgflibrary{easing}
262 % \tikzpicture
263 % \foreach\x in{0,...,12}{
264 % \draw[gray,dashed]
265 % (0,-1) -- (0,4) (5,-1) -- (5,4);
266 % \draw[thick]
267 % ({5*smootheasein(0,12,\x)},3)
268 % circle (0.25)
269 % ({5*smoothstep(0,12,\x)},1.5)
270 % circle (0.25)
271 % ({5*smootheaseout(0,12,\x)},0)
272 % circle (0.25);
273 % }
274 % \endtikzpicture
275 % \end
276 % \end{verbatim}\end{fakelisting}
277 % \end{minipage}
278 % \vspace{\parskip}
279 %
280 % \subsection{Specifying parameters}
281 %
282 % Some of these shapes can be modified by adjusting one or more
283 % parameters, which is done through |pgfkeys|: the parameter
284 % \meta{param} for functions of shape \meta{shape} is specified by
285 % setting the \pgf{} key |/easing/|\meta{shape}|/|\meta{param}:
286 %
287 % \vspace{\parskip}
288 % \begin{minipage}[h]{0.5\textwidth}
289 % \hspace{-0.11\textwidth}
290 % \tikzpicture
291 % \axis[
292 % width=1.1\textwidth, ^^A give up on understanding how pgfplots
293 % ^^A computes the width of a graph and just
294 % ^^A eyeball it
295 % domain=-0.2:1.2, samples=64,
296 % xmin=0, xmax=1, enlarge x limits,
297 % cycle list={
298 % [samples of colormap=6 of viridis]},
299 % no marks, thick]
300 % \pgfplotsinvokeforeach{0,...,4}{
301 % \pgfkeys{easing,back/overshoot=#1}
302 % \addplot{backeaseout(0,1,x)};
303 % }
304 % \endaxis
305 % \endtikzpicture
306 % \end{minipage}%
307 % \begin{minipage}[h]{0.5\textwidth}
308 % \begin{fakelisting}\begin{verbatim}
309 % \input pgfplots
310 % \usepgflibrary{easing}
311 % \tikzpicture
312 % \axis[
313 % domain=-0.2:1.2, samples=64,
314 % xmin=0, xmax=1, enlarge x limits,
315 % cycle list={
316 % [samples of colormap=6 of viridis]},
317 % no marks, thick]
318 % \pgfplotsinvokeforeach{0,...,4}{
319 % \pgfkeys{easing,back/overshoot=#1}
320 % \addplot{backeaseout(0,1,x)};
321 % }
322 % \endaxis
323 % \endtikzpicture
324 % \end
325 % \end{verbatim}\end{fakelisting}
326 % \end{minipage}
327 % \vspace{\parskip}
328 %
329 % Setting a parameter affects the ease-in, step, and ease-out forms of
330 % the relevant function at once.
331 %
332 % For detailed descriptions of the parameters admitted by each shape,
333 % see the following section.
334 %
335 % \section{List of easing function shapes}
336 %
337 % An exhaustive list follows of all the easing functions implemented
338 % by the \textsf{easing} library. For clarity, where mathematical
339 % expressions are given for functions, they are written in terms of
340 % a parameter $t$ equal to $\frac{x}{b-a}$.
341 %
342 % \subsection{Polynomials}
343 %
344 % \subsubsection{The \texttt{smooth} and \texttt{smoother} shapes}
345 %
346 % The step function form of the |smooth| shape is a third-order
347 % Hermite polynomial interpolation between $0$ and $1$, so that the
348 % first derivate at the endpoints are zero. It is defined $3t^2-2t^3$
349 % for $0\le t\le 1$.
350 %
351 % The step function form of the |smoother| shape is a fifth-order
352 % Hermite polynomial interpolation between $0$ and $1$, so that the
353 % first and second derivatives at the endpoints are zero. It is defined
354 % $10t^3-15t^4+6t^5$ for $0\le t\le 1$.
355 %
356 % \foreachtypeeasinggraph{%
357 % \easinggraphlabel{smooth\easingtype}{{\color{white!46!black}smoother\easingtype}}
358 % \easinggraphplot{smoother\easingtype}{46}
359 % \easinggraphplot{smooth\easingtype}{0}
360 % }
361 %
362 % \subsubsection{The \texttt{pow} shape and friends (\texttt{linear}, \texttt{quad},
363 % \texttt{cubic}, \texttt{quart}, and \texttt{quint})}
364 %
365 % Polynomial easing. The ease-in form is defined as $t^n$ for $0\le
366 % t\le 1$, where the exponent $n$ is set with the \pgf{} key
367 % |/easing/pow/exponent|, and should be greater than $0$. The parameter
368 % defaults to $n=2.4$.
369 %
370 % When $n=1$, the function is linear between $0$ and $1$. For
371 % $0<n\le1$, the ease-in form has discontinuous derivative at $0$.
372 %
373 % The shapes |linear|, |quad|, |cubic|, |quart|, and |quint| are the
374 % same functions as |pow| with $n=1,\dots,5$,
375 % respectively. Computations for these shapes are implemented with
376 % \TeX{} registers, which is a little faster and more accurate than
377 % setting the argument then evaluating the equivalent |pow| function.
378 %
379 % \foreachtypeeasinggraph{%
380 % \easinggraphplotfive{pow}{exponent}{n}{0.5,1,2,3,4}}
381 %
382 % \subsubsection{The \texttt{back} shape}
383 %
384 % Anticipatory easing. The ease-in form is defined as $t^2(1-t)s+t^3$
385 % for $0\le t\le 1$, where the parameter $s$ is set with the \pgf{} key
386 % |/easing/back/overshoot|. The parameter defaults to $s=1.6$.
387 %
388 % When $s\le0$, there is no overshoot. When $s=0$, the function is
389 % equivalent to |pow| with $n=3$.
390 %
391 % \def\graphmarginy{0.3}
392 % \foreachtypeeasinggraph{%
393 % \easinggraphplotfive{back}{overshoot}{s}{-0.8,0.0,0.8,1.6,2.4}}
394 % \edef\graphmarginy{\graphmargindefaulty}
395 %
396 % \subsection{Trigonometric and exponential}
397 %
398 % \subsubsection{The \texttt{sine} shape}
399 %
400 % An easing function that looks like a section of a sinusoid. The ease-out form is
401 % defined as $\sin(\frac{\pi}{2}t)$ for $0\le t\le 1$.
402 %
403 % This shape admits no parameters.
404 %
405 % \foreachtypeeasinggraph{%
406 % \easinggraphlabel{\phantom{nothing here}}{sine\easingtype}
407 % \easinggraphplot{sine\easingtype}{0}}
408 %
409 % \subsubsection{The \texttt{exp} shape}
410 %
411 % An easing function that looks like an exponential function. The
412 % ease-in form is defined as $e^{c (t-1)}$ for $0\le t\le 1$, where
413 % the parameter $c$ is set with the \pgf{} key |/easing/exp/speed|,
414 % and should be greater than $0$. The parameter defaults to
415 % $c=7.2$.
416 %
417 % Because of the nature of the exponential function, this shape is
418 % only approximately continuous at the endpoints $a$ and $b$. In
419 % practice, the discontinuity only becomes noticeable for small
420 % $c$, around $c\le 4$.
421 %
422 % \foreachtypeeasinggraph{%
423 % \easinggraphplotfive{exp}{speed}{c}{4,7,10,13,16}}
424 %
425 % \subsection{Other}
426 %
427 % \subsubsection{The \texttt{circ} shape}
428 %
429 % An easing function whose graph is part of an ellipse. This shape
430 % admits no parameters.
431 %
432 % \foreachtypeeasinggraph{%
433 % \easinggraphlabel{\phantom{nothing here}}{circ\easingtype}
434 % \easinggraphplot{circ\easingtype}{0}}
435 %
436 % \subsubsection{The \texttt{elastic} shape}
437 %
438 % Easing function that looks like a damped harmonic oscillator. The
439 % ease-out form is defined as $e^c(t-1)\cos(2\pi f (1-t))$. This shape
440 % admits two parameters:
441 %
442 % \begin{itemize}
443 %
444 % \item The frequency $f$ is the number of oscillations between the
445 % endpoints. It is set with the \pgf{} key
446 % |/easing/elastic/frequency|, and should be greater than $0$. The
447 % frequency defaults to $f=3$.
448 %
449 % \item The damping coefficient $b$ affects the speed at which the
450 % amplitude decays. It is set with the \pgf{} key
451 % |/easing/elastic/damping|, and should be greater than zero. The
452 % damping coefficient defaults to $b=7.2$.
453 %
454 % \end{itemize}
455 %
456 % The function overshoots the range $[0,1]$ when $f>0.5$. For $0<f\le
457 % 1$, this function becomes a family of anticipatory easing curves
458 % that look slightly different from the |back| shape but are more
459 % expensive to compute.
460 %
461 % ^^A twiddle with the size of the background so that the curves don't
462 % ^^A overshoot the box
463 %
464 % \def\graphmarginy{0.5}
465 % \foreachtypeeasinggraph{%
466 % \easinggraphplotfive{elastic}{frequency}{f}{0.5,1.4,2.3,3.2,4.1}}
467 % \edef\graphmarginy{\graphmargindefaulty}
468 %
469 % \StopEventually{\PrintChanges}
470 % \section{Implementation}
471 %
472 % \begin{macro}{\ifeasing@withfpu}
473 % \begin{macro}{\easing@divide}
474 %
475 % This library uses \TeX{} registers and \pgf's mathematical engine for
476 % computations.
477 %
478 % It is possible that the user is loading this library together with
479 % the floating point unit library. We save the basic routines from
480 % |pgfmath|, so that when this happens, the FPU doesn't break
481 % everything when it does a switcharoo with the |pgfmath| macros.
482 %
483 % \begin{macrocode}
484 \newif\ifeasing@withfpu
485 \expandafter\ifx\csname pgflibraryfpuifactive\endcsname\relax
486 \easing@withfpufalse
487 \else
488 \easing@withfputrue
489 \fi
490 \ifeasing@withfpu
491 \let\easing@cos\pgfmath@basic@cos@
492 \let\easing@divide\pgfmath@basic@divide@
493 \let\easing@exp\pgfmath@basic@exp@
494 \let\easing@ln\pgfmath@basic@ln@
495 \let\easing@sqrt\pgfmath@basic@sqrt@
496 \else
497 \let\easing@cos\pgfmathcos@
498 \let\easing@divide\pgfmathdivide@
499 \let\easing@exp\pgfmathexp@
500 \let\easing@ln\pgfmathln@
501 \let\easing@sqrt\pgfmathsqrt@
502 \fi
503 % \end{macrocode}
504 % \end{macro}
505 % \end{macro}
506 %
507 % \begin{macro}{\easing@linearstep@ne}
508 % \begin{macro}{\easing@linearstep@fixed}
509 % \begin{macro}{\easing@linearstep@float}
510 % \begin{macro}{\easing@linearstep}
511 %
512 % In absence of the FPU, the next section of code defines
513 % |\easing@linearstep|, which expects as arguments plain numbers
514 % (i.e. things that can be assigned to dimension registers). The net
515 % effect of |\easing@linearstep{#1}{#2}{#3}| is to set
516 % |\pgfmathresult| to
517 % $\frac{\mathtt{\#3}-\mathtt{\#1}}{\mathtt{\#2}-\mathtt{\#1}}$,
518 % clamped to between $0$ and $1$.
519 %
520 % If the FPU is loaded, |\easing@linearstep| is instead named
521 % |\easing@linearstep@fixed|, and we additionally define
522 % |\easing@linearstep@float|, which expects FPU-format floats as
523 % arguments. We do not format the output as a float since the FPU is
524 % smart enough to do that conversion quietly on its own.
525 %
526 % The |\easing@linearstep| routine is the first step in the definition
527 % of all other routines that compute easing functions.
528 %
529 % \begin{macrocode}
530 \def\easing@linearstep@ne#1{%
531 \begingroup
532 \pgf@x#1pt
533 \ifdim1pt<\pgf@x\pgf@x 1pt\fi
534 \ifdim0pt>\pgf@x\pgf@x 0pt\fi
535 \pgfmathreturn\pgf@x
536 \endgroup
537 }%
538 \expandafter\def
539 \csname easing@linearstep\ifeasing@withfpu @fixed\fi\endcsname#1#2#3{%
540 \begingroup
541 \pgf@xa#3pt
542 \pgf@xb#2pt
543 \pgf@xc#1pt
544 \ifdim\pgf@xb=\pgf@xc
545 \edef\pgfmathresult{\ifdim\pgf@xa>\pgf@xb 1\else 0\fi}%
546 \else
547 \advance\pgf@xa-\pgf@xc
548 \advance\pgf@xb-\pgf@xc
549 \easing@divide{\pgfmath@tonumber\pgf@xa}{\pgfmath@tonumber\pgf@xb}%
550 \easing@linearstep@ne\pgfmathresult
551 \fi
552 \pgfmathsmuggle\pgfmathresult
553 \endgroup
554 }%
555 \ifeasing@withfpu
556 \def\easing@linearstep@float#1#2#3{%
557 \begingroup
558 \pgfmathfloatsubtract{#3}{#1}%
559 \edef\pgf@tempa{\pgfmathresult}%
560 \pgfmathfloatsubtract{#2}{#1}%
561 \edef\pgf@tempb{\pgfmathresult}%
562 \pgfmathfloatifflags{\pgf@tempb}{0}{%
563 \pgfmathfloatifflags{\pgf@tempa}{-}{%
564 \edef\pgfmathresult{0}%
565 }{%
566 \edef\pgfmathresult{1}%
567 }%
568 }{%
569 \pgfmathfloatdivide\pgf@tempa\pgf@tempb
570 \pgfmathfloattofixed{\pgfmathresult}%
571 \easing@linearstep@ne\pgfmathresult
572 }%
573 \pgfmathsmuggle\pgfmathresult
574 \endgroup
575 }%
576 \def\easing@linearstep#1#2#3{%
577 \pgflibraryfpuifactive{%
578 \easing@linearstep@float{#1}{#2}{#3}}{%
579 \easing@linearstep@fixed{#1}{#2}{#3}}%
580 }%
581 \fi
582 % \end{macrocode}
583 % \end{macro}
584 % \end{macro}
585 % \end{macro}
586 % \end{macro}
587 %
588 % \begin{macro}{\easing@linearstep@easein@ne}
589 % \begin{macro}{\easing@linearstep@easeout@ne}
590 %
591 % The linear ease-in and ease-out functions are identical to the
592 % linear step function. We define the respective macros so as not to
593 % surprise the user with their absence.
594 %
595 % \begin{macrocode}
596 \let\easing@lineareasein\easing@linearstep
597 \pgfmathdeclarefunction{lineareasein}{3}{%
598 \easing@lineareasein{#1}{#2}{#3}}%
599 \let\easing@lineareaseout\easing@linearstep
600 \pgfmathdeclarefunction{lineareaseout}{3}{%
601 \easing@lineareasein{#1}{#2}{#3}}%
602 % \end{macrocode}
603 % \end{macro}
604 % \end{macro}
605 %
606 % ^^A the next few macros have long names, so we scoot this page to
607 % ^^A the right to make space in the margins:
608 %
609 % \begingroup
610 % \addtolength\oddsidemargin{50pt}
611 % \addtolength\evensidemargin{50pt}
612 %
613 % \begin{macro}{\easing@derive@easein@nefromstep@ne}
614 % \begin{macro}{\easing@derive@easeout@nefromstep@ne}
615 % \begin{macro}{\easing@derive@step@nefromeasein@ne}
616 % \begin{macro}{\easing@derive@easeout@nefromeasein@ne}
617 %
618 % The pattern in general is that, for each shape, we define the
619 % one-parameter version of the step, ease-in, and ease-out routines
620 % interpolating between values $0$ at $1$ at the ends of the unit
621 % interval. Then by composing with |\easing@linearstep|, we obtain the
622 % three-parameter versions that allow the user to specify the begin
623 % and end points of the interpolation.
624 %
625 % Most of the time it suffices to define just one of the three
626 % one-parameter versions of a shape to be able to infer the form of
627 % all three. This is done with the |\easing@derive|--|from|-- macros.
628 %
629 % \begin{macrocode}
630 \def\easing@derive@easein@nefromstep@ne#1{%
631 \expandafter\def\csname easing@#1easein@ne\endcsname##1{%
632 \begingroup
633 \pgf@x##1 pt
634 \divide\pgf@x 2
635 \csname easing@#1step@ne\endcsname{\pgfmath@tonumber\pgf@x}%
636 \pgf@x\pgfmathresult pt
637 \multiply\pgf@x 2
638 \pgfmathreturn\pgf@x
639 \endgroup
640 }%
641 }%
642 \def\easing@derive@easeout@nefromstep@ne#1{%
643 \expandafter\def\csname easing@#1easeout@ne\endcsname##1{%
644 \begingroup
645 \pgf@x##1 pt
646 \divide\pgf@x 2
647 \advance\pgf@x 0.5pt
648 \csname easing@#1step@ne\endcsname{\pgfmath@tonumber\pgf@x}%
649 \pgf@x\pgfmathresult pt
650 \multiply\pgf@x 2
651 \advance\pgf@x -1pt
652 \pgfmathreturn\pgf@x
653 \endgroup
654 }%
655 }%
656 \def\easing@derive@step@nefromeasein@ne#1{%
657 \expandafter\def\csname easing@#1step@ne\endcsname##1{%
658 \begingroup
659 \pgf@x##1 pt
660 \multiply\pgf@x 2
661 \ifdim\pgf@x<1pt
662 \csname easing@#1easein@ne\endcsname{\pgfmath@tonumber\pgf@x}%
663 \pgf@x\pgfmathresult pt
664 \divide\pgf@x 2
665 \else
666 \multiply\pgf@x -1
667 \advance\pgf@x 2pt
668 \csname easing@#1easein@ne\endcsname{\pgfmath@tonumber\pgf@x}%
669 \pgf@x\pgfmathresult pt
670 \divide\pgf@x 2
671 \multiply\pgf@x -1
672 \advance\pgf@x 1pt
673 \fi
674 \pgfmathreturn\pgf@x
675 \endgroup
676 }%
677 }%
678 \def\easing@derive@easeout@nefromeasein@ne#1{%
679 \expandafter\def\csname easing@#1easeout@ne\endcsname##1{%
680 \begingroup
681 \pgf@x##1pt
682 \multiply\pgf@x -1
683 \advance\pgf@x 1pt
684 \csname easing@#1easein@ne\endcsname{\pgfmath@tonumber\pgf@x}%
685 \pgf@x\pgfmathresult pt
686 \multiply\pgf@x -1
687 \advance\pgf@x 1pt
688 \pgfmathreturn\pgf@x
689 \endgroup
690 }%
691 }%
692 % \end{macrocode}
693 % \end{macro}
694 % \end{macro}
695 % \end{macro}
696 % \end{macro}
697 % \endgroup ^^A marginpar modifications
698 %
699 % \begin{macro}{\easing@pgfmathinstall}
700 %
701 % The three-parameter versions of each routine is installed
702 % into the mathematical engine, so that they are available in
703 % |\pgfmathparse|.
704 %
705 % \begin{macrocode}
706 \def\easing@pgfmathinstall#1{%
707 \pgfmathdeclarefunction{#1step}{3}{%
708 \easing@linearstep{##1}{##2}{##3}%
709 \csname easing@#1step@ne\endcsname\pgfmathresult
710 }%
711 \pgfmathdeclarefunction{#1easein}{3}{%
712 \easing@linearstep{##1}{##2}{##3}%
713 \csname easing@#1easein@ne\endcsname\pgfmathresult
714 }%
715 \pgfmathdeclarefunction{#1easeout}{3}{%
716 \easing@linearstep{##1}{##2}{##3}%
717 \csname easing@#1easeout@ne\endcsname\pgfmathresult
718 }%
719 }%
720 % \end{macrocode}
721 % \end{macro}
722 %
723 % \begin{macro}{\easing@smoothstep@ne}
724 % \begin{macro}{\easing@smootheasein@ne}
725 % \begin{macro}{\easing@smootheaseout@ne}
726 %
727 % The |smooth| shape.
728 %
729 % \begin{macrocode}
730 \def\easing@smoothstep@ne#1{%
731 \begingroup
732 \pgf@x#1pt
733 \edef\pgf@temp{\pgfmath@tonumber\pgf@x}%
734 \multiply\pgf@x-2
735 \advance\pgf@x 3pt
736 \pgf@x\pgf@temp\pgf@x
737 \pgf@x\pgf@temp\pgf@x
738 \pgfmathreturn\pgf@x
739 \endgroup
740 }%
741 \easing@derive@easein@nefromstep@ne{smooth}%
742 \easing@derive@easeout@nefromstep@ne{smooth}%
743 \easing@pgfmathinstall{smooth}%
744 % \end{macrocode}
745 % \end{macro}
746 % \end{macro}
747 % \end{macro}
748 %
749 % \begin{macro}{\easing@smootherstep@ne}
750 % \begin{macro}{\easing@smoothereasein@ne}
751 % \begin{macro}{\easing@smoothereaseout@ne}
752 %
753 % The |smoother| shape.
754 %
755 % \begin{macrocode}
756 \def\easing@smootherstep@ne#1{%
757 \begingroup
758 \pgf@x#1pt
759 \edef\pgf@temp{\pgfmath@tonumber\pgf@x}%
760 \multiply\pgf@x 6
761 \advance\pgf@x -15pt
762 \pgf@x\pgf@temp\pgf@x
763 \advance\pgf@x 10pt
764 \pgf@x\pgf@temp\pgf@x
765 \pgf@x\pgf@temp\pgf@x
766 \pgf@x\pgf@temp\pgf@x
767 \pgfmathreturn\pgf@x
768 \endgroup
769 }%
770 \easing@derive@easein@nefromstep@ne{smoother}%
771 \easing@derive@easeout@nefromstep@ne{smoother}%
772 \easing@pgfmathinstall{smoother}%
773 % \end{macrocode}
774 % \end{macro}
775 % \end{macro}
776 % \end{macro}
777 %
778 % \begin{macro}{\easing@powstep@ne}
779 % \begin{macro}{\easing@poweasein@ne}
780 % \begin{macro}{\easing@poweaseout@ne}
781 %
782 % The |pow| shape.
783 %
784 % Because of some wonkiness in the FPU, |\pgfmath@pow@basic@| actually
785 % doesn't work. Instead of invoking the |pow| function, we compute
786 % $t^n$ approximately by computing $e^{n\ln t}$ using |ln| and |exp|
787 % instead (which is what |pgfmath| does anyway when the exponent is
788 % not an integer.)
789 %
790 % \begin{macrocode}
791 \pgfkeys{/easing/.is family}%
792 \pgfkeys{easing,
793 pow/exponent/.estore in=\easing@param@pow@exponent,
794 pow/exponent/.default=2.4,
795 pow/exponent}%
796 \def\easing@poweasein@ne#1{%
797 \begingroup
798 \pgf@x#1pt
799 \ifdim\pgf@x=0pt
800 \edef\pgfmathresult{0}%
801 \else
802 \easing@ln{#1}%
803 \pgf@x\pgfmathresult pt
804 \pgf@x\easing@param@pow@exponent\pgf@x
805 \easing@exp{\pgfmath@tonumber\pgf@x}%
806 \fi
807 \pgfmathsmuggle\pgfmathresult
808 \endgroup
809 }%
810 \easing@derive@easeout@nefromeasein@ne{pow}%
811 \easing@derive@step@nefromeasein@ne{pow}%
812 \easing@pgfmathinstall{pow}%
813 % \end{macrocode}
814 % \end{macro}
815 % \end{macro}
816 % \end{macro}
817 %
818 % \begin{macro}{\easing@quadstep@ne}
819 % \begin{macro}{\easing@quadeasein@ne}
820 % \begin{macro}{\easing@quadeaseout@ne}
821 %
822 % \begin{macro}{\easing@cubicstep@ne}
823 % \begin{macro}{\easing@cubiceasein@ne}
824 % \begin{macro}{\easing@cubiceaseout@ne}
825 %
826 % \begin{macro}{\easing@quartstep@ne}
827 % \begin{macro}{\easing@quarteasein@ne}
828 % \begin{macro}{\easing@quarteaseout@ne}
829 %
830 % \begin{macro}{\easing@quintstep@ne}
831 % \begin{macro}{\easing@quinteasein@ne}
832 % \begin{macro}{\easing@quinteaseout@ne}
833 %
834 % The |quad|--, |cubic|--, |quart|--, and |quint|-- routines have
835 % explicit definitions.
836 %
837 % \begin{macrocode}
838 \def\easing@quadeasein@ne#1{%
839 \begingroup
840 \pgf@x#1pt
841 \edef\pgf@temp{\pgfmath@tonumber\pgf@x}%
842 \pgf@x\pgf@temp\pgf@x
843 \pgfmathreturn\pgf@x
844 \endgroup
845 }%
846 \easing@derive@step@nefromeasein@ne{quad}%
847 \easing@derive@easeout@nefromeasein@ne{quad}%
848 \easing@pgfmathinstall{quad}%
849 %
850 \def\easing@cubiceasein@ne#1{%
851 \begingroup
852 \pgf@x#1pt
853 \edef\pgf@temp{\pgfmath@tonumber\pgf@x}%
854 \pgf@x\pgf@temp\pgf@x
855 \pgf@x\pgf@temp\pgf@x
856 \pgfmathreturn\pgf@x
857 \endgroup
858 }%
859 \easing@derive@step@nefromeasein@ne{cubic}%
860 \easing@derive@easeout@nefromeasein@ne{cubic}%
861 \easing@pgfmathinstall{cubic}%
862 %
863 \def\easing@quarteasein@ne#1{%
864 \begingroup
865 \pgf@x#1pt
866 \edef\pgf@temp{\pgfmath@tonumber\pgf@x}%
867 \pgf@x\pgf@temp\pgf@x
868 \pgf@x\pgf@temp\pgf@x
869 \pgf@x\pgf@temp\pgf@x
870 \pgfmathreturn\pgf@x
871 \endgroup
872 }%
873 \easing@derive@step@nefromeasein@ne{quart}%
874 \easing@derive@easeout@nefromeasein@ne{quart}%
875 \easing@pgfmathinstall{quart}%
876 %
877 \def\easing@quinteasein@ne#1{%
878 \begingroup
879 \pgf@x#1pt
880 \edef\pgf@temp{\pgfmath@tonumber\pgf@x}%
881 \pgf@x\pgf@temp\pgf@x
882 \pgf@x\pgf@temp\pgf@x
883 \pgf@x\pgf@temp\pgf@x
884 \pgf@x\pgf@temp\pgf@x
885 \pgfmathreturn\pgf@x
886 \endgroup
887 }%
888 \easing@derive@step@nefromeasein@ne{quint}%
889 \easing@derive@easeout@nefromeasein@ne{quint}%
890 \easing@pgfmathinstall{quint}%
891 % \end{macrocode}
892 % \end{macro}
893 % \end{macro}
894 % \end{macro}
895 %
896 % \end{macro}
897 % \end{macro}
898 % \end{macro}
899 %
900 % \end{macro}
901 % \end{macro}
902 % \end{macro}
903 %
904 % \end{macro}
905 % \end{macro}
906 % \end{macro}
907 %
908 % \begin{macro}{\easing@backstep@ne}
909 % \begin{macro}{\easing@backeasein@ne}
910 % \begin{macro}{\easing@backeaseout@ne}
911 %
912 % The |back| shape.
913 %
914 % \begin{macrocode}
915 \pgfkeys{easing,
916 back/overshoot/.estore in=\easing@param@back@overshoot,
917 back/overshoot/.default=1.6,
918 back/overshoot}%
919 \def\easing@backeasein@ne#1{%
920 \begingroup
921 \pgf@x#1pt
922 \edef\pgf@temp{\pgfmath@tonumber\pgf@x}%
923 \advance\pgf@x -1pt
924 \pgf@x\easing@param@back@overshoot\pgf@x
925 \advance\pgf@x\pgf@temp pt
926 \pgf@x\pgf@temp\pgf@x
927 \pgf@x\pgf@temp\pgf@x
928 \pgfmathreturn\pgf@x
929 \endgroup
930 }%
931 \easing@derive@step@nefromeasein@ne{back}%
932 \easing@derive@easeout@nefromeasein@ne{back}%
933 \easing@pgfmathinstall{back}%
934 % \end{macrocode}
935 % \end{macro}
936 % \end{macro}
937 % \end{macro}
938 %
939 % \begin{macro}{\easing@sinestep@ne}
940 % \begin{macro}{\easing@sineeasein@ne}
941 % \begin{macro}{\easing@sineeaseout@ne}
942 %
943 % The |sine| shape.
944 %
945 % We write down both the |easein| and |step| forms of this, since they
946 % are simple compared to what would have been obtained by
947 % |\easing@derive|--.
948 %
949 % \begin{macrocode}
950 \def\easing@sineeasein@ne#1{%
951 \begingroup
952 \pgf@x#1pt
953 \multiply\pgf@x 90
954 \easing@cos{\pgfmath@tonumber\pgf@x}%
955 \pgf@x\pgfmathresult pt
956 \multiply\pgf@x -1
957 \advance\pgf@x 1pt
958 \pgfmathreturn\pgf@x
959 \endgroup
960 }%
961 \def\easing@sinestep@ne#1{%
962 \begingroup
963 \pgf@x#1pt
964 \multiply\pgf@x 180
965 \easing@cos{\pgfmath@tonumber\pgf@x}%
966 \pgf@x\pgfmathresult pt
967 \divide\pgf@x 2
968 \multiply\pgf@x -1
969 \advance\pgf@x 0.5pt
970 \pgfmathreturn\pgf@x
971 \endgroup
972 }%
973 \easing@derive@easeout@nefromeasein@ne{sine}%
974 \easing@pgfmathinstall{sine}%
975 % \end{macrocode}
976 % \end{macro}
977 % \end{macro}
978 % \end{macro}
979 %
980 % \begin{macro}{\easing@expstep@ne}
981 % \begin{macro}{\easing@expeasein@ne}
982 % \begin{macro}{\easing@expeaseout@ne}
983 %
984 % The |exp| shape.
985 %
986 % \begin{macrocode}
987 \pgfkeys{easing,
988 exp/speed/.estore in=\easing@param@exponent@speed,
989 exp/speed/.default=7.2,
990 exp/speed}%
991 \def\easing@expeasein@ne#1{%
992 \begingroup
993 \pgf@x#1pt
994 \advance\pgf@x -1pt
995 \pgf@x\easing@param@exponent@speed\pgf@x
996 \easing@exp{\pgfmath@tonumber\pgf@x}%
997 \pgfmathsmuggle\pgfmathresult
998 \endgroup
999 }%
1000 \easing@derive@step@nefromeasein@ne{exp}%
1001 \easing@derive@easeout@nefromeasein@ne{exp}%
1002 \easing@pgfmathinstall{exp}%
1003 % \end{macrocode}
1004 %
1005 % \end{macro}
1006 % \end{macro}
1007 % \end{macro}
1008 %
1009 % \begin{macro}{\easing@circstep@ne}
1010 % \begin{macro}{\easing@circeasein@ne}
1011 % \begin{macro}{\easing@circeaseout@ne}
1012 %
1013 % The |circ| shape.
1014 %
1015 % \begin{macrocode}
1016 \def\easing@circeasein@ne#1{%
1017 \begingroup
1018 \pgf@x#1pt
1019 \advance\pgf@x -1pt
1020 \edef\pgf@temp{\pgfmath@tonumber\pgf@x}%
1021 \pgf@x\pgf@temp\pgf@x
1022 \multiply\pgf@x -1
1023 \advance\pgf@x 1pt
1024 \easing@sqrt{\pgfmath@tonumber\pgf@x}%
1025 \pgfmathsmuggle\pgfmathresult
1026 \endgroup
1027 }%
1028 \easing@derive@step@nefromeasein@ne{circ}%
1029 \easing@derive@easeout@nefromeasein@ne{circ}%
1030 \easing@pgfmathinstall{circ}%
1031 % \end{macrocode}
1032 %
1033 % \end{macro}
1034 % \end{macro}
1035 % \end{macro}
1036 %
1037 % \begin{macro}{\easing@elasticstep@ne}
1038 % \begin{macro}{\easing@elasticeasein@ne}
1039 % \begin{macro}{\easing@elasticeaseout@ne}
1040 %
1041 % The |elastic| shape.
1042 %
1043 % \begin{macrocode}
1044 \pgfkeys{easing,
1045 elastic/frequency/.estore in=\easing@param@elastic@frequency,
1046 elastic/damping/.estore in=\easing@param@elastic@damping,
1047 elastic/frequency/.default=3,
1048 elastic/damping/.default=7.2,
1049 elastic/frequency, elastic/damping}%
1050 \def\easing@elasticeasein@ne#1{%
1051 \begingroup
1052 \pgf@xa#1pt
1053 \advance\pgf@xa -1pt
1054 \pgf@xb-\pgf@xa
1055 \pgf@xa\easing@param@elastic@damping\pgf@xa
1056 \easing@exp{\pgfmath@tonumber\pgf@xa}%
1057 \pgf@xa\pgfmathresult pt
1058 \pgf@xb 360\pgf@xb
1059 \pgf@xb\easing@param@elastic@frequency\pgf@xb
1060 \easing@cos{\pgfmath@tonumber\pgf@xb}%
1061 \pgf@xa\pgfmathresult\pgf@xa
1062 \pgfmathreturn\pgf@xa
1063 \endgroup
1064 }%
1065 \easing@derive@step@nefromeasein@ne{elastic}%
1066 \easing@derive@easeout@nefromeasein@ne{elastic}%
1067 \easing@pgfmathinstall{elastic}%
1068 % \end{macrocode}
1069 % \end{macro}
1070 % \end{macro}
1071 % \end{macro}
1072 %
1073 % \Finale