Let's take the flag of Germany as an example, because the flag is way quite simple and its waving state can be easily drawn "manually". But I am asking about general flag (the flag of any country/group, even the flag of my team).
Normal flag (1)
\documentclass[tikz]{standalone}
\usepackage{xcolor}
\definecolor{gerbla}{RGB}{0,0,0}
\definecolor{gerred}{RGB}{255,0,0}
\definecolor{geryel}{RGB}{255,204,0}
\begin{document}
\begin{tikzpicture}
\fill[gerbla] (0,2) rectangle (5,3);
\fill[gerred] (0,1) rectangle (5,2);
\fill[geryel] (0,0) rectangle (5,1);
\end{tikzpicture}
\end{document}
Waving flag (2) (the ratio may not be true)
\documentclass[tikz]{standalone}
\usepackage{xcolor}
\definecolor{gerbla}{RGB}{0,0,0}
\definecolor{gerred}{RGB}{255,0,0}
\definecolor{geryel}{RGB}{255,204,0}
\begin{document}
\begin{tikzpicture}
\fill[gerbla] (0,3) to[out=0,in=180] (4,2) -- (4,1) to[out=180,in=0] (0,2) -- cycle;
\fill[gerred] (0,2) to[out=0,in=180] (4,1) -- (4,0) to[out=180,in=0] (0,1) -- cycle;
\fill[geryel] (0,1) to[out=0,in=180] (4,0) -- (4,-1) to[out=180,in=0] (0,0) -- cycle;
\end{tikzpicture}
\end{document}
Advanced waving flag (3)
(unTikZified – image taken from Emojipedia)
Question
How to draw a waving flag? In other word, say I already have a rectangle-shape flag (1), with many patterns and items on it (even with some \includegraphics
), how can I "wave" (1) to get (2), where
- The ratio length/width is still correct.
- The images, patterns, etc. on the flag are waved too, and these items still fit correctly with the overall flag.
Bonus question
If I already have (1) or (2), how can I get shadow effects and light effects like (3)?
The code for the flag of the United States, as requested by @marmot:
\documentclass[tikz]{standalone}
\usetikzlibrary{shapes}
\usepackage{xcolor}
\begin{document}
\begin{tikzpicture}
\definecolor{usblue}{rgb}{.234,.233,.430}
\definecolor{usared}{rgb}{.698,.132,.203}
\fill[usared] (0,0) rectangle (1.9,1);
\foreach \i in {1,3,...,11}
\fill[white] (0,\i/13) rectangle (1.9,{(\i+1)/13});
\fill [usblue] (0,6/13) rectangle ({1.9*2/5},1);
\foreach \i in {1,2,3,4,5,6} {
\foreach \j in {1,2,3,4,5} {
\node[star,star points=5,star point ratio=2.25,fill=white,minimum size=0.0616cm,inner sep=0pt] at ({(1.9/15)*\i-(1.9/30)},{6/13+(7/130)+(7*(\j-1)/65)}) {};
}
}
\foreach \i in {1,2,3,4,5} {
\foreach \j in {1,2,3,4} {
\node[star,star points=5,star point ratio=2.25,fill=white,minimum size=0.0616cm,inner sep=0pt] at ({(1.9/15)*\i},{6/13+(7*\j/65)}) {};
}
}
\end{tikzpicture}
\end{document}
Best Answer
You can use nonlinear transformations to achieve this effect.
Of course, this works with any flag you have the TikZ code for, including of course your nice US flag.
And here is something for Black Mild.
This answer has the codes for many flags, out of which I picked Iceland. (Note that if the flag contains shapes, you need to say
transform shape nonlinear=true
.) The shading can be added on top.In order to draw a 3d flag, you may use
tikz-3dplot
. With\shade
you can get something like this.