Advertisement
Guest User

Untitled

a guest
Mar 7th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.29 KB | None | 0 0
  1. % !TeX root = ./examples/cat.tex
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3. %
  4. % The tikzlings-cats package (part of the tikzlings collection)
  5. % A package to bring little cats into tikz
  6. % Maintained by samcarter
  7. %
  8. % Project repository and bug tracker:
  9. % https://github.com/samcarter/tikzlings
  10. %
  11. % Released under the LaTeX Project Public License v1.3c or later
  12. % See http://www.latex-project.org/lppl.txt
  13. %
  14. % Version 0.1
  15. % Feb 5, 2019
  16. %
  17. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  18. \ProvidesPackage{tikzlings-cats}
  19. [2019/02/05 v0.1 Drawing cats in TikZ]
  20.  
  21. \RequirePackage{tikz}
  22. \RequirePackage{tikzlings-addons}
  23.  
  24. \RequirePackage{ifluatex}
  25. \RequirePackage{ifxetex}
  26.  
  27. \ifluatex
  28. \let\pdfrandomseed\randomseed
  29. \fi
  30.  
  31. \ifxetex
  32. \pgfmathsetseed{\time}
  33. \else
  34. \pgfmathsetseed{\number\pdfrandomseed}
  35. \fi
  36.  
  37. \newcommand*{\cat}[1][]{%
  38. \begin{scope}%
  39. \tikzset{/cat/.cd,#1}%
  40. \cat@draw%
  41. \end{scope}%
  42. \thing[#1]%
  43. }
  44.  
  45. \newif\ifcat@threeD
  46. \newif\ifcat@schroedinger
  47.  
  48. \tikzset{
  49. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  50. %
  51. % Pass unknown keys on to tikz
  52. %
  53. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  54. /cat/.search also={/tikz,/pgf,/thing},
  55. /cat/.cd,
  56. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  57. %
  58. % body
  59. %
  60. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  61. body/.code = \def\cat@body{#1},
  62. body = gray!30!black,
  63. whiskers/.code = \def\cat@whiskers{#1},
  64. whiskers = gray!50!white,
  65. eyes/.code = \def\cat@eyes{#1},
  66. eyes = yellow!80!orange,
  67. pupil/.code = \def\cat@pupil{#1},
  68. pupil = black,
  69. pupil width/.code = \def\cat@pupil@width{#1}\edef\cat@pupil@offset{\strip@pt\dimexpr#1pt/4},
  70. narrow pupils/.style = {pupil width = 0.005},
  71. medium pupils/.style = {pupil width = 0.015},
  72. wide pupils/.style = {pupil width = 0.025},
  73. very wide pupils/.style = {pupil width = 0.050},
  74. pupil width = 0.15,
  75. paws/.code = \def\cat@paws{#1},
  76. paws = \cat@body,
  77. nose/.code = \def\cat@nose{#1},
  78. nose = red!40!white!80!gray,
  79. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  80. %
  81. % options
  82. %
  83. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  84. 3D/.code = \cat@threeDtrue,
  85. schroedinger/.code = \cat@schroedingertrue,
  86. }
  87.  
  88. \def\cat@draw{%
  89. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  90. %
  91. % Opening Schr"odingers Box
  92. %
  93. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  94. \def\cat@rotate{0}
  95. \ifcat@schroedinger
  96. \pgfmathparse{int(random(0,1))}
  97. \let\cat@random=\pgfmathresult
  98. \ifnum\cat@random=1
  99. \def\cat@rotate{90}
  100. \fi
  101. \fi
  102. %
  103. \begin{scope}[rotate=\cat@rotate]
  104. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  105. %
  106. % minimal bounding box size
  107. %
  108. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  109. \path (-0.56,0.1) rectangle (1.63, 2.22);
  110. %
  111. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  112. %
  113. % store the current scale factor
  114. % from https://github.com/samcarter/tikzlings/issues/3#issuecomment-461373494
  115. %
  116. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  117. \pgfgettransformentries{\tmpscaleA}{\tmpscaleB}{\tmpscaleC}{\tmpscaleD}{\tmp}{\tmp}%
  118. \pgfmathsetmacro{\scalingfactor}{sqrt(abs(\tmpscaleA*\tmpscaleD-\tmpscaleB*\tmpscaleC))}%
  119. \pgfmathsetmacro{\xscalefactor}{\tmpscaleA}
  120. \pgfmathsetmacro{\yscalefactor}{\tmpscaleD}
  121. %
  122. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  123. %
  124. % switch between 2D and 3D, from
  125. % https://chat.stackexchange.com/transcript/message/45991801#45991801
  126. %
  127. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  128. \ifcat@threeD
  129. \def\cat@part@draw[##1]{\shade[ball color=##1]}
  130. \else
  131. \def\cat@part@draw[##1]{\fill[##1]}
  132. \fi
  133. %
  134. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  135. %
  136. % Body parts (center: x=0)
  137. %
  138. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  139. %
  140. % Tail %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  141. \begin{pgfinterruptboundingbox}
  142. \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;
  143. \end{pgfinterruptboundingbox}
  144. %
  145. % Body %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  146. \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;
  147. %
  148. % Ears %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  149. \cat@part@draw[\cat@body]
  150. (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;
  151. \cat@part@draw[\cat@body]
  152. (-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;
  153. %
  154. % Head %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  155. \cat@part@draw[\cat@body] (0,1.64) circle (0.44);
  156. %
  157. % Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  158. \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;
  159. \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;
  160. %
  161. % Pupils %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  162. \cat@part@draw[\cat@pupil]
  163. (-0.1720, 1.8071)
  164. .. 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)
  165. .. 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)
  166. -- cycle;
  167. \cat@part@draw[\cat@pupil]
  168. ( 0.1720, 1.8071)
  169. .. 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)
  170. .. 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)
  171. -- cycle;
  172. %
  173. % Mouth %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  174. \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);
  175. %
  176. % Nose %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  177. \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;
  178. %
  179. % Wiskers %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  180. \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;
  181. \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;
  182. \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;
  183. \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;
  184. \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;
  185. \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;
  186. %
  187. % Feet %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  188. \cat@part@draw[\cat@paws] (-0.255,0.3) circle (0.18);
  189. \cat@part@draw[\cat@paws] (0.255,0.3) circle (0.18);
  190. %
  191. \end{scope}% from the Schroedinger Cat
  192. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement