How to draw a waving flag in TikZTikZ and FIFA WorldCup 2018: Flags of Nationstransform shape nonlinear=true vs. accessing coordinatesTikZ: Cropping the Bounding BoxRotate a node but not its content: the case of the ellipse decorationNational flag using TikZHow to define the default vertical distance between nodes?Drawing a flag in Tikz!TikZ: Drawing an arc from an intersection to an intersectionHow to prevent rounded and duplicated tick labels in pgfplots with fixed precision?Esperanto flag in Tikz?Algerian flag in TikzLine up nested tikz enviroments or how to get rid of them

Is it tax fraud for an individual to declare non-taxable revenue as taxable income? (US tax laws)

Why can't we play rap on piano?

Is it unprofessional to ask if a job posting on GlassDoor is real?

Replacing matching entries in one column of a file by another column from a different file

Which country benefited the most from UN Security Council vetoes?

What does "Puller Prush Person" mean?

Definite integral giving negative value as a result?

Why is Minecraft giving an OpenGL error?

When a company launches a new product do they "come out" with a new product or do they "come up" with a new product?

How does quantile regression compare to logistic regression with the variable split at the quantile?

Why are electrically insulating heatsinks so rare? Is it just cost?

Convert two switches to a dual stack, and add outlet - possible here?

What's that red-plus icon near a text?

Modeling an IP Address

How can I prevent hyper evolved versions of regular creatures from wiping out their cousins?

Is it possible to do 50 km distance without any previous training?

Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)

Can I make popcorn with any corn?

What is the word for reserving something for yourself before others do?

Is it possible to run Internet Explorer on OS X El Capitan?

How to format long polynomial?

What typically incentivizes a professor to change jobs to a lower ranking university?

Find the result of this dual key cipher

Intersection point of 2 lines defined by 2 points each



How to draw a waving flag in TikZ


TikZ and FIFA WorldCup 2018: Flags of Nationstransform shape nonlinear=true vs. accessing coordinatesTikZ: Cropping the Bounding BoxRotate a node but not its content: the case of the ellipse decorationNational flag using TikZHow to define the default vertical distance between nodes?Drawing a flag in Tikz!TikZ: Drawing an arc from an intersection to an intersectionHow to prevent rounded and duplicated tick labels in pgfplots with fixed precision?Esperanto flag in Tikz?Algerian flag in TikzLine up nested tikz enviroments or how to get rid of them













5















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
usepackagexcolor
definecolorgerblaRGB0,0,0
definecolorgerredRGB255,0,0
definecolorgeryelRGB255,204,0
begindocument
begintikzpicture
fill[gerbla] (0,2) rectangle (5,3);
fill[gerred] (0,1) rectangle (5,2);
fill[geryel] (0,0) rectangle (5,1);
endtikzpicture
enddocument


enter image description here



Waving flag (2) (the ratio may not be true)



documentclass[tikz]standalone
usepackagexcolor
definecolorgerblaRGB0,0,0
definecolorgerredRGB255,0,0
definecolorgeryelRGB255,204,0
begindocument
begintikzpicture
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;
endtikzpicture
enddocument


enter image description here



Advanced waving flag (3)



enter image description here



(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



  1. The ratio length/width is still correct.

  2. 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
usetikzlibraryshapes
usepackagexcolor
begindocument
begintikzpicture
definecolorusbluergb.234,.233,.430
definecolorusaredrgb.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)) ;


endtikzpicture
enddocument


enter image description here










