-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a jigsaw puzzle decoration #1357
Comments
If you want to use control sequence with Either way, here is the decoration with those hard-coded numbers in TeX-math (so, without PGFMath on top). I've added a A part from adding more customization, it would be nice to just provide a list of piece-wise customization so that a full path can be decorated with just one decoration. (This would help to decorate nodes since you can't access the separate path segments.) I don't see a built-in decoration that uses this but I have some ideas … \documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations}
% jigsaw puzzle decorations
%
% Parameters: \pgfdecorationegmentaspect
\makeatletter
\pgfdeclaredecoration{jigsaw}{jigsaw}{%
\state{jigsaw}[
width=+\pgfdecoratedremainingdistance,
next state=final,
if input segment is closepath={next state=close}
]{%
\pgf@yd=\pgfdecorationsegmentaspect\pgfdecoratedremainingdistance
\pgf@yd=2\pgf@yd % 2 * aspect * remaining dist
\pgf@yc=.26\pgf@yd % .26 * 2 * aspect * remaining dist
\pgf@ya=.04\pgf@yd % .04 * 2 * aspect * remaining dist
\pgf@yb=.11\pgf@yd % .11 * 2 * aspect * remaining dist
%
\pgf@xd=\pgfdecorationsegmentaspect pt
\pgf@xa=-.2\pgf@xd % - .2*aspect
\advance\pgf@xa by .5pt % .5 - .2*aspect
\pgf@xa=\pgf@sys@tonumber\pgf@xa\pgfdecoratedremainingdistance
\pgf@xb=.2\pgf@xd % .2*aspect
\advance\pgf@xb by .5pt % .5 + .2*aspect
\pgf@xb=\pgf@sys@tonumber\pgf@xb\pgfdecoratedremainingdistance
\pgf@xc=-.6\pgf@xd % - .6*aspect
\advance\pgf@xc by .5pt % .5 - .6*aspect
\pgf@xc=\pgf@sys@tonumber\pgf@xc\pgfdecoratedremainingdistance
\pgf@xd=.6\pgf@xd % .6*aspect
\advance\pgf@xd by .5pt % .5 + .6*aspect
\pgf@xd=\pgf@sys@tonumber\pgf@xd\pgfdecoratedremainingdistance
%
\edef\pgf@marshal{%
\noexpand\pgfpathcurveto
{\noexpand\pgfqpoint{0pt}{0pt}}
{\noexpand\pgfqpoint{\the\pgf@xa}{-\the\pgf@ya}}
{\noexpand\pgfqpoint{\the\pgf@xa}{\the\pgf@ya}}%
\noexpand\pgfpathcurveto
{\noexpand\pgfqpoint{\the\pgf@xa}{\the\pgf@yb}}
{\noexpand\pgfqpoint{\the\pgf@xc}{\the\pgf@yc}}
{\noexpand\pgfqpoint{.5\pgfdecoratedremainingdistance}{\the\pgf@yc}}%
\noexpand\pgfpathcurveto
{\noexpand\pgfqpoint{\the\pgf@xd}{\the\pgf@yc}}
{\noexpand\pgfqpoint{\the\pgf@xb}{\the\pgf@yb}}
{\noexpand\pgfqpoint{\the\pgf@xb}{\the\pgf@ya}}%
\noexpand\pgfpathcurveto
{\noexpand\pgfqpoint{\the\pgf@xb}{-\the\pgf@ya}}
{\noexpand\pgfpointdecoratedinputsegmentlast}
{\noexpand\pgfpointdecoratedinputsegmentlast}}%
\pgf@marshal
}
\state{close}[next state=final]{\pgfpathclose}%
\state{final}{}%
}%
\makeatother
\begin{document}
\tikz[x=3cm, y=3cm, line width=2mm]
\draw[fill=red!20] (0,0)
decorate[decoration=jigsaw] { -- (0,1)}
decorate[decoration={jigsaw, mirror}] { -- (1,1)}
decorate[decoration={jigsaw, mirror}] { -- (1,0)}
decorate[decoration=jigsaw] { -- cycle};
\end{document} |
I experienced that error. It makes sense now, thanks.
Thank you! This looks way cleaner. Some words about parametrization:
With the current code, the height is set to My first attempt was this parametrization:
Advantages: The argument effects fit to their description. Both, height and width can be scaled. So my second attempt is the posted one:
Advantages: Without arguments, the decoration looks as intended. The Without the argument presets in PGF, I would give the decoration two arguments: |
Brief outline of the proposed feature
For a picture, I needed a jigsaw puzzle decoration. I searched the internet but only found a package for complete puzzle pieces and some stackoverflow posts.
Therefore, I created such a decoration by myself based on the jigsaw package (and the brace decoration). Maybe you want to include this decoration directly into TikZ. There are, however, a few things left, so I hand it in as feature request and not as a PR:
\pgf@xa
etc. to work (TeX reports always that it is an unknown command).aspect
-argument for a generic scale. However, it is possible to scale height and width seperately of each other. Maybe, it is also meaningful to respectamplitude
but the default of2.5pt
looks really bad for that decoration.Usage example
This gives this picture:
The text was updated successfully, but these errors were encountered: