中国十二生肖和农历年可以说是非常亲密的朋友。在东方文化中,每个农历年都分配给十二生肖中的一种动物。今年的动物(或者说吉祥物)是猪。所以,我在这个问题中的问题是:
如何用 LaTeX 画一只(可爱的)小猪?
我在TeXample上找到了一张非常漂亮的图:
% Author M.R.C. van Dongen
% Draw parameterised pig.
% This code can/should be improved by using the pgfkey library.
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{keyval}
\makeatletter
% We're not using pgfkeys, and we've chosen to use keyval
% for option parsing. The following define the keys for a
% pig keyval family. The main purpose of the keys and
% default values is that we want to be able to draw pigs
% with predefined colours for certain parts and predefined
% scaling factors for line thickness.
\def\pig@draw@thick@width{0.85}
\def\pig@draw@thin@width{0.20}
\def\pig@label{pig label}
\tikzset{draw thick/.style={draw=black,line width=0.85}}
\tikzset{draw thin/.style={draw=black,line width=0.20}}
\tikzset{fill colour/.style={fill=pink}}
\tikzset{nose hole fill colour/.style={fill=purple!50!gray}}
\tikzset{eye fill colour/.style={fill=white}}
\tikzset{pupil fill colour/.style={fill=black}}
\define@key{pig}{draw thick}{\def\draw@pig@thick@width{#1}}
\define@key{pig}{draw thin}{\def\draw@pig@thin@width{#1}}
\define@key{pig}{fill colour}{\tikzset{fill colour/.style={fill=#1}}}
\define@key{pig}{nose hole fill colour}{\tikzset{nose hole fill colour/.style={fill=#1}}}
\define@key{pig}{eye fill colour}{\tikzset{eye fill colour/.style={fill=#1}}}
\define@key{pig}{pupil fill colour}{\tikzset{pupil fill colour/.style={fill=#1}}}
\define@key{pig}{pig label}{\def\pig@label{#1}}
\def\pig@scale{1}
\def\pig{\@ifnextchar[\draw@pig{\draw@pig[]}}
\def\draw@pig[#1]#2{%
% Set the relative line width for thick lines.
\def\draw@pig@thick@width{0.85}
% Set the relative line width for thin lines.
\def\draw@pig@thin@width{0.20}
% Set the relative scale of the pig.
\def\pig@scale{#2}
\setkeys{pig}{#1}
\begin{tikzpicture}[scale=#2,
draw thick/.style={draw=black,line width=\draw@pig@thick@width*\pig@scale},
draw thin/.style={draw=black,line width=\draw@pig@thin@width*\pig@scale}]
\path (0,0) coordinate (\pig@label head)
+ (-0.005,-0.20) coordinate (\pig@label nose)
+ (-0.010,+0.05) coordinate (\pig@label body)
+ (-0.010,+0.45) coordinate (\pig@label tail);
% Define points for tail.
\foreach \number/\point in {1/{+0.000,+0.055},%
2/{-0.058,+0.075},%
3/{+0.044,+0.094},%
4/{-0.072,+0.137},%
5/{+0.048,+0.170},%
6/{-0.078,+0.206}} {
\path (\pig@label tail) +(\point) coordinate (tail \number);
}
% Define points for ears and legs.
\foreach \offset in {-1,1} {
\path (\pig@label head)
++ (+0.12*\offset,+0.00) coordinate (ear pt 1 \offset)
+ (-0.04*\offset,+0.07) coordinate (ear pt 2 \offset)
+ (-0.02*\offset,+0.25) coordinate (ear pt 3 \offset)
+ (+0.11*\offset,+0.25) coordinate (ear pt 4 \offset)
+ (+0.14*\offset,+0.13) coordinate (ear pt 5 \offset)
+ (+0.09*\offset,-0.06) coordinate (ear pt 6 \offset)
(\pig@label head)
++ (+0.09*\offset,-0.30) coordinate (leg 1 \offset)
++ (+0.01*\offset,-0.24) coordinate (leg 2 \offset)
++ (+0.04*\offset,+0.08) coordinate (leg 3 \offset)
++ (+0.04*\offset,-0.08) coordinate (leg 4 \offset)
++ (+0.02*\offset,+0.30) coordinate (leg 5 \offset);
}
% draw legs.
\foreach \number in {-1,1} {
\filldraw[fill colour,draw thick]
(leg 1 \number) --
(leg 2 \number) --
(leg 3 \number) --
(leg 4 \number) --
(leg 5 \number) -- cycle;
}
% draw tail.
\draw[draw thick,line join=round,line cap=round]
(\pig@label tail) \foreach \num in {1,...,6} { -- (tail \num)};
% draw body.
\draw[fill colour,draw thick]
(\pig@label body) ellipse (4.50mm and 4.10mm);
% draw ears.
\foreach \number in {-1,1} {
% ears
\filldraw[fill colour,draw thick]
(ear pt 1 \number) .. controls
(ear pt 2 \number) and
(ear pt 3 \number) ..
(ear pt 4 \number) .. controls
(ear pt 5 \number) and
(ear pt 6 \number) .. (ear pt 1 \number);
}
% draw nose.
\filldraw[fill colour,draw thick]
(\pig@label head) ellipse (1.42mm and 1.40mm);
\foreach \offset in {-1,1} {
\filldraw[draw thin,eye fill colour]
(\pig@label head) ++ (-0.006,0.00) ++ (0.055*\offset,+0.03)
coordinate (eye \offset)
ellipse (0.04 and 0.060);
\fill[pupil fill colour]
(eye \offset) ellipse (0.020 and 0.035);
}
\filldraw[fill colour,draw thick]
(\pig@label nose) ellipse (2.60mm and 1.72mm);
% Draw nose holes
\foreach \offset in {-1,1} {
\filldraw[draw thick,nose hole fill colour]
(\pig@label nose) ++ (\offset*0.080,0)
ellipse (0.50mm and 0.85mm);
}
\end{tikzpicture}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\draw (0,0) node[anchor=south]{\pig{3}}
(4,0) node[anchor=south]{\pig[nose hole fill colour=purple!20,fill colour=blue!40]{5}};
\end{tikzpicture}
\end{document}
不过,我希望在这里看到更多的猪,尤其是和其他熟悉的动物一起,比如狮子、鸭子、土拨鼠、熊、兔子、鸟、驴或企鹅。
我也在寻找tikzlings
猪!
答案1
首次亮相tikzpig
:
\documentclass{standalone}
\usepackage{tikz}
\definecolor{piglight}{RGB}{246,208,198}
\definecolor{pigdark}{RGB}{241,164,142}
\begin{document}
\begin{tikzpicture}
% Tail %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\draw[pigdark,thick] (0.8471, 0.5927) .. controls (0.8549, 0.4832) and (0.8046, 0.4105) .. (0.7319, 0.4079) .. controls (0.6592, 0.4052) and (0.6142, 0.4365) .. (0.5964, 0.5024) .. controls (0.5786, 0.5682) and (0.6252, 0.6291) .. (0.6794, 0.6342) .. controls (0.7335, 0.6394) and (0.7561, 0.6114) .. (0.7663, 0.5661) .. controls (0.7765, 0.5208) and (0.746, 0.458) .. (0.7192, 0.4319) .. controls (0.6924, 0.4058) and (0.7073, 0.4182) .. (0.6604, 0.3859) .. controls (0.6134, 0.3536) and (0.4367, 0.3643) .. (0.3877, 0.5055);
% Body %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\fill[piglight] ( 0.6, 0.8 ) .. controls ( 0.6 , 0.4) and ( 0.35, 0.16) .. ( 0.0, 0.16) .. controls (-0.35, 0.16) and (-0.6 , 0.4) .. (-0.6, 0.8 ) .. controls (-0.6 , 1.3) and (-0.35, 1.5) .. ( 0.0, 1.5) .. controls ( 0.35, 1.5) and ( 0.6 , 1.3) .. ( 0.6, 0.75) -- cycle;
% Arms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\fill[pigdark,rotate around={70:(0.33,0.9)}] (0.33,0.9) ellipse (0.18 and 0.13);
\fill[pigdark,rotate around={-70:(-0.33,0.9)}] (-0.33,0.9) ellipse (0.18 and 0.13);
% Head %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\fill[piglight] (0,1.64) ellipse (.5 and .5);
% Eyes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\fill[gray] (-0.09, 1.82) circle (0.02);
\fill[gray] ( 0.09, 1.82) circle (0.02);
% Nose %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\fill[pigdark] (0, 1.62) ellipse (0.18 and 0.14);
\fill[gray] (-0.06, 1.62) circle (0.035);
\fill[gray] ( 0.06, 1.62) circle (0.035);
% Mouth %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\draw[gray] (0.105, 1.46) arc [start angle=-50, end angle=-130, radius=0.16] ;
% Ears %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\fill[pigdark] (0.22, 2.0392) .. controls (0.22, 2.1584) and (0.49460, 2.255) .. (0.49460, 2.255) .. controls (0.49460, 2.255) and (0.5300, 1.86) .. (0.3721, 1.86) .. controls (0.2891, 1.86) and (0.22, 1.9201) .. (0.22, 2.0392) -- cycle;
\fill[piglight] (0.22, 2.0392) .. controls (0.26, 2.1584) and (0.47, 2.22) .. (0.47, 2.20) .. controls (0.47, 2.2) and (0.49, 1.9) .. (0.3721, 1.9) .. controls (0.2891, 1.88) and (0.22, 1.88) .. (0.22, 2.0392) -- cycle;
\fill[pigdark] (-0.22, 2.0392) .. controls (-0.22, 2.1584) and (-0.49460, 2.255) .. (-0.49460, 2.255) .. controls (-0.49460, 2.255) and (-0.5300, 1.86) .. (-0.3721, 1.86) .. controls (-0.2891, 1.86) and (-0.22, 1.9201) .. (-0.22, 2.0392) -- cycle;
\fill[piglight] (-0.22, 2.0392) .. controls (-0.26, 2.1584) and (-0.47, 2.22) .. (-0.47, 2.20) .. controls (-0.47, 2.2) and (-0.49, 1.9) .. (-0.3721, 1.9) .. controls (-0.2891, 1.88) and (-0.22, 1.88) .. (-0.22, 2.0392) -- cycle;
% Feet %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{scope}
\clip (-0.5,0.4) rectangle (0.5,0.13);
\fill[pigdark] (-0.22,0.17) circle (0.15);
\fill[pigdark] (0.22,0.17) circle (0.15);
\end{scope}
\end{tikzpicture}
\end{document}
同时,tikzpig
已添加到软件包的开发版本中tikzlings
(可用这里) 改进了@Circumscribe和@CarLaTeX(多谢!)
\documentclass{standalone}
\usepackage{tikzlings}
\begin{document}
\begin{tikzpicture}
\pig
\end{tikzpicture}
\end{document}
答案2
你真的不需要任何包
\documentclass{article}
\begin{document}
\begin{picture}(100,100)
\put(43,56){\circle{6}}
\put(43,56){\circle*{1}}
\put(57,56){\circle{6}}
\put(57,56){\circle*{1}}
\put(50,45){\circle{12}}
\put(48,45){\oval(3,5)}
\put(52,45){\oval(3,5)}
\put(50,50){\circle{40}}
\put(43,32){\oval(5,20)[b]}
\put(57,32){\oval(5,20)[b]}
\put(64,64){\vector(1,1){10}}
\end{picture}
\end{document}