-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathSpherical_pig.tex
124 lines (107 loc) · 6.84 KB
/
Spherical_pig.tex
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Disclaimer:
%% - No pigs were harmed in the preparation of this tex file
%% - Contributed by @circumscribe
%% - https://github.com/samcarter/tikzlings/issues/3#issuecomment-464382318
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% !TeX program = txs:///arara
% arara: latexmk: {
% arara: --> engine: pdflatex,
% arara: --> options: [
% arara: --> '-pretex="\\AtBeginDocument{\\pagecolor{gray!20}}"',
% arara: --> '-usepretex'
% arara: --> ]
% arara: --> }
% arara: pdftocairo: {
% arara: --> format: 'png',
% arara: --> options: [
% arara: --> '-r', '150', '-transp', '-singlefile',
% arara: --> '@{getBasename(getOriginalReference())}_bg'
% arara: --> ]
% arara: --> }
% arara: latexmk: {
% arara: --> engine: pdflatex,
% arara: --> }
% arara: pdftocairo: {
% arara: --> format: 'png',
% arara: --> options: ['-r', '150', '-transp', '-singlefile'],
% arara: --> }
% arara: clean: { extensions: [ aux, log, fdb_latexmk, fls, synctex.gz ] }
\documentclass[tikz]{standalone}
\usetikzlibrary{fadings} %% <- for the stars
\definecolor{piglight}{RGB}{246,208,198}
\definecolor{pigdark}{RGB}{241,164,142}
%% Custom ball shading for the pig:
%% (Based on https://tex.stackexchange.com/a/54239, with modified colours)
\makeatletter
\pgfdeclareradialshading[tikz@ball]{pigball}{\pgfqpoint{0bp}{0bp}}{%
color(0bp)=(tikz@ball!50!white);
color(10bp)=(tikz@ball!90!white);
color(15bp)=(tikz@ball!90!black);
color(20bp)=(tikz@ball!65!black);
color(25bp)=(tikz@ball!30!black)}
\tikzoption{pigball color}{\pgfutil@colorlet{tikz@ball}{#1}\def\tikz@shading{pigball}}%
\makeatother
%% Fading for the stars:
%% (Why is this not allowed INSIDE the tikz environment?)
\tikzfading [name=fade out, inner color=pgftransparent!0, outer color=pgftransparent]
%% For the mouth:
\def\happiness{2}
\begin{document}
\begin{tikzpicture}
%%%%%%%%%%%%%%
%% SKY code %%
%%%%%%%%%%%%%%
\clip (-1.6,-1.6) rectangle (1.6,1.6); %% <- clips off stars extending beyond the edge
%% The sky:
\pagecolor{black}
\foreach \X in {1,2,...,1024} {
% Changing the apparent brightness by modulating the size of the dots
\pgfmathsetmacro{\starbrightness}{.003+rnd*.008}%% <- making them smaller causes errors
% Adding some random redshift (this does not reflect the true z distribution of stars, but what looked nice)
\pgfmathsetmacro{\starredshift}{20*rnd}%
% adding an intrisic colour to the star. The code below produces equal ammout of red and blue stars (this is not a realistic value, again just waht looked nice), the intensity of the colour is random
\pgfmathsetmacro{\starcolfraction}{50*rnd}%
\pgfmathsetmacro{\starcol}{less(rand,0.)}
\ifnum\starcol>0
\def\starcolour{blue}
\else%
\def\starcolour{red}
\fi%
\fill[
\starcolour!\starcolfraction!red!\starredshift!white
,path fading=fade out] (rand*1.6,rand*1.6) circle[radius=\starbrightness];
}
%%%%%%%%%%%%%%
%% PIG code %%
%%%%%%%%%%%%%%
\pgfgettransform{\pigtransform} %% <- define pig-space coordinates
\newcommand\pigshading[1]{
\begingroup
\pgfsettransform{\pigtransform} %% <- use pig-space coordinates for shading
\shade [pigball color=#1,rotate=45] (0,.5) ellipse (1.8 and 1.6);
\endgroup
}
%% The body:
\path[path picture=\pigshading{piglight}] (0,0) circle[radius=1];
%% The ears:
\begin{scope}[yshift=-.5cm,yscale=.7]
\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!99.5!black] (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!80!white] (-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;
\end{scope}
%% The face:
\fill[gray] (-.09, .77) circle (.02 and .017) ( .09, .77) circle (.02 and .017); %% Eyes
\path[path picture=\pigshading{pigdark}] (0, .57) ellipse (.18 and .1); %% Nose
% \path[path picture=\pigshading{pigdark}} (0, .57) ellipse (.18 and .1); %% Nose
\fill[gray] (-.06, .57) circle (.035 and .029) ( .06, .57) circle (.035 and .029); %% Nostrils
\draw[gray,line width=.4pt] (-.11,.37) to[out=-10*\happiness,in=180+10*\happiness] (.11,.37); %% Mouth
%% The arms:
\path[path picture=\pigshading{pigdark},yshift=-.9cm,xshift=-.2cm] (-0.2402, 0.9823) .. controls (-0.2994, 1.0582) and (-0.3721, 1.0651) .. (-0.4024, 0.9978) .. controls (-0.4327, 0.9305) and (-0.4092, 0.8145) .. (-0.35, 0.7386) .. controls (-0.3311, 0.7145) and (-0.3101, 0.6964) .. (-0.289, 0.6862) .. controls (-0.2755, 0.7023) and (-0.2498, 0.7563) .. (-0.2498, 0.7563) .. controls (-0.2498, 0.7563) and (-0.1790, 0.731) .. (-0.1611, 0.746) .. controls (-0.1611, 0.746) and (-0.1809, 0.9064) .. (-0.2402, 0.9823) -- cycle;
\path[path picture=\pigshading{pigdark},yshift=-.9cm,xshift=.2cm] (0.2402, 0.9823) .. controls (0.2994, 1.0582) and (0.3721, 1.0651) .. (0.4024, 0.9978) .. controls (0.4327, 0.9305) and (0.4092, 0.8145) .. (0.35, 0.7386) .. controls (0.3311, 0.7145) and (0.3101, 0.6964) .. (0.289, 0.6862) .. controls (0.2755, 0.7023) and (0.2498, 0.7563) .. (0.2498, 0.7563) .. controls (0.2498, 0.7563) and (0.1790, 0.731) .. (0.1611, 0.746) .. controls (0.1611, 0.746) and (0.1809, 0.9064) .. (0.2402, 0.9823) -- cycle;
%% The legs:
\path[path picture=\pigshading{pigdark},yshift=-1.2cm,yscale=0.5] (-0.2402, 0.9823) .. controls (-0.2994, 1.0582) and (-0.3721, 1.0651) .. (-0.4024, 0.9978) .. controls (-0.4327, 0.9305) and (-0.4092, 0.8145) .. (-0.35, 0.7386) .. controls (-0.3311, 0.7145) and (-0.3101, 0.6964) .. (-0.289, 0.6862) .. controls (-0.2755, 0.7023) and (-0.2498, 0.7563) .. (-0.2498, 0.7563) .. controls (-0.2498, 0.7563) and (-0.1790, 0.731) .. (-0.1611, 0.746) .. controls (-0.1611, 0.746) and (-0.1809, 0.9064) .. (-0.2402, 0.9823) -- cycle;
\path[path picture=\pigshading{pigdark},yshift=-1.2cm,yscale=0.5] (0.2402, 0.9823) .. controls (0.2994, 1.0582) and (0.3721, 1.0651) .. (0.4024, 0.9978) .. controls (0.4327, 0.9305) and (0.4092, 0.8145) .. (0.35, 0.7386) .. controls (0.3311, 0.7145) and (0.3101, 0.6964) .. (0.289, 0.6862) .. controls (0.2755, 0.7023) and (0.2498, 0.7563) .. (0.2498, 0.7563) .. controls (0.2498, 0.7563) and (0.1790, 0.731) .. (0.1611, 0.746) .. controls (0.1611, 0.746) and (0.1809, 0.9064) .. (0.2402, 0.9823) -- cycle;
\end{tikzpicture}
\end{document}