Skip to content

Commit

Permalink
Added a wrapper around \duck@draw to turn it into a pic, seems to work
Browse files Browse the repository at this point in the history
(but could do with more extensive testing - see duck_library.tex for
tests).

Also added a "super duck" with everything enabled.

Minor modification to tikzducks.sty to allow unknown keys to be passed
back to tikz or pgf, also removed bounding scope as that is put in place
by the pic syntax.
  • Loading branch information
loopspace committed Mar 28, 2018
1 parent 277606f commit 1a039d7
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 11 deletions.
39 changes: 39 additions & 0 deletions duckpond/duck_library.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{ducks}

%\usepackage{trace-pgfkeys}

%\pgfkeystracelevel{trace}
%\tikzset{duck/water=blue}
%\pgfkeystracelevel{silent}

\begin{document}

\begin{tikzpicture}
\draw (0,0) pic[duck/super duck] {duck};
\end{tikzpicture}

\begin{tikzpicture}
%\draw (4,0) pic[duck/water=blue] {duck};
\draw (0,0) pic[
duck/water=blue,
duck/book={Animal Farm},
] {duck};
\draw (0,4) pic[
duck/water=blue,
scale=2,
duck/book={Animal Farm},
] {duck};
\end{tikzpicture}

\begin{tikzpicture}
\duck[book={Animal Farm}]
\end{tikzpicture}

\begin{tikzpicture}
\duck[xscale=-1]
\end{tikzpicture}

\end{document}
26 changes: 15 additions & 11 deletions tikzducks.sty
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,13 @@
\newif\ifduck@crozier
\newif\ifduck@davidlikespineapplepizza

\tikzset{
/duck/.cd,
name/.code = \duck@nametrue \def\duck@name{#1},
\tikzset{
%
% Pass unknown keys on to tikz
%
/duck/.search also={/tikz,/pgf},
/duck/.cd,
name/.code= \duck@nametrue \def\duck@name{#1},
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Environment
Expand Down Expand Up @@ -304,7 +308,7 @@
}

\def\duck@draw{
\begin{scope}
%\begin{scope}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% minimal bounding box size
Expand Down Expand Up @@ -721,29 +725,29 @@
\ifduck@book
\fill[\duck@bookcolour,rotate=-20]
(0.40,1.20) rectangle (0.80,0.60);
\node[rotate=-20*\yscalefactor/\xscalefactor, color=white] at (0.88,0.70) {\duck@book};%
\node[transform shape, rotate=-20*\yscalefactor/\xscalefactor, color=white] at (0.88,0.70) {\duck@book};%
\fi
%
% signpost %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ifduck@signpost
\fill[\duck@signcolour, rounded corners=\yscalefactor*1, rotate=-20] (0.8,0.75) rectangle (0.9,1.75);
\fill[\duck@signcolour, rounded corners=\yscalefactor*1, rotate=-20] (0.4,1.7) rectangle (1.3,2.4);
\fill[\duck@signback, rounded corners=\yscalefactor*1, rotate=-20] (0.45,1.75) rectangle (1.25,2.35);
\node[rotate=-20*\yscalefactor/\xscalefactor, color=white] at (1.5,1.65) {\duck@signpost};
\node[transform shape, rotate=-20*\yscalefactor/\xscalefactor, color=white] at (1.5,1.65) {\duck@signpost};
\fi
%
% speech bubble %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ifduck@speech
\fill[\duck@bubblecolour] (-0.5,1.8) ellipse (0.7 and 0.3);
\fill[\duck@bubblecolour] (-0.2,1.54) -- (0.2,1.35) -- (0.0,1.6) -- cycle;
\node at (-0.5,1.8) {\duck@speech};
\node[transform shape] at (-0.5,1.8) {\duck@speech};
\fi
%
% think bubble %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ifduck@think
\fill[\duck@bubblecolour] (2,2.4) ellipse (0.7 and 0.35);
\fill[\duck@bubblecolour] (1.55,2.35) circle (0.25) (2.0,2.15) circle (0.25) (2.4,2.25) circle (0.25) (1.6,2.55) circle (0.25) (2.0,2.6) circle (0.25) (2.35,2.5) circle (0.25) (1.65,1.95) circle (0.1) (1.55,1.80) circle (0.06) (1.47,1.70) circle (0.03);
\node at (2,2.4) {\duck@think};
\node[transform shape] at (2,2.4) {\duck@think};
\fi
%
% magic wand %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down Expand Up @@ -941,7 +945,7 @@
%
%\draw (current bounding box.north west) rectangle (current bounding box.south east);% For debugging bounding boxes
%
\end{scope}
%\end{scope}
}% from `\def\duck@draw{` at the very beginning

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down Expand Up @@ -1271,7 +1275,7 @@
}
\end{scope}
\end{pgfinterruptboundingbox}
\node at (wing) {\stripes@emblem };
\node[transform shape] at (wing) {\stripes@emblem };
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%.........................%%%%%%%%%%%%%%%%%%%.........................
Expand Down Expand Up @@ -1308,4 +1312,4 @@
%................%%%%%%%%.................%%%...%%%%%%................
%....................%%%%%%%%......%%%%%%%%%%%%%%%....................
%..........................%%%%%%%%%%%%%%%%%..........................
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87 changes: 87 additions & 0 deletions tikzlibraryducks.code.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
\usepackage{tikzducks}


% This is all that is needed ...
\tikzset{
duck/.pic={%
\duck@draw
},
duck/.search also={,/tikz,/pgf},
}

% A test duck with *everything*
\tikzset{
/duck/.cd,
super duck/.style={
duck/.cd,
name=Donald,
% Environment %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
water,
% body parts %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
grumpy,
% hair styles %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
shorthair,
longhair,
crazyhair,
recedinghair,
eyebrow,
beard,
mohican,
mullet,
% clothing %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
tshirt,
jacket,
tie,
cape,
stripes,
% Headgear %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
alien,
hat,
cap,
santa,
unicorn,
magichat,
chef,
witch,
graduate,
beret,
crown,
queencrown,
kingcrown,
peakedcap,
bunny,
tophat,
darthvader,
% Accessories %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
glasses,
sunglasses,
squareglasses,
icecream,
book,
magicwand,
cricket,
rollingpin,
signpost,
lightsaber,
cake,
pizza,
hockey,
baguette,
football,
mask,
necklace,
milkshake,
wine,
prison,
speech,
think,
torch,
easter,
basket,
buttons,
sheep,
horsetail,
crozier,
davidlikespineapplepizza,
}
}

0 comments on commit 1a039d7

Please sign in to comment.