summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/liftarm/liftarm.sty
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/pgf/contrib/liftarm/liftarm.sty')
-rw-r--r--graphics/pgf/contrib/liftarm/liftarm.sty132
1 files changed, 106 insertions, 26 deletions
diff --git a/graphics/pgf/contrib/liftarm/liftarm.sty b/graphics/pgf/contrib/liftarm/liftarm.sty
index 9cd8660f8e..b850c8f16a 100644
--- a/graphics/pgf/contrib/liftarm/liftarm.sty
+++ b/graphics/pgf/contrib/liftarm/liftarm.sty
@@ -1,20 +1,36 @@
-%liftarm package
-%Draw liftarms with TikZ
-%(c) Matthias Floré
-%This program can be redistributed and/or modified under the terms of the LaTeX Project Public License Distributed from CTAN archives on http://www.latex-project.org/lppl.txt.
+%% liftarm.sty
+%% Copyright 2022 Matthias Floré
+%
+% This work may be distributed and/or modified under the
+% conditions of the LaTeX Project Public License, either version 1.3
+% of this license or (at your option) any later version.
+% The latest version of this license is in
+% http://www.latex-project.org/lppl.txt
+% and version 1.3 or later is part of all distributions of LaTeX
+% version 2005/12/01 or later.
+%
+% This work has the LPPL maintenance status `maintained'.
+%
+% The Current Maintainer of this work is Matthias Floré.
+%
+% This work consists of the files liftarm.pdf, liftarm.sty,
+% liftarm.tex and README.md.
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{liftarm}[2022/03/06 v1.0 Draw liftarms with TikZ]
+\ProvidesPackage{liftarm}[2022/04/07 v2.0 Draw liftarms with TikZ]
\RequirePackage{etoolbox}
\RequirePackage[dvipsnames]{xcolor}
\RequirePackage{tikz}
\usetikzlibrary{calc}
+\newif\ifliftarm@animate
\newif\ifliftarm@brick
-\newif\ifliftarm@contour
\newif\ifliftarm@connectreverse
+\newif\ifliftarm@contour
\pgfkeys{
/liftarm/.is family,
/liftarm/.unknown/.code={\edef\liftarm@colorkey{\pgfkeyscurrentname}},
/liftarm,
+axle holes/.store in=\liftarm@axleholes,
+brick/.is if=liftarm@brick,
color/.store in=\liftarm@colorkey,
color 0/.initial=Gray,
color 1/.initial=darkgray,
@@ -25,27 +41,26 @@ color 5/.initial=Green,
color 6/.initial=Blue,
color 7/.initial=Brown,
color modulo/.initial=8,
-brick/.is if=liftarm@brick,
-axle holes/.store in=\liftarm@axleholes,
-mark holes/.store in=\liftarm@markholes,
-mark color/.initial=Black,
-screw holes/.store in=\liftarm@screwholes,
-screw holes angle/.initial=45,
-screw color/.initial=Black,
-scalefactor/.initial=0.5,
+connect/.store in=\liftarm@connect,
+connect coordinate/.store in=\liftarm@connectcoordinate,
+connect reverse/.is if=liftarm@connectreverse,
contour/.is if=liftarm@contour,
coordinate/.store in=\liftarm@coordinate,
-connect coordinate/.store in=\liftarm@connectcoordinate,
-connect/.store in=\liftarm@connect,
globalize/.code n args={2}{\xdef#1{#2}},
-liftarm 1 options/.style={},
+hole radius/.initial=0.3,
liftarm 1/.style={liftarm 1 options/.style={#1}},
-liftarm 2 options/.style={},
+liftarm 1 options/.style={},
liftarm 2/.style={liftarm 2 options/.style={#1}},
-origin/.initial=0,
-connect reverse/.is if=liftarm@connectreverse,
-hole radius/.initial=0.3,
+liftarm 2 options/.style={},
liftarm thickness/.initial=0.92,
+mark color/.initial=Black,
+mark holes/.store in=\liftarm@markholes,
+origin/.initial=0,
+scalefactor/.initial=0.5,
+screw color/.initial=Black,
+screw holes/.store in=\liftarm@screwholes,
+screw holes angle/.initial=45,
+trace/.store in=\liftarm@trace,
}
\pgfmathsetmacro{\liftarm@axleholeangle}{14}%2*\liftarm@axleholeradius*sin(\liftarm@axleholeangle)=1.78/8
\pgfmathsetmacro{\liftarm@screwholestartangle}{10}
@@ -145,6 +160,32 @@ liftarm thickness/.initial=0.92,
\coordinate (\liftarm@name) at (\liftarm@value,0);
}
\fi
+\ifcsname liftarm@trace\endcsname
+\ifliftarm@animate
+\foreach\liftarm@n/\liftarm@numberofframes/\liftarm@tracefigure in \liftarm@trace{
+\pgfmathsetmacro{\liftarm@value}{\liftarm@n}
+\gappto\liftarm@animateframestrace{\newframe\begin{scope}}
+\addtocounter{liftarm@animateframenumber}{1}
+\xappto\liftarm@animateframestrace{[shift={(#2)},rotate=\liftarm@ang]}
+\gappto\liftarm@animateframestrace{\begin{scope}}
+\xappto\liftarm@animateframestrace{[shift={(\liftarm@value-\liftarm@origin,0)}]}
+\ifdefempty{\liftarm@tracefigure}{
+\gappto\liftarm@animateframestrace{\fill[Black] (0,0) circle}
+\xappto\liftarm@animateframestrace{[radius=0.66*\liftarm@holeradius];}
+}
+{
+\xappto\liftarm@animateframestrace{\expandonce\liftarm@tracefigure}
+}
+\gappto\liftarm@animateframestrace{\end{scope}\end{scope}}
+\ifdefempty{\liftarm@numberofframes}{
+\csxappto{liftarm@animatetimeline0}{\theliftarm@animateframenumber x0,}
+}
+{
+\csxappto{liftarm@animatetimeline\theliftarm@animatestepnumber}{\theliftarm@animateframenumber x\liftarm@numberofframes,}
+}
+}
+\fi
+\fi
\end{scope}
\end{scope}
\fi
@@ -194,11 +235,11 @@ in
/liftarm/globalize={\liftarm@connectyblet}{\n2}
]
;
-\pgfmathsetmacro{\liftarm@connectxa}{\liftarm@connectxalet};
-\pgfmathsetmacro{\liftarm@connectya}{\liftarm@connectyalet};
-\pgfmathsetmacro{\liftarm@connectxb}{\liftarm@connectxblet};
-\pgfmathsetmacro{\liftarm@connectyb}{\liftarm@connectyblet};
-\pgfmathsetmacro{\liftarm@absdiff}{abs(\liftarm@connectxa-\liftarm@connectxb)};
+\pgfmathsetmacro{\liftarm@connectxa}{\liftarm@connectxalet}
+\pgfmathsetmacro{\liftarm@connectya}{\liftarm@connectyalet}
+\pgfmathsetmacro{\liftarm@connectxb}{\liftarm@connectxblet}
+\pgfmathsetmacro{\liftarm@connectyb}{\liftarm@connectyblet}
+\pgfmathsetmacro{\liftarm@absdiff}{abs(\liftarm@connectxa-\liftarm@connectxb)}
\ifdim \liftarm@absdiff pt<0.001 pt
\pgfmathsetmacro{\liftarm@connectanglegamma}{90}
\ifdim \liftarm@connectya pt<\liftarm@connectyb pt
@@ -253,4 +294,43 @@ in
\expandafter\liftarm@construction\expandafter[\liftarm@constructoptions]{#1}
}
\newenvironment{liftarmconstruction}[1][]{\def\liftarm@constructoptions{#1}\def\liftarm@constructfigure{}\begin{enumerate}}{\end{enumerate}}
+\newcounter{liftarm@animatenumberofsteps}
+\newcounter{liftarm@animateframenumber}
+\newcounter{liftarm@animatestepnumber}
+\newwrite\liftarm@animatewritetimeline
+\newcounter{liftarm@animatenumberofanimation}
+\newcommand{\liftarmanimate}[4][]{%
+\liftarm@animatetrue%
+\addtocounter{liftarm@animatenumberofanimation}{1}%
+\setcounter{liftarm@animatenumberofsteps}{-1}%
+\gdef\liftarm@animateframes{}%
+\gdef\liftarm@animateframestrace{}%
+\setcounter{liftarm@animatestepnumber}{-1}%
+\foreach\liftarm@n in {#3}{%
+\addtocounter{liftarm@animatenumberofsteps}{1}%
+\gappto\liftarm@animateframes{\newframe\addtocounter{liftarm@animatestepnumber}{1}#4}%
+\xappto\liftarm@animateframes{{\liftarm@n}}%
+}%
+\patchcmd{\liftarm@animateframes}{\newframe}{}{}{}%
+\csgdef{liftarm@animatetimeline0}{c,}%
+\foreach\liftarm@n in {1,...,\theliftarm@animatenumberofsteps}{%
+\csgdef{liftarm@animatetimeline\liftarm@n}{}%
+}%
+\setcounter{liftarm@animateframenumber}{\theliftarm@animatenumberofsteps}%
+\IfFileExists{\jobname\theliftarm@animatenumberofanimation.tln}{}{%
+\immediate\openout\liftarm@animatewritetimeline=\jobname\theliftarm@animatenumberofanimation.tln%
+\immediate\write\liftarm@animatewritetimeline{::c,0}%
+\immediate\closeout\liftarm@animatewritetimeline%
+}%
+\begin{animateinline}[#1,timeline=\jobname\theliftarm@animatenumberofanimation.tln]{#2}%
+\liftarm@animateframes%
+\liftarm@animateframestrace%
+\end{animateinline}%
+\immediate\openout\liftarm@animatewritetimeline=\jobname\theliftarm@animatenumberofanimation.tln%
+\foreach\liftarm@n in {0,...,\theliftarm@animatenumberofsteps}{%
+\immediate\write\liftarm@animatewritetimeline{::\csname liftarm@animatetimeline\liftarm@n\endcsname\liftarm@n}%
+}%
+\immediate\closeout\liftarm@animatewritetimeline%
+\liftarm@animatefalse%
+}
\endinput \ No newline at end of file