19

I'm trying to draw a sleeping duck, using the extremely cool tikzducks.sty. And I encounter two problems. To explain them, let me present the MWE first.

\documentclass{standalone}
\usepackage{tikzducks}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}[scale=9] % changing the scale to 1 (or even somewhat larger values) fails
 \duck[eye=yellow!50!brown,pupil=yellow!50!brown]
        \begin{scope}[ultra thick,rotate=-20,decoration={ticks,raise=-4,amplitude=4,segment length=8
        }]
        \draw[decorate] (0.161,1.682) arc [start angle=220, end angle=320,x radius=0.0893, y radius=0.125];
%       \draw[decorate] (0.23,1.7675) ellipse (0.0893 and 0.125); %from tikzducks.sty
        \draw[decorate] (-0.06,1.74) ellipse (0.0786 and 0.1143); %from tikzducks.sty
%       \draw[decorate] (-0.125,1.67) arc [start angle=220, end angle=320,x radius=0.0893, y radius=0.125];
        \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

The right eye (OK, the duck would say it's her left eye) is roughly as I want it to be. However, I had to move the center of the ellipse whose arc I was drawing relative to the values found in tikzducks.sty. On the left I I drew the complete ellipse, and no adjustment of the coordinates was necessary. (Of course, ultimately I'd like only a arc here, too.) So my first question is whether one can draw an elliptical arc sitting on the ellipse without adjusting this coordinate.

What is more, if I downscale the picture, i.e. remove the [scale=9] after begin{tikzpicture}, the compilation fails with a ! Dimension too large. error. Is there a way to fix this? (Or do the ducks have to stay awake all the time? ;-)

Henri Menke
  • 109,596
  • 2
    An ellipse is drawn with the pen (coordinate before ellipse, (0.23,1.7675) in this case) initially located on its center. While an arc is drawn with the pen located on the starting point, which in this case should be over the ellipse. – Ignasi Jan 08 '18 at 17:04
  • @Ignasi Thanks, I am aware of this. (Perhaps I should have written this.) My question is whether one can only draw a part of an ellipse with the placement coinciding with the one of the full ellipse -- the above is an example for a situation where this could be useful. –  Jan 08 '18 at 17:11
  • @marmot you could draw the full ellipse and clip to the part you want to see. – samcarter_is_at_topanswers.xyz Jan 08 '18 at 17:13
  • @samcarter That's a great suggestion! Then the "only" remaining problem is the Dimension too large error. –  Jan 08 '18 at 17:17
  • 4
    Personally, I would let sleeping ducks lie. – Alan Munn Jan 08 '18 at 18:22
  • 1
    ooh a duck-friendly marmot! ♥ – Paulo Cereda Jan 08 '18 at 21:50
  • @AlanMunn be my guest ;-) –  Jan 08 '18 at 21:57
  • 1
    @PauloCereda Well, if there is one thing marmots are good at (apart from eating, of course), it's sleeping ;-) –  Jan 08 '18 at 21:59
  • Am I alone in pronouncing 'slee-ping duck' to rhyme with 'Peking duck'? – Strawberry Jan 08 '18 at 22:01
  • @AlanMunn But they're not ;). – cfr Jan 09 '18 at 02:23
  • @cfr lie has two meanings, either being in a horizontal position, which they don't, or not telling the truth, which will be hard to express in a simple picture (unless you want to prove me lies;-) –  Jan 09 '18 at 02:27
  • @marmot They are surely in a horizontal position. Vertical would be 'heads down, tails up' (or, I guess, tails down, heads up, but that seems rather less likely from a physiological point of view). 'Lie' has more than two meanings .... – cfr Jan 09 '18 at 04:19

2 Answers2

24

I wouldn't use decorate. You run into problems at different scales, also you can't really fine tune the length. I would draw the eyelashes one by one, and perhaps even bend some. As the line width doesn't scale, some style to adapt the lashes will be needed. A sleeping mask is perhaps easier ;-).

\documentclass{article}
\usepackage{tikzducks}

\begin{document}

\begin{tikzpicture}[scale=1] 
\duck

\path[rotate=-20]
    (0.23,1.7675)coordinate(ECR) ellipse (0.0893 and 0.125);

