I'm currently working on a little latex package to bring rubber ducks into tikz
(a continuation from https://tex.stackexchange.com/a/347458/36296). As this is the first bigger project in which I use tikz
I'd like to hear your opinion about the current way it is implemented.
I'm looking forward to your suggestions!
A few questions I have in particular:
Do you find it acceptable to load
xcolor
with the optionsvgnames
? This could lead to option clashes if used in projects that use other colour systems. On the other hand its so easy to use the pre-made colours, much less work than mixing or defining all the colours myself.-> confirmed that this is bad idea, see edit below
Do you think the commands needs to be more flexible, i.e. optional arguments to adjust specific colours/shapes of the subcomponents? For example I could introduce an optional argument to change the head colour independently from the body colour, but this might make using the package more complicated and more importantly the code much harder to read.
A cut down version of the package:
\documentclass{article}
\RequirePackage[svgnames]{xcolor}
\RequirePackage{tikz}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% combine ducks
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%1: skin colour
\newcommand{\duck}[1]{%
\colorlet{duck}{#1}
\colorlet{eye}{Cornsilk}
\colorlet{pupil}{black}
\colorlet{bill}{orange}
\duckbody{duck}
\duckhead{duck}
\duckbill{bill}
\duckeyes{pupil}{eye}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% body parts
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%1: skin colour
\newcommand{\duckbody}[1]{%
\path[fill=#1] (0.5128,1.1446) .. controls (0.2669,1.1021) and (-0.1252,0.6574) .. (0.2894,0.2611) .. controls (0.7040,-0.1351) and (2.8627,0.1303) .. (1.8177,1.4188) .. controls (0.9375,0.9457) and (1.2396,1.3785) .. (0.5128,1.1446) -- cycle;
}
%1: skin colour
\newcommand{\duckhead}[1]{%
\path[fill=#1] (0.90,1.50) ellipse (0.50 and 0.625);
}
%1: bill colour
\newcommand{\duckbill}[1]{%
\path[fill=#1] (0.4056,1.4721) .. controls (0.6429,1.5298) and (0.5408,1.3034) .. (0.9095,1.37) .. controls (0.0825,0.85) and (0.2685,1.3690) .. (0.4058,1.4721) -- cycle;
}
%1: pupile colour
%2: eye colour
\newcommand{\duckeyes}[2]{%
% right eye
\path[fill=#2, rotate=-20] (0.23,1.7675) ellipse (0.0893 and 0.125);
\path[fill=#1, rotate=-20] (0.26,1.7575) ellipse (0.0357 and 0.0714);
% left eye
\path[fill=#2, rotate=-20] (-0.06,1.74) ellipse (0.0786 and 0.1143);
\path[fill=#1, rotate=-20] (-0.03,1.73) ellipse (0.0286 and 0.0643);
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Accessories
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%1: frame colour
\newcommand{\addglasses}[1]{
\path[draw=#1,line width=1] (0.93,1.62) -- (1.30,1.50);
\draw[line width=1,color=#1] (0.73,1.67) arc (65:92:0.20);
\path[draw=#1,line width=1,rotate=-20] (0.23,1.7675) circle (0.125);
\path[draw=#1,line width=1,rotate=-20] (-0.06,1.74) circle (0.1143);
}
\begin{document}
\begin{tikzpicture}
\duck{yellow}
\addglasses{brown}
\end{tikzpicture}
\end{document}
Full code is available from https://github.com/samcarter8/tikzducks
P.S. I know that \RequirePackage
is not meant to be used in documents, but as this part is copied from the .sty
file, I decided to leave it as it is.
EDIT
new version of the code
- without the
svgnames
option ofxcolor
- replaced
\newcommand
by\newcommand*
- hopefully added the necessary
%
, probably added way to many ...
\documentclass{article}
\RequirePackage{xcolor}
\RequirePackage{tikz}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% combine ducks
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%1: skin colour
\newcommand*{\duck}[1]{%
\colorlet{duck}{#1}%
\colorlet{eye}{white!85!yellow}%
\colorlet{pupil}{black}%
\colorlet{bill}{orange}%
\duckbody{duck}%
\duckhead{duck}%
\duckbill{bill}%
\duckeyes{pupil}{eye}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% body parts
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%1: skin colour
\newcommand*{\duckbody}[1]{%
\path[fill=#1] (0.5128,1.1446) .. controls (0.2669,1.1021) and (-0.1252,0.6574) .. (0.2894,0.2611) .. controls (0.7040,-0.1351) and (2.8627,0.1303) .. (1.8177,1.4188) .. controls (0.9375,0.9457) and (1.2396,1.3785) .. (0.5128,1.1446) -- cycle;%
}
%1: skin colour
\newcommand*{\duckhead}[1]{%
\path[fill=#1] (0.90,1.50) ellipse (0.50 and 0.625);%
}
%1: bill colour
\newcommand*{\duckbill}[1]{%
\path[fill=#1] (0.4056,1.4721) .. controls (0.6429,1.5298) and (0.5408,1.3034) .. (0.9095,1.37) .. controls (0.0825,0.85) and (0.2685,1.3690) .. (0.4058,1.4721) -- cycle;%
}
%1: pupile colour
%2: eye colour
\newcommand*{\duckeyes}[2]{%
% right eye
\path[fill=#2, rotate=-20] (0.23,1.7675) ellipse (0.0893 and 0.125);%
\path[fill=#1, rotate=-20] (0.26,1.7575) ellipse (0.0357 and 0.0714);%
% left eye
\path[fill=#2, rotate=-20] (-0.06,1.74) ellipse (0.0786 and 0.1143);%
\path[fill=#1, rotate=-20] (-0.03,1.73) ellipse (0.0286 and 0.0643);%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Accessories
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%1: frame colour
\newcommand*{\addglasses}[1]{%
\path[draw=#1,line width=1] (0.93,1.62) -- (1.30,1.50);%
\draw[line width=1,color=#1] (0.73,1.67) arc (65:92:0.20);%
\path[draw=#1,line width=1,rotate=-20] (0.23,1.7675) circle (0.125);%
\path[draw=#1,line width=1,rotate=-20] (-0.06,1.74) circle (0.1143);%
}
\begin{document}
\begin{tikzpicture}
\duck{yellow}%
\addglasses{brown}%
\end{tikzpicture}
\end{document}
%
and suggest the use of\newcommand*
instead of\newcommand
- the commands created by the non-star version are allways\long
, which you normally don't want. \$\endgroup\$xcolor
without thesvgnames
option the clash would be unavoidable. The package defines Cornsilk to be the same as\definecolor{Cornsilk}{rgb}{1,.972,.864}
. \$\endgroup\$svgnames
option. \$\endgroup\$