summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/tikzlings/tikzlings-rhinos.sty
blob: dabbd15f178a42ef71a55836f4d190904d2c8272 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
% !TeX root = ./examples/rhino.tex
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% The tikzlings-rhinos package (part of the tikzlings collection)
% A package to bring little rhinos 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.2
% April 7, 2019    
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ProvidesPackage{tikzlings-rhinos}
 [2019/04/07 v0.2 Drawing rhinos in TikZ]

\RequirePackage{tikz}
\RequirePackage{tikzlings-addons}

\newcommand*{\rhino}[1][]{%
  \begin{scope}%
    \tikzset{/rhino/.cd,#1}%
    \rhino@draw%
  \end{scope}%
  \thing[#1]%
}

\newif\ifrhino@threeD

\tikzset{
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % Pass unknown keys on to tikz
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  /rhino/.search also={/tikz,/pgf,/thing},
  /rhino/.cd,
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % body
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  body/.code         = \def\rhino@body{#1},
  body               = gray,
  toes/.code         = \def\rhino@toes{#1},
  toes               = \rhino@body!55!white,
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % options
  %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3D/.code           = \rhino@threeDtrue, 
}

\def\rhino@draw{%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% minimal bounding box size 
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\path (-0.625,0.1) rectangle (0.625, 2.17);
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% 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
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ifrhino@threeD
  \def\rhino@part@draw[##1]{\shade[ball color=##1]}
\else
  \def\rhino@part@draw[##1]{\fill[##1]}
\fi
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Body parts (center: x=0)
% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Ears %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\rhino@part@draw[\rhino@body]  (-0.1772, 2.0686) .. controls (-0.2057, 2.1602) and (-0.3552, 2.2076) .. (-0.3552, 2.1922) .. controls (-0.3552, 2.1922) and (-0.3694, 1.9615) .. (-0.2855, 1.9615) .. controls (-0.2264, 1.9462) and (-0.1772, 1.9462) .. (-0.1772, 2.0686) -- cycle;
\rhino@part@draw[\rhino@body]  (0.1772, 2.0686) .. controls (0.2057, 2.1602) and (0.3552, 2.2076) .. (0.3552, 2.1922) .. controls (0.3552, 2.1922) and (0.3694, 1.9615) .. (0.2855, 1.9615) .. controls (0.2264, 1.9462) and (0.1772, 1.9462) .. (0.1772, 2.0686) -- cycle;
%
% Body %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\rhino@part@draw[\rhino@body!55!white] ( 0.55,  0.8 ) .. controls ( 0.55 , 0.4) and ( 0.35, 0.19) .. ( 0.0,  0.19) .. controls (-0.35, 0.19) and (-0.55 , 0.4) .. (-0.55,  0.8 ) .. controls (-0.55 , 1.3) and (-0.35, 1.65) .. ( 0.0,  1.65) .. controls ( 0.35, 1.65) and ( 0.55 , 1.3) .. ( 0.55,  0.75) -- cycle;
%
% Arms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\rhino@part@draw[\rhino@body,rotate around={90:(0.3,1.0)}] (0.3,1.0) ellipse (0.24 and 0.13);
\rhino@part@draw[\rhino@body,rotate around={-90:(-0.3,1.0)}] (-0.3,1.0) ellipse (0.24 and 0.13);
%
% Head %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\rhino@part@draw[\rhino@body!55!white] (0, 1.76) circle (0.36);
%
% Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\fill[white] (-0.11, 1.83) ellipse (0.08 and 0.12);
\fill[white] (0.11, 1.83) ellipse (0.08 and 0.12);
\fill[black] (-0.105, 1.78) ellipse (0.04 and 0.07);
\fill[black] (0.105, 1.78) ellipse (0.04 and 0.07);
%
% Nose %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\rhino@part@draw[\rhino@body!80!white] (0, 1.55) ellipse (0.36 and 0.2);
%
% Horn %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\rhino@part@draw[white!95!yellow] (0, 1.7911) .. controls (-0.0231, 1.7372) and (-0.0463, 1.6832) .. (-0.0642, 1.6274) .. controls (-0.0687, 1.6132) and (-0.0724, 1.5981) .. (-0.0678, 1.5834) .. controls (-0.0603, 1.552) and (-0.0287, 1.5287) .. (0, 1.531) .. controls (0.0287, 1.5287) and (0.0603, 1.552) .. (0.0678, 1.5834) .. controls (0.0724, 1.5981) and (0.0687, 1.6132) .. (0.0642, 1.6274) .. controls (0.0463, 1.6832) and (0.0231, 1.7372) .. (0, 1.7911) -- cycle;
%
% Mouth %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ifrhino@threeD
	\draw[black,line width=\scalingfactor*0.4pt] (0.125, 1.5) arc [start angle=-50, end angle=-130, radius=0.2] ;
	\else
		\draw[\rhino@body!70!black,line width=\scalingfactor*0.4pt] (0.125, 1.5) arc [start angle=-50, end angle=-130, radius=0.2] ;
		\fi
		%
% Feet %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{scope}
	\clip (-0.5,0.4) rectangle (0.5,0.13);
	\rhino@part@draw[\rhino@body] (-0.25,0.15) ellipse (0.16 and 0.17);
	\rhino@part@draw[\rhino@body] (0.25,0.15) ellipse (0.16 and 0.17);
	\rhino@part@draw[\rhino@toes] (0.25,0.13) ellipse (0.05 and 0.1);
	\rhino@part@draw[\rhino@toes] (0.13,0.11) ellipse (0.05 and 0.1);
	\rhino@part@draw[\rhino@toes] (0.37,0.11) ellipse (0.05 and 0.1);
	\rhino@part@draw[\rhino@toes] (-0.25,0.13) ellipse (0.05 and 0.1);
	\rhino@part@draw[\rhino@toes] (-0.13,0.11) ellipse (0.05 and 0.1);
	\rhino@part@draw[\rhino@toes] (-0.37,0.11) ellipse (0.05 and 0.1);	
\end{scope}
%
}