\path[rotate=-20]
    (-0.06,1.74)coordinate(ECL) ellipse (0.0786 and 0.1143);

\foreach \x/\y in {0/1,1/2,2/3,3/3.3,4/3,5/2,6/1.4}
{ \draw[brown!50!black,rotate=-20,line cap=round] (ECR)--++(\x*15+220:0.11cm+\y*0.012cm); };

\foreach \x/\y in {0/1,1/2,2/3,3/3.3,4/3,5/2,6/1.4}
{ \draw[brown!50!black,rotate=-20,line cap=round] (ECL)--++(\x*15+220:0.11cm+\y*0.009cm); };
%
%
\fill[rotate=-20,yellow!50!brown]
    (0.23,1.7675) ellipse (0.0893 and 0.125);
%
\fill[rotate=-20,yellow!50!brown]
    (-0.06,1.74) ellipse (0.0786 and 0.1143);

\end{tikzpicture}

\begin{tikzpicture}[scale=5] % changing the scale to 1 (or even somewhat larger values) fails
\duck

\path[rotate=-20]
    (0.23,1.7675)coordinate(ECR) ellipse (0.0893 and 0.125);

\path[rotate=-20]
    (-0.06,1.74)coordinate(ECL) ellipse (0.0786 and 0.1143);

\begin{scope}[ultra thick]
\foreach \x/\y in {0/1,1/2,2/3,3/3.3,4/3,5/2,6/1.4}
{ \draw[brown!50!black,rotate=-20,line cap=round] (ECR)--++(\x*15+220:0.11cm+\y*0.012cm); };

\foreach \x/\y in {0/1,1/2,2/3,3/3.3,4/3,5/2,6/1.4}
{ \draw[brown!50!black,rotate=-20,line cap=round] (ECL)--++(\x*15+220:0.11cm+\y*0.009cm); };
\end{scope}
%
%
\fill[rotate=-20,yellow!50!brown]
    (0.23,1.7675) ellipse (0.0893 and 0.125);
%
\fill[rotate=-20,yellow!50!brown]
    (-0.06,1.74) ellipse (0.0786 and 0.1143);

\end{tikzpicture}
\end{document}

enter image description here

Andrew Swann
  • 95,762
Ulrike Fischer
  • 327,261
5

A solution with an updated version of veclen. I used xfp. The problem is the same with my macro \tkzMarkAngle. I used the library decoration and an error appeared with small angle's value.

\documentclass{standalone}
\usepackage{tikzducks,xfp}
\usetikzlibrary{decorations.pathreplacing}
\makeatletter
\let\pgfmath@function@veclen\relax
\pgfmathdeclarefunction*{veclen}{2}{%
\begingroup%
    \pgfmath@x#1pt\relax%
    \pgfmath@y#2pt\relax%
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y%
    \edef\tkz@temp@a{\fpeval{\pgfmath@tonumber{\pgf@xa}}}
    \edef\tkz@temp@b{\fpeval{\pgfmath@tonumber{\pgf@ya}}}
    \edef\tkz@temp@sum{\fpeval{%
        (\tkz@temp@a*\tkz@temp@a+\tkz@temp@b*\tkz@temp@b)}}
    \edef\tkz@xfpMathLen{\fpeval{sqrt(\tkz@temp@sum)}}
%\edef\pgfmath@tmp{\fpeval{round(\tkzFPMathLen,6)}}
%\pgfmath@tmp %
    \pgfmath@returnone\tkz@xfpMathLen pt%
\endgroup%
}
\makeatother
\begin{document}
\begin{tikzpicture}[scale=1] % changing the scale to 1 (or even somewhat larger values) fails
 \duck[eye=yellow!50!brown,pupil=yellow!50!brown]
        \begin{scope}[line width=.4pt,rotate=-20,decoration={ticks,raise=-.5,amplitude=.5,segment length=1.5
        }]
        \draw[decorate] (0.161,1.682) arc [start angle=220, end angle=320,x radius=0.0893, y radius=0.125];
       \draw[decorate] (-0.125,1.67) arc [start angle=220, end angle=320,x radius=0.0893, y radius=0.125];
        \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

Alain Matthes
  • 95,075