share|improve this question




























    5















    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
    usepackagexcolor
    definecolorgerblaRGB0,0,0
    definecolorgerredRGB255,0,0
    definecolorgeryelRGB255,204,0
    begindocument
    begintikzpicture
    fill[gerbla] (0,2) rectangle (5,3);
    fill[gerred] (0,1) rectangle (5,2);
    fill[geryel] (0,0) rectangle (5,1);
    endtikzpicture
    enddocument


    enter image description here



    Waving flag (2) (the ratio may not be true)



    documentclass[tikz]standalone
    usepackagexcolor
    definecolorgerblaRGB0,0,0
    definecolorgerredRGB255,0,0
    definecolorgeryelRGB255,204,0
    begindocument
    begintikzpicture
    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;
    endtikzpicture
    enddocument


    enter image description here



    Advanced waving flag (3)



    enter image description here



    (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



    1. The ratio length/width is still correct.

    2. 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
    usetikzlibraryshapes
    usepackagexcolor
    begindocument
    begintikzpicture
    definecolorusbluergb.234,.233,.430
    definecolorusaredrgb.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)) ;


    endtikzpicture
    enddocument


    enter image description here










    share|improve this question


























      5












      5








      5


      1






      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
      usepackagexcolor
      definecolorgerblaRGB0,0,0
      definecolorgerredRGB255,0,0
      definecolorgeryelRGB255,204,0
      begindocument
      begintikzpicture
      fill[gerbla] (0,2) rectangle (5,3);
      fill[gerred] (0,1) rectangle (5,2);
      fill[geryel] (0,0) rectangle (5,1);
      endtikzpicture
      enddocument


      enter image description here



      Waving flag (2) (the ratio may not be true)



      documentclass[tikz]standalone
      usepackagexcolor
      definecolorgerblaRGB0,0,0
      definecolorgerredRGB255,0,0
      definecolorgeryelRGB255,204,0
      begindocument
      begintikzpicture
      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;
      endtikzpicture
      enddocument


      enter image description here



      Advanced waving flag (3)



      enter image description here



      (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



      1. The ratio length/width is still correct.

      2. 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
      usetikzlibraryshapes
      usepackagexcolor
      begindocument
      begintikzpicture
      definecolorusbluergb.234,.233,.430
      definecolorusaredrgb.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)) ;


      endtikzpicture
      enddocument


      enter image description here










      share|improve this question
















      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
      usepackagexcolor
      definecolorgerblaRGB0,0,0
      definecolorgerredRGB255,0,0
      definecolorgeryelRGB255,204,0
      begindocument
      begintikzpicture
      fill[gerbla] (0,2) rectangle (5,3);
      fill[gerred] (0,1) rectangle (5,2);
      fill[geryel] (0,0) rectangle (5,1);
      endtikzpicture
      enddocument


      enter image description here



      Waving flag (2) (the ratio may not be true)



      documentclass[tikz]standalone
      usepackagexcolor
      definecolorgerblaRGB0,0,0
      definecolorgerredRGB255,0,0
      definecolorgeryelRGB255,204,0
      begindocument
      begintikzpicture
      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;
      endtikzpicture
      enddocument


      enter image description here



      Advanced waving flag (3)



      enter image description here



      (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



      1. The ratio length/width is still correct.

      2. 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
      usetikzlibraryshapes
      usepackagexcolor
      begindocument
      begintikzpicture
      definecolorusbluergb.234,.233,.430
      definecolorusaredrgb.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)) ;


      endtikzpicture
      enddocument


      enter image description here







      tikz-pgf






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 1 hour ago







      JouleV

















      asked 2 hours ago









      JouleVJouleV

      10.9k22560




      10.9k22560




















          1 Answer
          1






          active

          oldest

          votes


















          7














          You can use nonlinear transformations to achieve this effect.



          documentclass[tikz,border=3.14mm]standalone
          usepgfmodulenonlineartransformations
          definecolorgerblaRGB0,0,0
          definecolorgerredRGB255,0,0
          definecolorgeryelRGB255,204,0
          makeatletter
          defflagtransformation%
          pgf@xa=pgf@x%
          pgf@ya=pgf@y%
          %typeoutoldspace x=pgf@xaspace old space y=pgf@ya%
          pgfmathsetmacromyypgf@ya+7*sin(pgf@xa*3.6)-0.1*pgf@xa%
          %typeoutatspace x=thepgf@xa:space newspace y=myy%
          pgf@y=myy pt
          makeatother
          newcommandGermanFlag%
          fill[gerbla] (0,2) rectangle (4,3);
          fill[gerred] (0,1) rectangle (4,2);
          fill[geryel] (0,0) rectangle (4,1);
          begindocument
          begintikzpicture[font=sffamily,scale=1]
          beginscope[local bounding box=linear]
          GermanFlag
          endscope
          node[anchor=south] (lin) at (linear.north)linear;
          beginscope[xshift=5cm,local bounding box=nonlinear,transform shape
          nonlinear=true]
          pgftransformnonlinearflagtransformation
          GermanFlag
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0,0) rectangle (2,3);
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (2,0) rectangle (4,3);
          endscope
          node[anchor=south] at (lin.south-|nonlinear.north)nonlinear;
          endtikzpicture
          enddocument


          enter image description here



          Of course, this works with any flag you have the TikZ code for, including of course your nice US flag.



          documentclass[tikz,border=3.14mm]standalone
          usetikzlibraryshapes
          usepgfmodulenonlineartransformations
          definecolorusbluergb.234,.233,.430
          definecolorusaredrgb.698,.132,.203
          makeatletter
          defflagtransformation%
          pgf@xa=pgf@x%
          pgf@ya=pgf@y%
          %typeoutoldspace x=pgf@xaspace old space y=pgf@ya%
          pgfmathsetmacromyypgf@ya+7*sin(pgf@xa*3.6)-0.1*pgf@xa%
          %typeoutatspace x=thepgf@xa:space newspace y=myy%
          pgf@y=myy pt
          makeatother
          newcommandUSFlag%
          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)) ;


          begindocument
          begintikzpicture[font=sffamily,scale=2,transform shape]
          beginscope[local bounding box=linear]
          USFlag
          endscope
          node[anchor=south] (lin) at (linear.north)linear;
          beginscope[xshift=2.5cm,local bounding box=nonlinear,transform shape
          nonlinear=true]
          pgftransformnonlinearflagtransformation
          USFlag
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0,0) rectangle (0.95,1);
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0.95,0) rectangle (1.9,1);
          endscope
          node[anchor=south] at (lin.south-|nonlinear.north)nonlinear;
          endtikzpicture
          enddocument


          enter image description here



          And here is something for Black Mild.



          documentclass[tikz,border=3.14mm]standalone
          usetikzlibraryshapes
          usepgfmodulenonlineartransformations
          definecolorusbluergb.234,.233,.430
          definecolorusaredrgb.698,.132,.203
          makeatletter
          defflagtransformation%
          pgf@xa=pgf@x%
          pgf@ya=pgf@y%
          %typeoutoldspace x=pgf@xaspace old space y=pgf@ya%
          pgfmathsetmacromyypgf@ya+7*sin(pgf@xa*3.6)-0.1*pgf@xa%
          %typeoutatspace x=thepgf@xa:space newspace y=myy%
          pgf@y=myy pt
          tikzdeclarecoordinatesystemflag% https://tex.stackexchange.com/a/434247/121799
          tikz@scan@one@pointrelax(#1)
          flagtransformation

          makeatother
          newcommandUSFlag%
          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)) ;


          begindocument
          foreach X in 0,5,...,95
          begintikzpicture[font=sffamily,scale=2,transform shape]
          beginscope[xshift=X pt,
          local bounding box=nonlinear,transform shape
          nonlinear=true]
          pgftransformnonlinearflagtransformation
          USFlag
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0,0) rectangle (0.95,1);
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0.95,0) rectangle (1.9,1);
          shade[left color=gray,right color=gray!70,middle color=gray!20]
          (0,1.05) rectangle ++ (-0.1,-3);
          endscope
          endtikzpicture
          enddocument


          enter image description here



          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.



          documentclass[tikz,border=3.14mm]standalone
          usepgfmodulenonlineartransformations
          makeatletter
          defflagtransformation%
          pgf@xa=pgf@x%
          pgf@ya=pgf@y%
          %typeoutoldspace x=pgf@xaspace old space y=pgf@ya%
          pgfmathsetmacromyypgf@ya+7*sin(pgf@xa*3.6)-0.1*pgf@xa%
          %typeoutatspace x=thepgf@xa:space newspace y=myy%
          pgf@y=myy pt
          makeatother
          definecolorSkyBluergb0.00784314,0.32156864,0.61176473
          definecolorFireRedrgb0.86274511,0.11764706,0.20784314
          newcommandIcelandFlag
          fill[SkyBlue] (0,0) rectangle (25,18);
          fill[white] (7,0) rectangle (11,18);
          fill[white] (0,7) rectangle (25,11);
          fill[FireRed] (8,0) rectangle (10,18);
          fill[FireRed] (0,8) rectangle (25,10);
          begindocument
          begintikzpicture[font=sffamily,scale=0.15]
          beginscope[local bounding box=linear]
          IcelandFlag
          endscope
          node[anchor=south] (lin) at (linear.north)linear;
          beginscope[xshift=35cm,local bounding box=nonlinear]
          pgftransformnonlinearflagtransformation
          IcelandFlag
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0,0) rectangle (12.5,18);
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (12.5,0) rectangle (25,18);
          endscope
          node[anchor=south] at (lin.south-|nonlinear.north)nonlinear;
          endtikzpicture
          enddocument


          enter image description here



          In order to draw a 3d flag, you may use tikz-3dplot.
          With shade you can get something like this.



          documentclass[tikz]standalone
          usepackagetikz-3dplot
          definecolorgerblaRGB0,0,0
          definecolorgerredRGB255,0,0
          definecolorgeryelRGB255,204,0
          begindocument
          tdplotsetmaincoords7020
          begintikzpicture[tdplot_main_coords]
          % draw[-stealth] (0,0,0) -- (2,0,0) node[pos=1.1]$x$;
          % draw[-stealth] (0,0,0) -- (0,2,0) node[pos=1.1]$y$;
          foreach X [count=Y] in gerbla,gerred,geryel
          shade[left color=X,right color=X!70!black,middle color=X!70!white]
          plot[variable=x,domain=0:2] (x,0.2*sin(x*90),4-Y)
          --
          plot[variable=x,domain=2:0] (x,0.2*sin(x*90),3-Y);
          shade[left color=X!70!black,right color=X,middle color=X!70!white]
          plot[variable=x,domain=2:4] (x,0.2*sin(x*90),4-Y)
          --
          plot[variable=x,domain=4:2] (x,0.2*sin(x*90),3-Y);
          endtikzpicture
          enddocument


          enter image description here






          share|improve this answer

























          • I'm afraid this only answers the bonus question, for flags of Germany, Netherlands, etc. only. How can it deal with, for example, the US flag?

            – JouleV
            2 hours ago











          • @JouleV I switched gears completely and used nonlinear transformations. That way you can wave any flag you have the TikZ code for.

            – marmot
            1 hour ago






          • 1





            @JouleV It does work if you set transform shape nonlinear=true.

            – marmot
            1 hour ago






          • 1





            @marmot One word: perfect! Thanks you very much!!!!!

            – JouleV
            56 mins ago






          • 1





            @JouleV OK OK, I give in. Now it is attached to some post. ;-)

            – marmot
            18 mins ago












          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "85"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f483459%2fhow-to-draw-a-waving-flag-in-tikz%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          7














          You can use nonlinear transformations to achieve this effect.



          documentclass[tikz,border=3.14mm]standalone
          usepgfmodulenonlineartransformations
          definecolorgerblaRGB0,0,0
          definecolorgerredRGB255,0,0
          definecolorgeryelRGB255,204,0
          makeatletter
          defflagtransformation%
          pgf@xa=pgf@x%
          pgf@ya=pgf@y%
          %typeoutoldspace x=pgf@xaspace old space y=pgf@ya%
          pgfmathsetmacromyypgf@ya+7*sin(pgf@xa*3.6)-0.1*pgf@xa%
          %typeoutatspace x=thepgf@xa:space newspace y=myy%
          pgf@y=myy pt
          makeatother
          newcommandGermanFlag%
          fill[gerbla] (0,2) rectangle (4,3);
          fill[gerred] (0,1) rectangle (4,2);
          fill[geryel] (0,0) rectangle (4,1);
          begindocument
          begintikzpicture[font=sffamily,scale=1]
          beginscope[local bounding box=linear]
          GermanFlag
          endscope
          node[anchor=south] (lin) at (linear.north)linear;
          beginscope[xshift=5cm,local bounding box=nonlinear,transform shape
          nonlinear=true]
          pgftransformnonlinearflagtransformation
          GermanFlag
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0,0) rectangle (2,3);
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (2,0) rectangle (4,3);
          endscope
          node[anchor=south] at (lin.south-|nonlinear.north)nonlinear;
          endtikzpicture
          enddocument


          enter image description here



          Of course, this works with any flag you have the TikZ code for, including of course your nice US flag.



          documentclass[tikz,border=3.14mm]standalone
          usetikzlibraryshapes
          usepgfmodulenonlineartransformations
          definecolorusbluergb.234,.233,.430
          definecolorusaredrgb.698,.132,.203
          makeatletter
          defflagtransformation%
          pgf@xa=pgf@x%
          pgf@ya=pgf@y%
          %typeoutoldspace x=pgf@xaspace old space y=pgf@ya%
          pgfmathsetmacromyypgf@ya+7*sin(pgf@xa*3.6)-0.1*pgf@xa%
          %typeoutatspace x=thepgf@xa:space newspace y=myy%
          pgf@y=myy pt
          makeatother
          newcommandUSFlag%
          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)) ;


          begindocument
          begintikzpicture[font=sffamily,scale=2,transform shape]
          beginscope[local bounding box=linear]
          USFlag
          endscope
          node[anchor=south] (lin) at (linear.north)linear;
          beginscope[xshift=2.5cm,local bounding box=nonlinear,transform shape
          nonlinear=true]
          pgftransformnonlinearflagtransformation
          USFlag
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0,0) rectangle (0.95,1);
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0.95,0) rectangle (1.9,1);
          endscope
          node[anchor=south] at (lin.south-|nonlinear.north)nonlinear;
          endtikzpicture
          enddocument


          enter image description here



          And here is something for Black Mild.



          documentclass[tikz,border=3.14mm]standalone
          usetikzlibraryshapes
          usepgfmodulenonlineartransformations
          definecolorusbluergb.234,.233,.430
          definecolorusaredrgb.698,.132,.203
          makeatletter
          defflagtransformation%
          pgf@xa=pgf@x%
          pgf@ya=pgf@y%
          %typeoutoldspace x=pgf@xaspace old space y=pgf@ya%
          pgfmathsetmacromyypgf@ya+7*sin(pgf@xa*3.6)-0.1*pgf@xa%
          %typeoutatspace x=thepgf@xa:space newspace y=myy%
          pgf@y=myy pt
          tikzdeclarecoordinatesystemflag% https://tex.stackexchange.com/a/434247/121799
          tikz@scan@one@pointrelax(#1)
          flagtransformation

          makeatother
          newcommandUSFlag%
          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)) ;


          begindocument
          foreach X in 0,5,...,95
          begintikzpicture[font=sffamily,scale=2,transform shape]
          beginscope[xshift=X pt,
          local bounding box=nonlinear,transform shape
          nonlinear=true]
          pgftransformnonlinearflagtransformation
          USFlag
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0,0) rectangle (0.95,1);
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0.95,0) rectangle (1.9,1);
          shade[left color=gray,right color=gray!70,middle color=gray!20]
          (0,1.05) rectangle ++ (-0.1,-3);
          endscope
          endtikzpicture
          enddocument


          enter image description here



          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.



          documentclass[tikz,border=3.14mm]standalone
          usepgfmodulenonlineartransformations
          makeatletter
          defflagtransformation%
          pgf@xa=pgf@x%
          pgf@ya=pgf@y%
          %typeoutoldspace x=pgf@xaspace old space y=pgf@ya%
          pgfmathsetmacromyypgf@ya+7*sin(pgf@xa*3.6)-0.1*pgf@xa%
          %typeoutatspace x=thepgf@xa:space newspace y=myy%
          pgf@y=myy pt
          makeatother
          definecolorSkyBluergb0.00784314,0.32156864,0.61176473
          definecolorFireRedrgb0.86274511,0.11764706,0.20784314
          newcommandIcelandFlag
          fill[SkyBlue] (0,0) rectangle (25,18);
          fill[white] (7,0) rectangle (11,18);
          fill[white] (0,7) rectangle (25,11);
          fill[FireRed] (8,0) rectangle (10,18);
          fill[FireRed] (0,8) rectangle (25,10);
          begindocument
          begintikzpicture[font=sffamily,scale=0.15]
          beginscope[local bounding box=linear]
          IcelandFlag
          endscope
          node[anchor=south] (lin) at (linear.north)linear;
          beginscope[xshift=35cm,local bounding box=nonlinear]
          pgftransformnonlinearflagtransformation
          IcelandFlag
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0,0) rectangle (12.5,18);
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (12.5,0) rectangle (25,18);
          endscope
          node[anchor=south] at (lin.south-|nonlinear.north)nonlinear;
          endtikzpicture
          enddocument


          enter image description here



          In order to draw a 3d flag, you may use tikz-3dplot.
          With shade you can get something like this.



          documentclass[tikz]standalone
          usepackagetikz-3dplot
          definecolorgerblaRGB0,0,0
          definecolorgerredRGB255,0,0
          definecolorgeryelRGB255,204,0
          begindocument
          tdplotsetmaincoords7020
          begintikzpicture[tdplot_main_coords]
          % draw[-stealth] (0,0,0) -- (2,0,0) node[pos=1.1]$x$;
          % draw[-stealth] (0,0,0) -- (0,2,0) node[pos=1.1]$y$;
          foreach X [count=Y] in gerbla,gerred,geryel
          shade[left color=X,right color=X!70!black,middle color=X!70!white]
          plot[variable=x,domain=0:2] (x,0.2*sin(x*90),4-Y)
          --
          plot[variable=x,domain=2:0] (x,0.2*sin(x*90),3-Y);
          shade[left color=X!70!black,right color=X,middle color=X!70!white]
          plot[variable=x,domain=2:4] (x,0.2*sin(x*90),4-Y)
          --
          plot[variable=x,domain=4:2] (x,0.2*sin(x*90),3-Y);
          endtikzpicture
          enddocument


          enter image description here






          share|improve this answer

























          • I'm afraid this only answers the bonus question, for flags of Germany, Netherlands, etc. only. How can it deal with, for example, the US flag?

            – JouleV
            2 hours ago











          • @JouleV I switched gears completely and used nonlinear transformations. That way you can wave any flag you have the TikZ code for.

            – marmot
            1 hour ago






          • 1





            @JouleV It does work if you set transform shape nonlinear=true.

            – marmot
            1 hour ago






          • 1





            @marmot One word: perfect! Thanks you very much!!!!!

            – JouleV
            56 mins ago






          • 1





            @JouleV OK OK, I give in. Now it is attached to some post. ;-)

            – marmot
            18 mins ago
















          7














          You can use nonlinear transformations to achieve this effect.



          documentclass[tikz,border=3.14mm]standalone
          usepgfmodulenonlineartransformations
          definecolorgerblaRGB0,0,0
          definecolorgerredRGB255,0,0
          definecolorgeryelRGB255,204,0
          makeatletter
          defflagtransformation%
          pgf@xa=pgf@x%
          pgf@ya=pgf@y%
          %typeoutoldspace x=pgf@xaspace old space y=pgf@ya%
          pgfmathsetmacromyypgf@ya+7*sin(pgf@xa*3.6)-0.1*pgf@xa%
          %typeoutatspace x=thepgf@xa:space newspace y=myy%
          pgf@y=myy pt
          makeatother
          newcommandGermanFlag%
          fill[gerbla] (0,2) rectangle (4,3);
          fill[gerred] (0,1) rectangle (4,2);
          fill[geryel] (0,0) rectangle (4,1);
          begindocument
          begintikzpicture[font=sffamily,scale=1]
          beginscope[local bounding box=linear]
          GermanFlag
          endscope
          node[anchor=south] (lin) at (linear.north)linear;
          beginscope[xshift=5cm,local bounding box=nonlinear,transform shape
          nonlinear=true]
          pgftransformnonlinearflagtransformation
          GermanFlag
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0,0) rectangle (2,3);
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (2,0) rectangle (4,3);
          endscope
          node[anchor=south] at (lin.south-|nonlinear.north)nonlinear;
          endtikzpicture
          enddocument


          enter image description here



          Of course, this works with any flag you have the TikZ code for, including of course your nice US flag.



          documentclass[tikz,border=3.14mm]standalone
          usetikzlibraryshapes
          usepgfmodulenonlineartransformations
          definecolorusbluergb.234,.233,.430
          definecolorusaredrgb.698,.132,.203
          makeatletter
          defflagtransformation%
          pgf@xa=pgf@x%
          pgf@ya=pgf@y%
          %typeoutoldspace x=pgf@xaspace old space y=pgf@ya%
          pgfmathsetmacromyypgf@ya+7*sin(pgf@xa*3.6)-0.1*pgf@xa%
          %typeoutatspace x=thepgf@xa:space newspace y=myy%
          pgf@y=myy pt
          makeatother
          newcommandUSFlag%
          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)) ;


          begindocument
          begintikzpicture[font=sffamily,scale=2,transform shape]
          beginscope[local bounding box=linear]
          USFlag
          endscope
          node[anchor=south] (lin) at (linear.north)linear;
          beginscope[xshift=2.5cm,local bounding box=nonlinear,transform shape
          nonlinear=true]
          pgftransformnonlinearflagtransformation
          USFlag
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0,0) rectangle (0.95,1);
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0.95,0) rectangle (1.9,1);
          endscope
          node[anchor=south] at (lin.south-|nonlinear.north)nonlinear;
          endtikzpicture
          enddocument


          enter image description here



          And here is something for Black Mild.



          documentclass[tikz,border=3.14mm]standalone
          usetikzlibraryshapes
          usepgfmodulenonlineartransformations
          definecolorusbluergb.234,.233,.430
          definecolorusaredrgb.698,.132,.203
          makeatletter
          defflagtransformation%
          pgf@xa=pgf@x%
          pgf@ya=pgf@y%
          %typeoutoldspace x=pgf@xaspace old space y=pgf@ya%
          pgfmathsetmacromyypgf@ya+7*sin(pgf@xa*3.6)-0.1*pgf@xa%
          %typeoutatspace x=thepgf@xa:space newspace y=myy%
          pgf@y=myy pt
          tikzdeclarecoordinatesystemflag% https://tex.stackexchange.com/a/434247/121799
          tikz@scan@one@pointrelax(#1)
          flagtransformation

          makeatother
          newcommandUSFlag%
          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)) ;


          begindocument
          foreach X in 0,5,...,95
          begintikzpicture[font=sffamily,scale=2,transform shape]
          beginscope[xshift=X pt,
          local bounding box=nonlinear,transform shape
          nonlinear=true]
          pgftransformnonlinearflagtransformation
          USFlag
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0,0) rectangle (0.95,1);
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0.95,0) rectangle (1.9,1);
          shade[left color=gray,right color=gray!70,middle color=gray!20]
          (0,1.05) rectangle ++ (-0.1,-3);
          endscope
          endtikzpicture
          enddocument


          enter image description here



          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.



          documentclass[tikz,border=3.14mm]standalone
          usepgfmodulenonlineartransformations
          makeatletter
          defflagtransformation%
          pgf@xa=pgf@x%
          pgf@ya=pgf@y%
          %typeoutoldspace x=pgf@xaspace old space y=pgf@ya%
          pgfmathsetmacromyypgf@ya+7*sin(pgf@xa*3.6)-0.1*pgf@xa%
          %typeoutatspace x=thepgf@xa:space newspace y=myy%
          pgf@y=myy pt
          makeatother
          definecolorSkyBluergb0.00784314,0.32156864,0.61176473
          definecolorFireRedrgb0.86274511,0.11764706,0.20784314
          newcommandIcelandFlag
          fill[SkyBlue] (0,0) rectangle (25,18);
          fill[white] (7,0) rectangle (11,18);
          fill[white] (0,7) rectangle (25,11);
          fill[FireRed] (8,0) rectangle (10,18);
          fill[FireRed] (0,8) rectangle (25,10);
          begindocument
          begintikzpicture[font=sffamily,scale=0.15]
          beginscope[local bounding box=linear]
          IcelandFlag
          endscope
          node[anchor=south] (lin) at (linear.north)linear;
          beginscope[xshift=35cm,local bounding box=nonlinear]
          pgftransformnonlinearflagtransformation
          IcelandFlag
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0,0) rectangle (12.5,18);
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (12.5,0) rectangle (25,18);
          endscope
          node[anchor=south] at (lin.south-|nonlinear.north)nonlinear;
          endtikzpicture
          enddocument


          enter image description here



          In order to draw a 3d flag, you may use tikz-3dplot.
          With shade you can get something like this.



          documentclass[tikz]standalone
          usepackagetikz-3dplot
          definecolorgerblaRGB0,0,0
          definecolorgerredRGB255,0,0
          definecolorgeryelRGB255,204,0
          begindocument
          tdplotsetmaincoords7020
          begintikzpicture[tdplot_main_coords]
          % draw[-stealth] (0,0,0) -- (2,0,0) node[pos=1.1]$x$;
          % draw[-stealth] (0,0,0) -- (0,2,0) node[pos=1.1]$y$;
          foreach X [count=Y] in gerbla,gerred,geryel
          shade[left color=X,right color=X!70!black,middle color=X!70!white]
          plot[variable=x,domain=0:2] (x,0.2*sin(x*90),4-Y)
          --
          plot[variable=x,domain=2:0] (x,0.2*sin(x*90),3-Y);
          shade[left color=X!70!black,right color=X,middle color=X!70!white]
          plot[variable=x,domain=2:4] (x,0.2*sin(x*90),4-Y)
          --
          plot[variable=x,domain=4:2] (x,0.2*sin(x*90),3-Y);
          endtikzpicture
          enddocument


          enter image description here






          share|improve this answer

























          • I'm afraid this only answers the bonus question, for flags of Germany, Netherlands, etc. only. How can it deal with, for example, the US flag?

            – JouleV
            2 hours ago











          • @JouleV I switched gears completely and used nonlinear transformations. That way you can wave any flag you have the TikZ code for.

            – marmot
            1 hour ago






          • 1





            @JouleV It does work if you set transform shape nonlinear=true.

            – marmot
            1 hour ago






          • 1





            @marmot One word: perfect! Thanks you very much!!!!!

            – JouleV
            56 mins ago






          • 1





            @JouleV OK OK, I give in. Now it is attached to some post. ;-)

            – marmot
            18 mins ago














          7












          7








          7







          You can use nonlinear transformations to achieve this effect.



          documentclass[tikz,border=3.14mm]standalone
          usepgfmodulenonlineartransformations
          definecolorgerblaRGB0,0,0
          definecolorgerredRGB255,0,0
          definecolorgeryelRGB255,204,0
          makeatletter
          defflagtransformation%
          pgf@xa=pgf@x%
          pgf@ya=pgf@y%
          %typeoutoldspace x=pgf@xaspace old space y=pgf@ya%
          pgfmathsetmacromyypgf@ya+7*sin(pgf@xa*3.6)-0.1*pgf@xa%
          %typeoutatspace x=thepgf@xa:space newspace y=myy%
          pgf@y=myy pt
          makeatother
          newcommandGermanFlag%
          fill[gerbla] (0,2) rectangle (4,3);
          fill[gerred] (0,1) rectangle (4,2);
          fill[geryel] (0,0) rectangle (4,1);
          begindocument
          begintikzpicture[font=sffamily,scale=1]
          beginscope[local bounding box=linear]
          GermanFlag
          endscope
          node[anchor=south] (lin) at (linear.north)linear;
          beginscope[xshift=5cm,local bounding box=nonlinear,transform shape
          nonlinear=true]
          pgftransformnonlinearflagtransformation
          GermanFlag
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0,0) rectangle (2,3);
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (2,0) rectangle (4,3);
          endscope
          node[anchor=south] at (lin.south-|nonlinear.north)nonlinear;
          endtikzpicture
          enddocument


          enter image description here



          Of course, this works with any flag you have the TikZ code for, including of course your nice US flag.



          documentclass[tikz,border=3.14mm]standalone
          usetikzlibraryshapes
          usepgfmodulenonlineartransformations
          definecolorusbluergb.234,.233,.430
          definecolorusaredrgb.698,.132,.203
          makeatletter
          defflagtransformation%
          pgf@xa=pgf@x%
          pgf@ya=pgf@y%
          %typeoutoldspace x=pgf@xaspace old space y=pgf@ya%
          pgfmathsetmacromyypgf@ya+7*sin(pgf@xa*3.6)-0.1*pgf@xa%
          %typeoutatspace x=thepgf@xa:space newspace y=myy%
          pgf@y=myy pt
          makeatother
          newcommandUSFlag%
          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)) ;


          begindocument
          begintikzpicture[font=sffamily,scale=2,transform shape]
          beginscope[local bounding box=linear]
          USFlag
          endscope
          node[anchor=south] (lin) at (linear.north)linear;
          beginscope[xshift=2.5cm,local bounding box=nonlinear,transform shape
          nonlinear=true]
          pgftransformnonlinearflagtransformation
          USFlag
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0,0) rectangle (0.95,1);
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0.95,0) rectangle (1.9,1);
          endscope
          node[anchor=south] at (lin.south-|nonlinear.north)nonlinear;
          endtikzpicture
          enddocument


          enter image description here



          And here is something for Black Mild.



          documentclass[tikz,border=3.14mm]standalone
          usetikzlibraryshapes
          usepgfmodulenonlineartransformations
          definecolorusbluergb.234,.233,.430
          definecolorusaredrgb.698,.132,.203
          makeatletter
          defflagtransformation%
          pgf@xa=pgf@x%
          pgf@ya=pgf@y%
          %typeoutoldspace x=pgf@xaspace old space y=pgf@ya%
          pgfmathsetmacromyypgf@ya+7*sin(pgf@xa*3.6)-0.1*pgf@xa%
          %typeoutatspace x=thepgf@xa:space newspace y=myy%
          pgf@y=myy pt
          tikzdeclarecoordinatesystemflag% https://tex.stackexchange.com/a/434247/121799
          tikz@scan@one@pointrelax(#1)
          flagtransformation

          makeatother
          newcommandUSFlag%
          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)) ;


          begindocument
          foreach X in 0,5,...,95
          begintikzpicture[font=sffamily,scale=2,transform shape]
          beginscope[xshift=X pt,
          local bounding box=nonlinear,transform shape
          nonlinear=true]
          pgftransformnonlinearflagtransformation
          USFlag
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0,0) rectangle (0.95,1);
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0.95,0) rectangle (1.9,1);
          shade[left color=gray,right color=gray!70,middle color=gray!20]
          (0,1.05) rectangle ++ (-0.1,-3);
          endscope
          endtikzpicture
          enddocument


          enter image description here



          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.



          documentclass[tikz,border=3.14mm]standalone
          usepgfmodulenonlineartransformations
          makeatletter
          defflagtransformation%
          pgf@xa=pgf@x%
          pgf@ya=pgf@y%
          %typeoutoldspace x=pgf@xaspace old space y=pgf@ya%
          pgfmathsetmacromyypgf@ya+7*sin(pgf@xa*3.6)-0.1*pgf@xa%
          %typeoutatspace x=thepgf@xa:space newspace y=myy%
          pgf@y=myy pt
          makeatother
          definecolorSkyBluergb0.00784314,0.32156864,0.61176473
          definecolorFireRedrgb0.86274511,0.11764706,0.20784314
          newcommandIcelandFlag
          fill[SkyBlue] (0,0) rectangle (25,18);
          fill[white] (7,0) rectangle (11,18);
          fill[white] (0,7) rectangle (25,11);
          fill[FireRed] (8,0) rectangle (10,18);
          fill[FireRed] (0,8) rectangle (25,10);
          begindocument
          begintikzpicture[font=sffamily,scale=0.15]
          beginscope[local bounding box=linear]
          IcelandFlag
          endscope
          node[anchor=south] (lin) at (linear.north)linear;
          beginscope[xshift=35cm,local bounding box=nonlinear]
          pgftransformnonlinearflagtransformation
          IcelandFlag
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0,0) rectangle (12.5,18);
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (12.5,0) rectangle (25,18);
          endscope
          node[anchor=south] at (lin.south-|nonlinear.north)nonlinear;
          endtikzpicture
          enddocument


          enter image description here



          In order to draw a 3d flag, you may use tikz-3dplot.
          With shade you can get something like this.



          documentclass[tikz]standalone
          usepackagetikz-3dplot
          definecolorgerblaRGB0,0,0
          definecolorgerredRGB255,0,0
          definecolorgeryelRGB255,204,0
          begindocument
          tdplotsetmaincoords7020
          begintikzpicture[tdplot_main_coords]
          % draw[-stealth] (0,0,0) -- (2,0,0) node[pos=1.1]$x$;
          % draw[-stealth] (0,0,0) -- (0,2,0) node[pos=1.1]$y$;
          foreach X [count=Y] in gerbla,gerred,geryel
          shade[left color=X,right color=X!70!black,middle color=X!70!white]
          plot[variable=x,domain=0:2] (x,0.2*sin(x*90),4-Y)
          --
          plot[variable=x,domain=2:0] (x,0.2*sin(x*90),3-Y);
          shade[left color=X!70!black,right color=X,middle color=X!70!white]
          plot[variable=x,domain=2:4] (x,0.2*sin(x*90),4-Y)
          --
          plot[variable=x,domain=4:2] (x,0.2*sin(x*90),3-Y);
          endtikzpicture
          enddocument


          enter image description here






          share|improve this answer















          You can use nonlinear transformations to achieve this effect.



          documentclass[tikz,border=3.14mm]standalone
          usepgfmodulenonlineartransformations
          definecolorgerblaRGB0,0,0
          definecolorgerredRGB255,0,0
          definecolorgeryelRGB255,204,0
          makeatletter
          defflagtransformation%
          pgf@xa=pgf@x%
          pgf@ya=pgf@y%
          %typeoutoldspace x=pgf@xaspace old space y=pgf@ya%
          pgfmathsetmacromyypgf@ya+7*sin(pgf@xa*3.6)-0.1*pgf@xa%
          %typeoutatspace x=thepgf@xa:space newspace y=myy%
          pgf@y=myy pt
          makeatother
          newcommandGermanFlag%
          fill[gerbla] (0,2) rectangle (4,3);
          fill[gerred] (0,1) rectangle (4,2);
          fill[geryel] (0,0) rectangle (4,1);
          begindocument
          begintikzpicture[font=sffamily,scale=1]
          beginscope[local bounding box=linear]
          GermanFlag
          endscope
          node[anchor=south] (lin) at (linear.north)linear;
          beginscope[xshift=5cm,local bounding box=nonlinear,transform shape
          nonlinear=true]
          pgftransformnonlinearflagtransformation
          GermanFlag
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0,0) rectangle (2,3);
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (2,0) rectangle (4,3);
          endscope
          node[anchor=south] at (lin.south-|nonlinear.north)nonlinear;
          endtikzpicture
          enddocument


          enter image description here



          Of course, this works with any flag you have the TikZ code for, including of course your nice US flag.



          documentclass[tikz,border=3.14mm]standalone
          usetikzlibraryshapes
          usepgfmodulenonlineartransformations
          definecolorusbluergb.234,.233,.430
          definecolorusaredrgb.698,.132,.203
          makeatletter
          defflagtransformation%
          pgf@xa=pgf@x%
          pgf@ya=pgf@y%
          %typeoutoldspace x=pgf@xaspace old space y=pgf@ya%
          pgfmathsetmacromyypgf@ya+7*sin(pgf@xa*3.6)-0.1*pgf@xa%
          %typeoutatspace x=thepgf@xa:space newspace y=myy%
          pgf@y=myy pt
          makeatother
          newcommandUSFlag%
          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)) ;


          begindocument
          begintikzpicture[font=sffamily,scale=2,transform shape]
          beginscope[local bounding box=linear]
          USFlag
          endscope
          node[anchor=south] (lin) at (linear.north)linear;
          beginscope[xshift=2.5cm,local bounding box=nonlinear,transform shape
          nonlinear=true]
          pgftransformnonlinearflagtransformation
          USFlag
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0,0) rectangle (0.95,1);
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0.95,0) rectangle (1.9,1);
          endscope
          node[anchor=south] at (lin.south-|nonlinear.north)nonlinear;
          endtikzpicture
          enddocument


          enter image description here



          And here is something for Black Mild.



          documentclass[tikz,border=3.14mm]standalone
          usetikzlibraryshapes
          usepgfmodulenonlineartransformations
          definecolorusbluergb.234,.233,.430
          definecolorusaredrgb.698,.132,.203
          makeatletter
          defflagtransformation%
          pgf@xa=pgf@x%
          pgf@ya=pgf@y%
          %typeoutoldspace x=pgf@xaspace old space y=pgf@ya%
          pgfmathsetmacromyypgf@ya+7*sin(pgf@xa*3.6)-0.1*pgf@xa%
          %typeoutatspace x=thepgf@xa:space newspace y=myy%
          pgf@y=myy pt
          tikzdeclarecoordinatesystemflag% https://tex.stackexchange.com/a/434247/121799
          tikz@scan@one@pointrelax(#1)
          flagtransformation

          makeatother
          newcommandUSFlag%
          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)) ;


          begindocument
          foreach X in 0,5,...,95
          begintikzpicture[font=sffamily,scale=2,transform shape]
          beginscope[xshift=X pt,
          local bounding box=nonlinear,transform shape
          nonlinear=true]
          pgftransformnonlinearflagtransformation
          USFlag
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0,0) rectangle (0.95,1);
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0.95,0) rectangle (1.9,1);
          shade[left color=gray,right color=gray!70,middle color=gray!20]
          (0,1.05) rectangle ++ (-0.1,-3);
          endscope
          endtikzpicture
          enddocument


          enter image description here



          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.



          documentclass[tikz,border=3.14mm]standalone
          usepgfmodulenonlineartransformations
          makeatletter
          defflagtransformation%
          pgf@xa=pgf@x%
          pgf@ya=pgf@y%
          %typeoutoldspace x=pgf@xaspace old space y=pgf@ya%
          pgfmathsetmacromyypgf@ya+7*sin(pgf@xa*3.6)-0.1*pgf@xa%
          %typeoutatspace x=thepgf@xa:space newspace y=myy%
          pgf@y=myy pt
          makeatother
          definecolorSkyBluergb0.00784314,0.32156864,0.61176473
          definecolorFireRedrgb0.86274511,0.11764706,0.20784314
          newcommandIcelandFlag
          fill[SkyBlue] (0,0) rectangle (25,18);
          fill[white] (7,0) rectangle (11,18);
          fill[white] (0,7) rectangle (25,11);
          fill[FireRed] (8,0) rectangle (10,18);
          fill[FireRed] (0,8) rectangle (25,10);
          begindocument
          begintikzpicture[font=sffamily,scale=0.15]
          beginscope[local bounding box=linear]
          IcelandFlag
          endscope
          node[anchor=south] (lin) at (linear.north)linear;
          beginscope[xshift=35cm,local bounding box=nonlinear]
          pgftransformnonlinearflagtransformation
          IcelandFlag
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (0,0) rectangle (12.5,18);
          shade[left color=black,right color=black,middle color=white,opacity=0.15]
          (12.5,0) rectangle (25,18);
          endscope
          node[anchor=south] at (lin.south-|nonlinear.north)nonlinear;
          endtikzpicture
          enddocument


          enter image description here



          In order to draw a 3d flag, you may use tikz-3dplot.
          With shade you can get something like this.



          documentclass[tikz]standalone
          usepackagetikz-3dplot
          definecolorgerblaRGB0,0,0
          definecolorgerredRGB255,0,0
          definecolorgeryelRGB255,204,0
          begindocument
          tdplotsetmaincoords7020
          begintikzpicture[tdplot_main_coords]
          % draw[-stealth] (0,0,0) -- (2,0,0) node[pos=1.1]$x$;
          % draw[-stealth] (0,0,0) -- (0,2,0) node[pos=1.1]$y$;
          foreach X [count=Y] in gerbla,gerred,geryel
          shade[left color=X,right color=X!70!black,middle color=X!70!white]
          plot[variable=x,domain=0:2] (x,0.2*sin(x*90),4-Y)
          --
          plot[variable=x,domain=2:0] (x,0.2*sin(x*90),3-Y);
          shade[left color=X!70!black,right color=X,middle color=X!70!white]
          plot[variable=x,domain=2:4] (x,0.2*sin(x*90),4-Y)
          --
          plot[variable=x,domain=4:2] (x,0.2*sin(x*90),3-Y);
          endtikzpicture
          enddocument


          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 18 mins ago

























          answered 2 hours ago









          marmotmarmot

          115k5145276




          115k5145276












          • I'm afraid this only answers the bonus question, for flags of Germany, Netherlands, etc. only. How can it deal with, for example, the US flag?

            – JouleV
            2 hours ago











          • @JouleV I switched gears completely and used nonlinear transformations. That way you can wave any flag you have the TikZ code for.

            – marmot
            1 hour ago






          • 1





            @JouleV It does work if you set transform shape nonlinear=true.

            – marmot
            1 hour ago






          • 1





            @marmot One word: perfect! Thanks you very much!!!!!

            – JouleV
            56 mins ago






          • 1





            @JouleV OK OK, I give in. Now it is attached to some post. ;-)

            – marmot
            18 mins ago


















          • I'm afraid this only answers the bonus question, for flags of Germany, Netherlands, etc. only. How can it deal with, for example, the US flag?

            – JouleV
            2 hours ago











          • @JouleV I switched gears completely and used nonlinear transformations. That way you can wave any flag you have the TikZ code for.

            – marmot
            1 hour ago






          • 1





            @JouleV It does work if you set transform shape nonlinear=true.

            – marmot
            1 hour ago






          • 1





            @marmot One word: perfect! Thanks you very much!!!!!

            – JouleV
            56 mins ago






          • 1





            @JouleV OK OK, I give in. Now it is attached to some post. ;-)

            – marmot
            18 mins ago

















          I'm afraid this only answers the bonus question, for flags of Germany, Netherlands, etc. only. How can it deal with, for example, the US flag?

          – JouleV
          2 hours ago





          I'm afraid this only answers the bonus question, for flags of Germany, Netherlands, etc. only. How can it deal with, for example, the US flag?

          – JouleV
          2 hours ago













          @JouleV I switched gears completely and used nonlinear transformations. That way you can wave any flag you have the TikZ code for.

          – marmot
          1 hour ago





          @JouleV I switched gears completely and used nonlinear transformations. That way you can wave any flag you have the TikZ code for.

          – marmot
          1 hour ago




          1




          1





          @JouleV It does work if you set transform shape nonlinear=true.

          – marmot
          1 hour ago





          @JouleV It does work if you set transform shape nonlinear=true.

          – marmot
          1 hour ago




          1




          1





          @marmot One word: perfect! Thanks you very much!!!!!

          – JouleV
          56 mins ago





          @marmot One word: perfect! Thanks you very much!!!!!

          – JouleV
          56 mins ago




          1




          1





          @JouleV OK OK, I give in. Now it is attached to some post. ;-)

          – marmot
          18 mins ago






          @JouleV OK OK, I give in. Now it is attached to some post. ;-)

          – marmot
          18 mins ago


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f483459%2fhow-to-draw-a-waving-flag-in-tikz%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Magento 2 duplicate PHPSESSID cookie when using session_start() in custom php scriptMagento 2: User cant logged in into to account page, no error showing!Magento duplicate on subdomainGrabbing storeview from cookie (after using language selector)How do I run php custom script on magento2Magento 2: Include PHP script in headerSession lock after using Cm_RedisSessionscript php to update stockMagento set cookie popupMagento 2 session id cookie - where to find it?How to import Configurable product from csv with custom attributes using php scriptMagento 2 run custom PHP script

          Can not update quote_id field of “quote_item” table magento 2Magento 2.1 - We can't remove the item. (Shopping Cart doesnt allow us to remove items before becomes empty)Add value for custom quote item attribute using REST apiREST API endpoint v1/carts/cartId/items always returns error messageCorrect way to save entries to databaseHow to remove all associated quote objects of a customer completelyMagento 2 - Save value from custom input field to quote_itemGet quote_item data using quote id and product id filter in Magento 2How to set additional data to quote_item table from controller in Magento 2?What is the purpose of additional_data column in quote_item table in magento2Set Custom Price to Quote item magento2 from controller

          How to solve knockout JS error in Magento 2 Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?(Magento2) knockout.js:3012 Uncaught ReferenceError: Unable to process bindingUnable to process binding Knockout.js magento 2Cannot read property `scopeLabel` of undefined on Product Detail PageCan't get Customer Data on frontend in Magento 2Magento2 Order Summary - unable to process bindingKO templates are not loading in Magento 2.1 applicationgetting knockout js error magento 2Product grid not load -— Unable to process binding Knockout.js magento 2Product form not loaded in magento2Uncaught ReferenceError: Unable to process binding “if: function()return (isShowLegend()) ” magento 2