Created
December 18, 2013 01:23
-
-
Save anonymous/8015840 to your computer and use it in GitHub Desktop.
Fish shape for pgf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass[tikz]{standalone} | |
\makeatletter | |
\pgfdeclareshape{fish} | |
{ | |
\savedmacro\fishpoints{ | |
\pgfextract@process\centerpoint{% | |
\pgf@x=.5\wd\pgfnodeparttextbox% | |
\pgf@y=.5\ht\pgfnodeparttextbox% | |
\advance\pgf@y by-.5\dp\pgfnodeparttextbox% | |
} | |
\pgfextract@process\innerradius{ | |
\centerpoint% | |
\pgfmathsetlength\pgf@yb{\pgfkeysvalueof{/pgf/inner ysep}}% | |
\advance\pgf@y by\pgf@yb% | |
\pgfmathsetlength\pgf@xb{\pgfkeysvalueof{/pgf/inner xsep}}% | |
\advance\pgf@x by\pgf@xb% | |
% Adjust to minimum dimensions. | |
\pgfmathsetlength\pgf@yc{\pgfkeysvalueof{/pgf/minimum height}}% | |
\ifdim\pgf@y<.5\pgf@yc% | |
\pgf@y=.5\pgf@yc% | |
\fi% | |
\pgfmathsetlength\pgf@xc{\pgfkeysvalueof{/pgf/minimum width}}% | |
\ifdim\pgf@x<.5\pgf@xc% | |
\pgf@x=.5\pgf@xc% | |
\fi% | |
} | |
\pgfextract@process\outerradius{ | |
\innerradius% | |
\pgfmathsetlength{\pgf@xb}{\pgfkeysvalueof{/pgf/outer xsep}}% | |
\advance\pgf@x by\pgf@xb% | |
\pgfmathsetlength{\pgf@yb}{\pgfkeysvalueof{/pgf/outer ysep}}% | |
\advance\pgf@y by\pgf@yb% | |
} | |
\pgfextract@process\tip{ | |
\innerradius | |
\pgf@xc1.5\pgf@x | |
\pgf@process{\centerpoint} | |
\advance\pgf@x\pgf@xc | |
} | |
\pgfextract@process\finmidpoint{ | |
\innerradius | |
\pgf@xc-2.75\pgf@x | |
\pgf@process{\centerpoint} | |
\advance\pgf@x\pgf@xc | |
} | |
\pgfextract@process\upperfin{ | |
\innerradius | |
\pgf@yc\pgf@y | |
\pgf@process{\finmidpoint} | |
\advance\pgf@y\pgf@yc | |
} | |
\pgfextract@process\lowerfin{ | |
\innerradius | |
\pgf@yc-1\pgf@y | |
\pgf@process{\finmidpoint} | |
\advance\pgf@y\pgf@yc | |
} | |
\pgfextract@process\findent{ | |
\innerradius | |
\pgf@xc-2.5\pgf@x | |
\pgf@process{\centerpoint} | |
\advance\pgf@x\pgf@xc | |
} | |
\pgfextract@process\upperfincontrol{ | |
\innerradius | |
\pgf@yc0.2\pgf@y | |
\pgf@process{\findent} | |
\advance\pgf@y\pgf@yc | |
} | |
\pgfextract@process\lowerfincontrol{ | |
\innerradius | |
\pgf@yc-0.2\pgf@y | |
\pgf@process{\findent} | |
\advance\pgf@y\pgf@yc | |
} | |
\pgfextract@process\rightbodycontrol{ | |
\innerradius | |
\pgf@xc-.75\pgf@x | |
\pgf@process{\centerpoint} | |
\advance\pgf@x\pgf@xc | |
} | |
\pgfextract@process\upperrightbodycontrol{ | |
\innerradius | |
\pgf@yc4\pgf@y | |
\pgf@process{\rightbodycontrol} | |
\advance\pgf@y\pgf@yc | |
} | |
\pgfextract@process\lowerrightbodycontrol{ | |
\innerradius | |
\pgf@yc-4\pgf@y | |
\pgf@process{\rightbodycontrol} | |
\advance\pgf@y\pgf@yc | |
} | |
\pgfextract@process\leftbodycontrol{ | |
\innerradius | |
\pgf@xc-1\pgf@x | |
\pgf@process{\centerpoint} | |
\advance\pgf@x\pgf@xc | |
} | |
\pgfextract@process\upperleftbodycontrol{ | |
\innerradius | |
\pgf@yc-1\pgf@y | |
\pgf@process{\leftbodycontrol} | |
\advance\pgf@y\pgf@yc | |
} | |
\pgfextract@process\lowerleftbodycontrol{ | |
\innerradius | |
\pgf@yc\pgf@y | |
\pgf@process{\leftbodycontrol} | |
\advance\pgf@y\pgf@yc | |
} | |
\pgfextract@process\northeast{ | |
\innerradius | |
\pgf@xc\pgf@x | |
\pgf@yc\pgf@y | |
\pgf@process{\centerpoint} | |
\advance\pgf@x\pgf@xc | |
\advance\pgf@y\pgf@yc | |
} | |
\pgfextract@process\southeast{ | |
\innerradius | |
\pgf@xc\pgf@x | |
\pgf@yc\pgf@y | |
\pgf@process{\centerpoint} | |
\advance\pgf@x\pgf@xc | |
\advance\pgf@y-\pgf@yc | |
} | |
\pgfextract@process\northwest{ | |
\innerradius | |
\pgf@xc\pgf@x | |
\pgf@yc\pgf@y | |
\pgf@process{\centerpoint} | |
\advance\pgf@x-\pgf@xc | |
\advance\pgf@y\pgf@yc | |
} | |
\pgfextract@process\southwest{ | |
\innerradius | |
\pgf@xc\pgf@x | |
\pgf@yc\pgf@y | |
\pgf@process{\centerpoint} | |
\advance\pgf@x-\pgf@xc | |
\advance\pgf@y-\pgf@yc | |
} | |
\addtosavedmacro{\tip} | |
\addtosavedmacro{\centerpoint} | |
\addtosavedmacro{\upperfin} | |
\addtosavedmacro{\lowerfin} | |
\addtosavedmacro{\findent} | |
\addtosavedmacro{\upperfincontrol} | |
\addtosavedmacro{\lowerfincontrol} | |
\addtosavedmacro{\upperrightbodycontrol} | |
\addtosavedmacro{\upperleftbodycontrol} | |
\addtosavedmacro{\lowerrightbodycontrol} | |
\addtosavedmacro{\lowerleftbodycontrol} | |
\addtosavedmacro{\northeast} | |
\addtosavedmacro{\southeast} | |
\addtosavedmacro{\northwest} | |
\addtosavedmacro{\southwest} | |
} | |
\anchor{center}{ | |
\fishpoints | |
\centerpoint | |
} | |
\anchor{east}{ | |
\fishpoints | |
\tip | |
} | |
\anchor{west}{ | |
\fishpoints | |
\findent | |
} | |
\anchor{north east}{ | |
\fishpoints | |
\northeast | |
} | |
\anchor{south east}{ | |
\fishpoints | |
\southeast | |
} | |
\anchor{north west}{ | |
\fishpoints | |
\northwest | |
} | |
\anchor{south west}{ | |
\fishpoints | |
\southwest | |
} | |
\backgroundpath{ | |
\fishpoints | |
\pgfpathmoveto{\tip} | |
\pgfpathcurveto{\upperrightbodycontrol}{\upperleftbodycontrol}{\upperfin} | |
\pgfpathcurveto{\upperfincontrol}{\lowerfincontrol}{\lowerfin} | |
\pgfpathcurveto{\lowerleftbodycontrol}{\lowerrightbodycontrol}{\tip} | |
\pgfpathclose | |
} | |
} | |
\makeatother | |
\begin{document} | |
\begin{tikzpicture} | |
\node[inner sep=0, draw=blue, fill=red, fish] (tuna) {tuna}; | |
\node[draw=blue, fill=red, fish] at (1, 1) (barb) {barb}; | |
\draw[gray] (tuna.north east) -- (tuna.south east) -- (tuna.south west) -- (tuna.north west) -- cycle; | |
\draw[gray] (barb.north east) -- (barb.south east) -- (barb.south west) -- (barb.north west) -- cycle; | |
\end{tikzpicture} | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment