Drawing a half-full bottle in TikZ
\documentclass[border=5pt,tikz]{standalone}
\begin{document}
\begin{tikzpicture}[xscale=1,yscale=1]
\fill[blue!20] (0,-2.5) --+ (0,2.5) arc (0:180:1.5) -- (-3,-2.5) arc (180:235:3) --+ (0,-.25) --+ (.45,-.25) --+ (.45,.015) (0,-2.5) arc (0:-55:3);
\fill[white] (0,0) arc(0:180:1.5) --+ (0,-2) -| cycle;
\fill[blue!10] (-1.5,-2) circle ({1.5cm-0.4pt} and 0.5cm); % Thank you, marmot! ;)
\draw[very thick] (0,-2.5) --+ (0,2.5) arc (0:180:1.5) -- (-3,-2.5) arc (180:235:3) --+ (0,-.25) --+ (.45,-.25) --+ (.45,.015) (0,-2.5) arc (0:-55:3);
\end{tikzpicture}
\end{document}
Output: See below
Explanation:
Maybe beginners don't know the clip
option and maybe the want just a type of "trivial" answer, so I had the following idea:
Let's fill the whole bottle with blue color and the just fill the upper part of it with white color. So we get at the end a bottle, which just a part is colored blue. The line
\fill[white] (0,0) arc(0:180:1.5) --+ (0,-2) -| cycle;
Does the following: It constructs the following path: It fills the arc at the top of the bottle, so we moved from point (-3,0)
to the point (0,0)
. Now, we are going from the last point two cm down, but we want TikZ to calculate that point, so we write … (x_1,y_1) --+ (0,-2)
, which gives us the coordinate (x_1,y_1 + (-2)) = (x_1,y_1-2)
. Now we have got three points, and want to cycle the path. The option -|
gives us the y
coordinate from the point (x_1,y_1 + (-2)) = (x_1,y_1-2)
and the x
coordinate of the point (0,0)
. The word cycle
means that we draw our path to the initial point.
P.S.: {1.5cm-0.4pt} (from the circle): in curly braces we let TikZ calculate the difference; 4pt
is the thickness of the line of the bottle.
EDIT:
A little bit better solution:
\documentclass[border=5pt,tikz]{standalone}
\begin{document}
\begin{tikzpicture}[xscale=1,yscale=1]
\clip (0,-2.5) --+ (0,2.5) arc (0:180:1.5) -- (-3,-2.5) arc (180:235:3) --+ (0,-.25) --+ (.45,-.25) --+ (.45,.015) (0,-2.5) arc (0:-55:3);
\fill[blue!20] (-3,-5.5) rectangle ++(3,3.5);
\fill[blue!10] (-1.5,-2) circle ({1.5cm-0.4pt} and 0.5cm);
\draw[very thick] (0,-2.5) --+ (0,2.5) arc (0:180:1.5) -- (-3,-2.5) arc (180:235:3) --+ (0,-.25) --+ (.45,-.25) --+ (.45,.015) (0,-2.5) arc (0:-55:3);
\end{tikzpicture}
\end{document}
Explanation:
We can just "clip" the bottle: everything, what we draw, is now in the area of the bottle. Everything outside that area is invisible. So we just clip the bottle and fill a rectangle, such it fills a certain area of the bottle.
Output:
EDIT:
For Sebastiano:
\documentclass[border=5pt,tikz]{standalone}
\usetikzlibrary{decorations.text,backgrounds}
\definecolor{wine}{RGB}{216,198,62}
\definecolor{bottle}{RGB}{76,163,58}
\tikzset{
my/.style={
postaction={decorate},decoration={text along path,
text={#1},text align=center}
}
}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip (0,-2.5) --+ (0,2.5) arc (0:180:1.5) -- (-3,-2.5) arc (180:235:3) --+ (0,-.25) --+ (.45,-.25) --+ (.45,.015) (0,-2.5) arc (0:-55:3);
\fill[inner color=bottle!50,outer color=bottle] (0,-2.5) --+ (0,2.5) arc (0:180:1.5) -- (-3,-2.5) arc (180:235:3) --+ (0,-.25) --+ (.45,-.25) --+ (.45,.015) (0,-2.5) arc (0:-55:3);
\fill[wine!60] (-3,-5.5) rectangle ++(3,3.5);
\fill[wine!40] (-1.5,-2) circle ({1.5cm-0.4pt} and 0.5cm);
\foreach \x in {-5,-4.9,...,5}
\foreach \y in {-5,...,-3}
{
\pgfmathsetmacro\opacity{random(1,10)*(1/10)}
\pgfmathsetmacro\radius{random(1,2)*(.05/2)}
\fill[white,opacity=\opacity] (\x+1.3*rnd,\y+1.4*rnd) circle(\radius);
}
\draw[very thick] (0,-2.5) --+ (0,2.5) arc (0:180:1.5) -- (-3,-2.5) arc (180:235:3) --+ (0,-.25) --+ (.45,-.25) --+ (.45,.015) (0,-2.5) arc (0:-55:3);
\path[my={The magic of Ti{\emph{\color{orange}k}}Z}] (-3.5,.5) arc(-180:0:2 and 1);
\end{scope}
\end{tikzpicture}
\end{document}
Output:
This looks like a code golfing challenge ;)
\documentclass[tikz,border=7pt]{standalone}
\usetikzlibrary{svg.path}
\begin{document}
\begin{tikzpicture}[scale=3]
\draw svg{M6 0V8A6 6 0 0 1-6 8V0};
\draw[fill=blue!20] svg{M6 0c0-9-3-11-5-13v-1h-2v1c-2 2-5 4-5 13};
\end{tikzpicture}
\end{document}