Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % !TeX root = ./examples/cat.tex
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % The tikzlings-cats package (part of the tikzlings collection)
- % A package to bring little cats into tikz
- % Maintained by samcarter
- %
- % Project repository and bug tracker:
- % https://github.com/samcarter/tikzlings
- %
- % Released under the LaTeX Project Public License v1.3c or later
- % See http://www.latex-project.org/lppl.txt
- %
- % Version 0.1
- % Feb 5, 2019
- %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- \ProvidesPackage{tikzlings-cats}
- [2019/02/05 v0.1 Drawing cats in TikZ]
- \RequirePackage{tikz}
- \RequirePackage{tikzlings-addons}
- \RequirePackage{ifluatex}
- \RequirePackage{ifxetex}
- \ifluatex
- \let\pdfrandomseed\randomseed
- \fi
- \ifxetex
- \pgfmathsetseed{\time}
- \else
- \pgfmathsetseed{\number\pdfrandomseed}
- \fi
- \newcommand*{\cat}[1][]{%
- \begin{scope}%
- \tikzset{/cat/.cd,#1}%
- \cat@draw%
- \end{scope}%
- \thing[#1]%
- }
- \newif\ifcat@threeD
- \newif\ifcat@schroedinger
- \tikzset{
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % Pass unknown keys on to tikz
- %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- /cat/.search also={/tikz,/pgf,/thing},
- /cat/.cd,
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % body
- %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- body/.code = \def\cat@body{#1},
- body = gray!30!black,
- whiskers/.code = \def\cat@whiskers{#1},
- whiskers = gray!50!white,
- eyes/.code = \def\cat@eyes{#1},
- eyes = yellow!80!orange,
- pupil/.code = \def\cat@pupil{#1},
- pupil = black,
- pupil width/.code = \def\cat@pupil@width{#1}\edef\cat@pupil@offset{\strip@pt\dimexpr#1pt/4},
- narrow pupils/.style = {pupil width = 0.005},
- medium pupils/.style = {pupil width = 0.015},
- wide pupils/.style = {pupil width = 0.025},
- very wide pupils/.style = {pupil width = 0.050},
- pupil width = 0.15,
- paws/.code = \def\cat@paws{#1},
- paws = \cat@body,
- nose/.code = \def\cat@nose{#1},
- nose = red!40!white!80!gray,
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % options
- %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- 3D/.code = \cat@threeDtrue,
- schroedinger/.code = \cat@schroedingertrue,
- }
- \def\cat@draw{%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % Opening Schr"odingers Box
- %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- \def\cat@rotate{0}
- \ifcat@schroedinger
- \pgfmathparse{int(random(0,1))}
- \let\cat@random=\pgfmathresult
- \ifnum\cat@random=1
- \def\cat@rotate{90}
- \fi
- \fi
- %
- \begin{scope}[rotate=\cat@rotate]
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % minimal bounding box size
- %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- \path (-0.56,0.1) rectangle (1.63, 2.22);
- %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % store the current scale factor
- % from https://github.com/samcarter/tikzlings/issues/3#issuecomment-461373494
- %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- \pgfgettransformentries{\tmpscaleA}{\tmpscaleB}{\tmpscaleC}{\tmpscaleD}{\tmp}{\tmp}%
- \pgfmathsetmacro{\scalingfactor}{sqrt(abs(\tmpscaleA*\tmpscaleD-\tmpscaleB*\tmpscaleC))}%
- \pgfmathsetmacro{\xscalefactor}{\tmpscaleA}
- \pgfmathsetmacro{\yscalefactor}{\tmpscaleD}
- %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % switch between 2D and 3D, from
- % https://chat.stackexchange.com/transcript/message/45991801#45991801
- %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- \ifcat@threeD
- \def\cat@part@draw[##1]{\shade[ball color=##1]}
- \else
- \def\cat@part@draw[##1]{\fill[##1]}
- \fi
- %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % Body parts (center: x=0)
- %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % Tail %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- \begin{pgfinterruptboundingbox}
- \cat@part@draw[\cat@body] (0.3, 0.5) .. controls (0.55, 0.87) and (0.73, 1.50) .. (1.05, 1.65) .. controls (1.32, 1.77) and (1.76, 1.34) .. (1.56,1.33) .. controls (0.92, 2.03) and (0.86, 0.60) .. (0.5, 0.37) -- cycle;
- \end{pgfinterruptboundingbox}
- %
- % Body %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- \cat@part@draw[\cat@body] (0.5462, 0.7155) .. controls (0.5462, 0.1823) and (0.3259, 0.17) .. (0, 0.17) .. controls (-0.3259, 0.17) and (-0.5462, 0.1823) .. (-0.5462, 0.7155) .. controls (-0.5554, 1.2487) and (-0.3075, 1.6768) .. (0, 1.6768) .. controls (0.3075, 1.6768) and (0.5554, 1.2487) .. (0.5462, 0.7155) -- cycle;
- %
- % Ears %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- \cat@part@draw[\cat@body]
- (0.12, 2.0392) .. controls (0.16, 2.1584) and (0.37, 2.22) .. (0.37, 2.20) .. controls (0.37, 2.2) and (0.39, 1.9) .. (0.2721, 1.9) .. controls (0.1891, 1.88) and (0.12, 1.88) .. (0.12, 2.0392) -- cycle;
- \cat@part@draw[\cat@body]
- (-0.12, 2.0392) .. controls (-0.16, 2.1584) and (-0.37, 2.22) .. (-0.37, 2.20) .. controls (-0.37, 2.2) and (-0.39, 1.9) .. (-0.2721, 1.9) .. controls (-0.1891, 1.88) and (-0.12, 1.88) .. (-0.12, 2.0392) -- cycle;
- %
- % Head %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- \cat@part@draw[\cat@body] (0,1.64) circle (0.44);
- %
- % Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- \cat@part@draw[\cat@eyes] (-0.1014, 1.7491) .. controls (-0.1014, 1.7491) and (-0.1451, 1.7171) .. (-0.1841, 1.7284) .. controls (-0.2231, 1.7397) and (-0.2427, 1.79) .. (-0.2427, 1.79) .. controls (-0.2427, 1.79) and (-0.1992, 1.8221) .. (-0.1602, 1.8108) .. controls (-0.1212, 1.7995) and (-0.1014, 1.7491) .. (-0.1014, 1.7491) -- cycle;
- \cat@part@draw[\cat@eyes] (0.1014, 1.7491) .. controls (0.1014, 1.7491) and (0.1451, 1.7171) .. (0.1841, 1.7284) .. controls (0.2231, 1.7397) and (0.2427, 1.79) .. (0.2427, 1.79) .. controls (0.2427, 1.79) and (0.1992, 1.8221) .. (0.1602, 1.8108) .. controls (0.1212, 1.7995) and (0.1014, 1.7491) .. (0.1014, 1.7491) -- cycle;
- %
- % Pupils %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- \cat@part@draw[\cat@pupil]
- (-0.1720, 1.8071)
- .. controls (-0.1720+\cat@pupil@width, 1.7827+\cat@pupil@offset) and (-0.1720+\cat@pupil@width, 1.7584-\cat@pupil@offset) .. (-0.1720, 1.7341)
- .. controls (-0.1720-\cat@pupil@width, 1.7584-\cat@pupil@offset) and (-0.1720-\cat@pupil@width, 1.7827+\cat@pupil@offset) .. (-0.1720, 1.8071)
- -- cycle;
- \cat@part@draw[\cat@pupil]
- ( 0.1720, 1.8071)
- .. controls ( 0.1720+\cat@pupil@width, 1.7827+\cat@pupil@offset) and ( 0.1720+\cat@pupil@width, 1.7584-\cat@pupil@offset) .. ( 0.1720, 1.7341)
- .. controls ( 0.1720-\cat@pupil@width, 1.7584-\cat@pupil@offset) and ( 0.1720-\cat@pupil@width, 1.7827+\cat@pupil@offset) .. ( 0.1720, 1.8071)
- -- cycle;
- %
- % Mouth %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- \draw[\cat@whiskers,line width=\scalingfactor*0.2pt] (-0.16, 1.527) .. controls (-0.16, 1.527) and (-0.062, 1.420) .. ( 0.000, 1.556) .. controls ( 0.062, 1.420) and ( 0.16, 1.527) .. ( 0.16, 1.527);
- %
- % Nose %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- \cat@part@draw[\cat@nose] (-0.069, 1.6452) .. controls (-0.0524, 1.6613) and (0.0524, 1.6613) .. (0.069, 1.6452) .. controls (0.08, 1.625) and (0.0206, 1.55) .. (0, 1.55) .. controls (-0.0206, 1.55) and (-0.08, 1.625) .. (-0.069, 1.6452) -- cycle;
- %
- % Wiskers %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- \fill[\cat@whiskers] (0.0788, 1.5946) .. controls (0.1658, 1.6099) and (0.2086, 1.5439) .. (0.2956, 1.5286) -- (0.2956, 1.5386) .. controls (0.2097, 1.5537) and (0.1648, 1.6097) .. (0.0788, 1.5946) -- cycle;
- \fill[\cat@whiskers] (-0.0788, 1.5946) .. controls (-0.1658, 1.6099) and (-0.2087, 1.5439) .. (-0.2956, 1.5286) -- (-0.2956, 1.5386) .. controls (-0.2097, 1.5537) and (-0.1648, 1.6097) .. (-0.0788, 1.5946) -- cycle;
- \fill[\cat@whiskers] (0.0752, 1.6081) .. controls (0.1583, 1.6383) and (0.2171, 1.6109) .. (0.3002, 1.5807) -- (0.3002, 1.5907) .. controls (0.2174, 1.6208) and (0.158, 1.6382) .. (0.0752, 1.6081) -- cycle;
- \fill[\cat@whiskers] (-0.0752, 1.6081) .. controls (-0.1583, 1.6383) and (-0.2171, 1.6109) .. (-0.3002, 1.5807) -- (-0.3002, 1.5907) .. controls (-0.2174, 1.6208) and (-0.158, 1.6382) .. (-0.0752, 1.6081) -- cycle;
- \fill[\cat@whiskers] (0.0671, 1.6243) .. controls (0.1414, 1.6725) and (0.2182, 1.6964) .. (0.2925, 1.6482) -- (0.2925, 1.6582) .. controls (0.2179, 1.7066) and (0.1417, 1.6727) .. (0.0671, 1.6243) -- cycle;
- \fill[\cat@whiskers] (-0.0671, 1.6243) .. controls (-0.1414, 1.6725) and (-0.2182, 1.6964) .. (-0.2925, 1.6482) -- (-0.2925, 1.6582) .. controls (-0.2179, 1.7066) and (-0.1417, 1.6727) .. (-0.0671, 1.6243) -- cycle;
- %
- % Feet %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- \cat@part@draw[\cat@paws] (-0.255,0.3) circle (0.18);
- \cat@part@draw[\cat@paws] (0.255,0.3) circle (0.18);
- %
- \end{scope}% from the Schroedinger Cat
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement