% Florian Sihler, 2022
% Licensed under GNU General Public License version 3
% https://opensource.org/licenses/gpl-3.0.html
\newif\if@pingu@x@rook@draw@hatch@
\pingu@create@extra{rook}{%
    rook/.code          = \pingu@set@extra{rook}{true}\pingu@color{rook}{#1},
    rook/.default       = pingu@silver,
    rook back/.code     = \pingu@color{rook@back}{#1},
    rook hatch/.is if   = @pingu@x@rook@draw@hatch@,
    rook hatch/.default = true,
    rook shade/.code    = \pingu@color{rook@shade}{#1},
}{rook back=\pingu@color@rook!85!black,rook shade=\pingu@color@rook!92!black,rook hatch}
\def\pingu@draw@ea@rook{%
\if@pingu@do@back@\else\if@pingu@x@rook@draw@hatch@\else\pingu@layer{foreground}[]\fi\fi
    \pingu@block[even odd rule]{\pingu@color@rook} ([xshift=-.2mm]\pingu@name-wings-side-right|-\pingu@name-foot-right) [rounded corners=\p@] to[bend right=9] coordinate[pos=.15] (@tmpe) ([xshift=.2mm]\pingu@name-wings-side-left|-\pingu@name-foot-left) [sharp corners] to[bend right=1.5*\pingu@bend] (\pingu@name-wings-side-left|-\pingu@name-head-top) coordinate (@tmp) to[bend left=3] coordinate[pos=.3] (@tmpc) coordinate[pos=.7] (@tmpd) (\pingu@name-wings-side-right|-\pingu@name-head-top) [rounded corners=\p@] coordinate (@tmpb) to[bend right=1.5*\pingu@bend] cycle \if@pingu@x@rook@draw@hatch@ (\pingu@name-head-center) ellipse[x radius=.8\pingu@w@half, y radius=.45\pingu@w@half]\fi;
    \pingu@block{\pingu@color@rook} (@tmp) to[bend right=2] ++(0,2mm) [rounded corners=.25mm] to[bend left=1] ++(-2mm,-.1mm) -- ++(0,-2.25mm);
    \pingu@block{\pingu@color@rook} (@tmpb) to[bend left=2] ++(0,2mm) [rounded corners=.25mm] to[bend right=1] ++(2mm,-.1mm) -- ++(0,-2.25mm);

    \pingu@block{\pingu@color@rook} (@tmpc)++(-2mm,-.25mm) [rounded corners=.25mm] to[bend left=2] ++(0,2.25mm) to[bend right=1] ++(4mm,.05mm) -- ++(0,-2.25mm);
    \pingu@block{\pingu@color@rook} (@tmpd)++(2mm,-.25mm) [rounded corners=.25mm] to[bend left=2] ++(0,2.25mm) to[bend left=1] ++(-4mm,-.05mm) -- ++(0,-2.25mm);

    % custom shade boi (or gurl, wateva)
    \scope
        \clip ([xshift=-.2mm]\pingu@name-wings-side-right|-\pingu@name-foot-right) [rounded corners=\p@] to[bend right=5] ([xshift=.2mm]\pingu@name-wings-side-left|-\pingu@name-foot-left) [sharp corners] to[bend right=1.5*\pingu@bend] (\pingu@name-wings-side-left|-\pingu@name-head-top) -- ++(0,2mm) to[bend left=3] (\pingu@name-wings-side-right|-\pingu@name-head-top) to[bend right=1.5*\pingu@bend] cycle;
        \if@pingu@x@rook@draw@hatch@
        \clip[/pingu/@invclip] (\pingu@name-head-center) ellipse[x radius=.8\pingu@w@half, y radius=.45\pingu@w@half];
        \fi
        \pingu@block{\pingu@color@rook@shade} (@tmpe) to[bend right=5] ([xshift=.2mm]@tmpe-|@tmp) to[bend right=1.5*\pingu@bend] ([yshift=2mm]@tmp) to[bend left=10] cycle;
    \endscope
    \if@pingu@do@back@\else\if@pingu@x@rook@draw@hatch@\else\endpingu@layer\fi\fi

    \pingu@layer{background}[]
        \pingu@block{\pingu@color@rook@back} (@tmp) to[bend right=3] coordinate[pos=.3] (@tmpc) coordinate[pos=.7] (@tmpd) (@tmpb) to[bend right=30] cycle;
        \pingu@block{\pingu@color@rook@back} (@tmpb) to[bend left=2] ++(0,2mm) [rounded corners=.25mm] to[bend left=1] ++(2mm,.1mm) -- ++(0,-2.25mm);
        \pingu@block{\pingu@color@rook@back} (@tmp) to[bend right=2] ++(0,2mm) [rounded corners=.25mm] to[bend right=1] ++(-2mm,.1mm) -- ++(0,-2.25mm);

        \pingu@block{\pingu@color@rook@back} (@tmpc)++(-2mm,-.49mm) [rounded corners=.25mm] to[bend left=2] ++(0,2.25mm) to[bend right=1] ++(4mm,.05mm) -- ++(0,-2.25mm);
        \pingu@block{\pingu@color@rook@back} (@tmpd)++(2mm,-.49mm) [rounded corners=.25mm] to[bend left=2] ++(0,2.25mm) to[bend left=1] ++(-4mm,-.05mm) -- ++(0,-2.25mm);
    \endpingu@layer
}

\newif\if@pingu@x@crown@ddd@ % 3d
\newif\if@pingu@x@crown@shade@ % 3d
\pingu@create@extra{crown}{%
  crown/.code             = \pingu@set@extra{crown}{true}\pingu@color{crown}{#1},
  crown/.default          = pingu@yellow,
  crown 3d/.is if         = @pingu@x@crown@ddd@, crown 3d/.default = true,
  crown 2d/.style         = {crown=#1, crown 3d=false},
  crown 2d/.default       = pingu@yellow,
  crown back/.code        = \pingu@color{crown@back}{#1},
  crown front bend/.code  = \def\pingu@x@crown@f@bend{#1},
  crown back bend/.code   = \def\pingu@x@crown@b@bend{#1},
  crown gem shade/.is if  = @pingu@x@crown@shade@, crown gem shade/.default = true,
  crown gem colors/.code n args = 7{\pingu@color{crown@gem@a}{#1}\pingu@color{crown@gem@b}{#2}\pingu@color{crown@gem@c}{#3}\pingu@color{crown@gem@d}{#4}\pingu@color{crown@gem@e}{#5}\pingu@color{crown@gem@f}{#6}\pingu@color{crown@gem@g}{#7}},
  crown gem ring/.code   = \pingu@color{crown@gem@ring}{#1},
  crown position/.code args  = {#1:(#2,#3)#4}{\def\pingu@x@crown@angle{#1}\def\pingu@x@crown@xshift{#2}\def\pingu@x@crown@yshift{#3}\def\pingu@x@crown@scale{#4}},
}{crown position={-9:(1mm,0mm)1},crown front bend=16,crown back bend=9,crown back=\pingu@color@crown!93!black,crown 3d,crown gem colors={pingu@purple}{pingu@blue}{pingu@green}{pingu@purple}{pingu@green}{pingu@blue}{pingu@purple},crown gem ring=\pingu@color@crown!85!white,crown gem shade}

% color | bend1 | bend1
\def\pingu@draw@ea@crown@s#1#2#3{
\pingu@block{#1} [rounded corners=.2mm](-6.25mm,-.25cm) to[bend left=2] ++(0,3.125mm) to[bend #2=\pingu@x@crown@f@bend]
    coordinate[pos=0] (r2)  coordinate[pos=.07] (r1)
    coordinate[pos=.14-.07] (a1)  coordinate[pos=.14] (a2) coordinate[pos=.14+.07] (a3)
    coordinate[pos=.30-.08] (b1)  coordinate[pos=.30] (b2) coordinate[pos=.30+.08] (b3)
    coordinate[pos=.50- .1] (c1)  coordinate[pos=.50] (x2) coordinate[pos=.50+ .1] (c3)
    coordinate[pos=.69-.08] (d1)  coordinate[pos=.69] (d2) coordinate[pos=.69+.08] (d3)
    coordinate[pos=.85-.07] (e1)  coordinate[pos=.85] (e2) coordinate[pos=.85+.07] (e3)
    coordinate[pos=1] (l2)  coordinate[pos=.93] (l1)
    ++(1.375cm,0) to[bend left=2] ++(0,-3.125mm) to[bend #3=\pingu@x@crown@f@bend] (-6mm,-.25cm) -- cycle;
\path (x2)++(0,.9mm) coordinate (c2);
\@for\a:={a,b,c,d,e}\do{
    \pingu@block{#1} ([yshift=-.1mm]\a1) to[bend right=\pingu@x@crown@f@bend] ([yshift=-.1mm]\a3) to[bend right=2] ([yshift=1.85mm]\a2) to[bend right=2] ([yshift=-.1mm]\a1) -- cycle;
}
\pingu@block{#1} (l2)++(0,-.2mm) to[bend right=2] ++(0,1.95mm) -- (l1) -- cycle;
\pingu@block{#1} (r2)++(0,-.2mm) to[bend left=2] ++(0,1.95mm) -- (r1) -- cycle;
}

% color | at | shift | scale
\def\pingu@draw@ea@crown@g#1#2#3#4{
\scope[shift={(#22)},shift={(#3,-.33mm)}]
    \pingu@block{\pingu@color@crown@gem@ring}  ellipse [x radius=.715mm*#4, y radius=.925mm*#4];
    \pingu@block{#1}  ellipse [x radius=.633mm*#4, y radius=.85mm*#4];
    \protected@edef\@tmp{#1}\ifx\@tmp\@pingu@none\else
    \if@pingu@x@crown@shade@
    \shade[ball color=#1,fill opacity=.45,shading angle=-95]  ellipse [x radius=.633mm*#4, y radius=.85mm*#4];
    \else
    \pingu@block[rotate around={7:(42:.3mm*#4 and .4mm*#4)}]{#1!45!pingu@white} (42:.3mm*#4 and .4mm*#4) ellipse[x radius=.17mm*#4, y radius=.24mm*#4];
    \pingu@block[rotate around={7:(232:.275mm*#4 and .35mm*#4)}]{#1!45!pingu@white} (232:.275mm*#4 and .35mm*#4) ellipse[x radius=.06mm*#4, y radius=.085mm*#4];
    \fi\fi
\endscope
}
\def\pingu@draw@ea@crown{%
\scope[rotate around={\pingu@x@crown@angle:(\pingu@name-head-top)},%
       shift={(\pingu@name-head-top)},
       shift={(\pingu@x@crown@xshift,\pingu@x@crown@yshift)},
       scale=\pingu@x@crown@scale]
% draw front
\if@pingu@x@crown@ddd@
    \pingu@draw@ea@crown@s{\pingu@color@crown}{right}{left}
    \def\@tmpa{.05mm}\def\@tmpb{.025mm}
\else
    \pingu@draw@ea@crown@s{\pingu@color@crown}{left}{right}
    \def\@tmpa{-.015mm}\def\@tmpb{-.035mm}
\fi
% draw the emeralds
\pingu@draw@ea@crown@g{\pingu@color@crown@gem@b}{a}{-\@tmpa}1
\pingu@draw@ea@crown@g{\pingu@color@crown@gem@c}{b}{-\@tmpb}1
\pingu@draw@ea@crown@g{\pingu@color@crown@gem@d}{x}{\z@}{1.35}
\pingu@draw@ea@crown@g{\pingu@color@crown@gem@e}{d}{\@tmpb}1
\pingu@draw@ea@crown@g{\pingu@color@crown@gem@f}{e}{\@tmpa}1
\pingu@layer{background}[]
\pingu@block{\pingu@color@crown@gem@a} (r2)++(0,-.33mm) ellipse [x radius=.3mm, y radius=.8mm];
\pingu@block{\pingu@color@crown@gem@ring} (r2)++(0,-.33mm) ellipse [x radius=.1mm, y radius=.885mm];
\pingu@block{\pingu@color@crown@gem@g} (l2)++(0,-.33mm) ellipse [x radius=.3mm, y radius=.8mm];
\pingu@block{\pingu@color@crown@gem@ring} (l2)++(0,-.33mm) ellipse [x radius=.1mm, y radius=.885mm];
% draw back if 3d
\if@pingu@x@crown@ddd@
    \pingu@draw@ea@crown@s{\pingu@color@crown@back}{left}{right}
\fi
\endpingu@layer
\endscope
}

\newif\if@pingu@x@princesscrown@ddd@
\newif\if@pingu@x@princesscrown@shade@
\newif\if@pingu@x@princesscrown@bobbles@
\pingu@create@extra{princesscrown}{%
  princess crown/.code    = \pingu@set@extra{princesscrown}{true}\pingu@color{princesscrown}{#1},
  princess crown/.default = pingu@yellow,
  princess crown 3d/.is if= @pingu@x@princesscrown@ddd@, princess crown 3d/.default = true,
  princess crown 2d/.style   = {princess crown=#1, princess crown 3d=false},
  princess crown 2d/.default = pingu@yellow,
  princess crown back/.code  = \pingu@color{princesscrown@back}{#1},
  princess crown front bend/.code  = \def\pingu@x@princesscrown@f@bend{#1},
  princess crown back bend/.code   = \def\pingu@x@princesscrown@b@bend{#1},
  princess crown gem shade/.is if  = @pingu@x@princesscrown@shade@,
  princess crown bobbles/.is if = @pingu@x@princesscrown@bobbles@,
  princess crown gem shade/.default = true,
  princess crown gem colors/.code n args = 5{\pingu@color{princesscrown@gem@a}{#1}\pingu@color{princesscrown@gem@b}{#2}\pingu@color{princesscrown@gem@c}{#3}\pingu@color{princesscrown@gem@d}{#4}\pingu@color{princesscrown@gem@e}{#5}},
  princess crown gem ring/.code   = \pingu@color{princesscrown@gem@ring}{#1},
  princess crown position/.code args  = {#1:(#2,#3)#4}{\def\pingu@x@princesscrown@angle{#1}\def\pingu@x@princesscrown@xshift{#2}\def\pingu@x@princesscrown@yshift{#3}\def\pingu@x@princesscrown@scale{#4}},
}{princess crown position={-9:(1mm,0mm)1},princess crown front bend=12,princess crown back bend=7,princess crown back=\pingu@color@princesscrown!93!black,princess crown 3d,princess crown gem colors={pingu@purple}{pingu@blue}{pingu@green}{pingu@blue}{pingu@purple},princess crown gem ring=\pingu@color@princesscrown!85!white,princess crown gem shade,princess crown bobbles}

% color | bend1 | bend2
\def\pingu@draw@ea@princesscrown@s#1#2#3{
\pingu@block{#1} [rounded corners=.2mm](-3.25mm,-.15cm) to[bend left=2] ++(0,2.32mm) to[bend #2=\pingu@x@princesscrown@f@bend]
    coordinate[pos=0] (r2)  coordinate[pos=.065] (r1)
    coordinate[pos=.11] (a1) coordinate[pos=.2] (a2) coordinate[pos=.29] (a3)
    coordinate[pos=.35] (b1) coordinate[pos=.50] (x2) coordinate[pos=.65] (b3)
    coordinate[pos=.71] (c1) coordinate[pos=.8] (c2) coordinate[pos=.89] (c3)
    coordinate[pos=1] (l2)  coordinate[pos=.93] (l1)
    ++(8mm,0) to[bend left=2] ++(0,-2.32mm) to[bend #3=\pingu@x@princesscrown@f@bend] (-3mm,-.15cm) -- cycle;
\path (x2)++(0,.9mm) coordinate (b2);
\@for\a:={a,b,c}\do{
    \pingu@block{#1} ([yshift=-.1mm]\a1) to[bend right=\pingu@x@princesscrown@f@bend] ([yshift=-.1mm]\a3) to[bend left=2] ([yshift=2.15mm]\a2) to[bend left=2] ([yshift=-.1mm]\a1) -- cycle;
    \if@pingu@x@princesscrown@bobbles@\pingu@block{#1} ([yshift=2.15mm]\a2) circle [radius=.45\p@];\fi
}
\pingu@block{#1} (l2)++(0,-.2mm) to[bend left=2] ++(0,2.25mm) -- (l1) -- cycle;
\pingu@block{#1} (r2)++(0,-.2mm) to[bend right=2] ++(0,2.25mm) -- (r1) -- cycle;
\if@pingu@x@princesscrown@bobbles@\pingu@block{#1} (l2)++(0,2.05mm) circle [radius=.45\p@];
\pingu@block{#1} (r2)++(0,2.05mm) circle [radius=.45\p@];\fi
}

% draw single gem; color | at | shift | scale
\def\pingu@draw@ea@princesscrown@g#1#2#3#4{
\scope[shift={(#22)},shift={(#3,-.33mm)}]
    \pingu@block{\pingu@color@princesscrown@gem@ring} ellipse [x radius=.715mm*#4, y radius=.925mm*#4];
    \pingu@block{#1} ellipse [x radius=.633mm*#4, y radius=.85mm*#4];
    \protected@edef\@tmp{#1}\ifx\@tmp\@pingu@none\else
    \if@pingu@x@princesscrown@shade@
    \shade[ball color=#1,fill opacity=.45,shading angle=-95] ellipse [x radius=.633mm*#4, y radius=.85mm*#4];
    \else
    \pingu@block[rotate around={7:(42:.3mm*#4 and .4mm*#4)}]{#1!45!pingu@white} (42:.3mm*#4 and .4mm*#4) ellipse[x radius=.17mm*#4, y radius=.24mm*#4];
    \pingu@block[rotate around={7:(232:.275mm*#4 and .35mm*#4)}]{#1!45!pingu@white} (232:.275mm*#4 and .35mm*#4) ellipse[x radius=.06mm*#4, y radius=.085mm*#4];
    \fi\fi
\endscope}
\def\pingu@draw@ea@princesscrown{%
\scope[rotate around={\pingu@x@princesscrown@angle:(\pingu@name-head-top)},%
       shift={(\pingu@name-head-top)},
       shift={(\pingu@x@princesscrown@xshift,\pingu@x@princesscrown@yshift)},
       scale=\pingu@x@princesscrown@scale]
% draw front
\if@pingu@x@princesscrown@ddd@
    \pingu@draw@ea@princesscrown@s{\pingu@color@princesscrown}{right}{left}
    \def\@tmpa{.05mm}
\else
    \pingu@draw@ea@princesscrown@s{\pingu@color@princesscrown}{left}{right}
    \def\@tmpa{-.015mm}
\fi
% draw the emaralds
\pingu@draw@ea@princesscrown@g{\pingu@color@princesscrown@gem@b}{a}{-\@tmpa}{.95}
\pingu@draw@ea@princesscrown@g{\pingu@color@princesscrown@gem@c}{x}{\z@}{1.3}
\pingu@draw@ea@princesscrown@g{\pingu@color@princesscrown@gem@d}{c}{\@tmpa}{.95}
\pingu@layer{background}[]
\pingu@block{\pingu@color@princesscrown@gem@a} (r2)++(0,-.33mm) ellipse [x radius=.3mm, y radius=.8mm];
\pingu@block{\pingu@color@princesscrown@gem@ring} (r2)++(0,-.33mm) ellipse [x radius=.1mm, y radius=.885mm];
\pingu@block{\pingu@color@princesscrown@gem@e} (l2)++(0,-.33mm) ellipse [x radius=.3mm, y radius=.8mm];
\pingu@block{\pingu@color@princesscrown@gem@ring} (l2)++(0,-.33mm) ellipse [x radius=.1mm, y radius=.885mm];
% draw back if 3d
\if@pingu@x@princesscrown@ddd@
    \pingu@draw@ea@princesscrown@s{\pingu@color@princesscrown@back}{left}{right}
\fi
\endpingu@layer
\endscope
}