19

I'm trying to reproduce the spiral shape in the picture below in TikZ, I'm not interested in the atoms and the text, just the spiral. I want the spiral to be coloured green like in the image.

picture to reproduce

I was considering somehow putting together several sinus curves, however that seems like a really inefficient way to do this, and I don't know how I would colour the shape using that method.

43

Here is a possible solution:

enter image description here

\documentclass[tikz]{standalone}

\begin{document}
\begin{tikzpicture}
  \colorlet{color 2}{lime!50!gray}
  \colorlet{color 1}{white}
  \foreach \dx in {0,2,4}{
    \begin{scope}[xshift=\dx cm]
      \draw[draw=gray,top color=color 2,bottom color=color 1]
      (0,0) -- ++(1,0) cos ++(.5,1) sin ++(.5,1) -- ++(-1,0) cos ++(-.5,-1) sin ++(-.5,-1) -- cycle;
    \end{scope}
  }
  \foreach \dx in {0,2,4}{
    \begin{scope}[xshift=1cm + \dx cm]
      \draw[draw=gray,top color=color 1,bottom color=color 2]
      (0,2) -- ++(1,0) cos ++(.5,-1) sin ++(.5,-1) -- ++(-1,0) cos ++(-.5,1) sin ++(-.5,1) -- cycle;
    \end{scope}
  }
\end{tikzpicture}
\end{document}
  • Your colors are upside down ;) – Cole Johnson Dec 12 '14 at 0:59
  • 1
    @ColeJohnson Are you sure? Where is the light? ;-) – Paul Gaborit Dec 12 '14 at 5:43
19

Taking inspiration (and code) from Paul, here is a cramped spiral using in and out angles, just to show another way:

\documentclass[tikz,border=5]{standalone}
\begin{document}
\begin{tikzpicture}[x=3cm,y=0.8cm]
  \colorlet{color 2}{lime!50!gray}
  \colorlet{color 1}{white}
  \foreach \dx in {0,6,12}{
    \begin{scope}[xshift=\dx cm]
      \draw[draw=gray,top color=color 2,bottom color=color 1]
      (0,0) -- ++(1,0) to[out=0,in=180] ++(1,3) -- ++(-1,0) to[out=180,in=0] ++(-1,-3) -- cycle;
    \end{scope}
  }
  \foreach \dx in {0,6,12}{
    \begin{scope}[xshift=3cm + \dx cm]
      \draw[draw=gray,top color=color 1,bottom color=color 2]
      (0,3) -- ++(1,0) to[out=0,in=180] ++(1,-3) -- ++(-1,0) to[out=180,in=0] ++(-1,3) -- cycle;
    \end{scope}
  }
\end{tikzpicture}
\end{document}

enter image description here

13

Here is the Paul Gaborit's code rewriten with triple foreach to make it shorter ;).

\begin{tikzpicture}
  \colorlet{color 1}{lime!50!gray}
  \colorlet{color -1}{white}
  \foreach \s [evaluate=\s as \w using int(-\s)] in {1,-1} {
    \foreach \t in {0,1,2} {
      \draw[draw=gray,top color=color \s,bottom color=color \w, xshift=2*\t cm, xscale=\s]
      (-1.5,-1) \foreach \i in {1,-1} {cos ++(\i/2,\i) sin ++(\i/2,\i) -- ++(\i,0)};
    }
  }
\end{tikzpicture}

Note: I came to update using the Ignasi suggestion to use the central symetry between (-1.5,-1) cos ++(.5,1) sin ++(.5,1) -- ++(1,0) and cos ++(-.5,-1) sin ++(-.5,-1) -- cycle by introducing a third \foreach.

  • 1
    You can mark your answer as CW if rep point is a concern for yourself. Otherwise no problem. – percusse Dec 11 '14 at 17:09
  • @percusse sorry what meens CW ? And how to do it ? Thanks in advance for your help. – Kpym Dec 11 '14 at 17:19
  • It's Community Wiki. Before you post it should be on the lower right corner, a tick box, that you can mark it as a CW. See this for example. – percusse Dec 11 '14 at 17:21
  • 1
    @Kpym What about (-1.5,-1) \foreach \i in {1,-1} {cos ++(.5*\i,1*\i) sin ++(.5*\i,1*\i) -- ++(\i,0)} -- cycle; ? – Ignasi Dec 11 '14 at 18:02
  • @Ignasi I like this ! I'll edit the answer with your code. – Kpym Dec 11 '14 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.