# Draw half part of the cylinder surface with one color and other half with another color

This code gives the cylinder but I would like half of the part of the cylindrical surface is of one color and another half with another color(half with respect to the top not middle, means when we cut the top circular cross section into half).

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0,0) ellipse (1.25 and 0.5);
\draw (-1.25,0) -- (-1.25,-3.5);
\draw (-1.25,-3.5) arc (180:360:1.25 and 0.5);
\draw [dashed] (-1.25,-3.5) arc (180:360:1.25 and -0.5);
\draw (1.25,-3.5) -- (1.25,0);
\fill [gray,opacity=0.5] (-1.25,0) -- (-1.25,-3.5) arc (180:360:1.25 and 0.5) -- (1.25,0) arc (0:180:1.25 and -0.5);
\end{tikzpicture}
\end{document}


How can we achieve it?

## 1 Answer

Do you mean something like this?

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0,0) ellipse (1.25 and 0.5);
\draw (-1.25,0) -- (-1.25,-3.5);
\draw (-1.25,-3.5) arc (180:360:1.25 and 0.5);
\draw [dashed] (-1.25,-3.5) arc (180:360:1.25 and -0.5);
\draw (1.25,-3.5) -- (1.25,0);
%
\fill [left color = blue, right color = red, opacity=0.5] (-1.25,0) -- (-1.25,-3.5) arc (180:360:1.25 and 0.5) -- (1.25,0) arc (0:180:1.25 and -0.5);
\end{tikzpicture}
\end{document}


If you still want a sharp transition you can replace the fill path with

\fill [opacity=0.5, color = blue] (-1.25,0) -- (-1.25,-3.5) arc
(180:270:1.25 and 0.5) -- (0,-0.5) node[midway, left, color =
black]{blue} arc(270:180:1.25 and 0.5) ;

\fill [opacity=0.5, color = red] (1.25,0) -- (1.25,-3.5) arc
(0:-90:1.25 and 0.5) -- (0,-0.5) node[midway, right, color =
black]{red} arc(270:360:1.25 and 0.5);


• Thanks, indeed the second one. Is there a way to write on the cylinder? – Shamina May 3 '18 at 2:03
• @Shamina Yes, I just updated my answer – caverac May 3 '18 at 2:35