2

I'm very new to TikZ and I'm having a slight problem that I'm not entirely sure how to solve.

Suppose I generate a sequence of boxes like so:

 \documentclass{report}
 \usepackage{tikz}

 \begin{document}
 \begin{tikzpicture}
 \foreach \x in {1,2,...,5}{
      \draw (\x,0) -- (\x+1,0) -- (\x+1,1) -- (\x,1) -- cycle;
 }
 \end{tikzpicture}
 \end{document}

How can I introduce a "wavy" effect to the sequence such the the boxes fit within the following shape:

 \documentclass{report}
 \usepackage{tikz}

 \begin{document}
 \begin{tikzpicture}
 \draw (0,0) .. controls (2.5,0.5) and (7.5,-0.5) .. (10,0) -- (10,1) .. controls (7.5,0.5) and (2.5,1.5) .. (0,1) -- cycle;
 \end{tikzpicture}
 \end{document}

I also want to colour these boxes using fill=, so I need for them to be recognised independent entities.

2

If you know the curve of your wave, you can use the plot command from tikz. I assume that it is not essential to use the spline that you gave in your MWE, so I replaced it with a sine wave that looks similar:

\begin{tikzpicture}
  \foreach \x in {1,2,...,5} {
    \draw (\x,0) .. controls (\x+0.25,0.5) and (\x+0.75,-0.5) .. (\x+1,0) -- (\x+1,1)  .. controls (\x+0.75,0.5) and (\x+0.25,1.5) .. (\x,1) -- cycle;
  }
\end{tikzpicture}

a sine wave

Then, one just has to use the same function to plot the boxes:

\begin{tikzpicture}
  \draw[domain=0:10] (0,0) -- plot (\x,{0.2*sin(\x*36)}) -- plot (10-\x,{1-0.2*sin(\x*36)}) -- cycle;
\end{tikzpicture}

a wave of boxes

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.