# How to use curve path with fill command in tikz?

I´ve tried using arcs to get the picture below, but I have to precise a specific center for each arc, because they don´t finish in the point which they should. Instead of arcs, I want to use curve paths to define the filled regions. How to draw or include in my code curve paths?. Maybe There's other solutions. I need your help.

\documentclass[10pt,a4paper]{book}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}

\draw[step=.2cm,gray!15,very thin](-2cm,-2cm)grid(2cm,2cm);

\draw[gray!30](-2cm,0) -- (2cm,0);
\draw[gray!30](0cm,-2cm) -- (0,2cm);
\draw (0cm,1.5576cm)--(0cm,.6227cm).. controls (.05cm,.28cm) and (.25cm,.2cm) ..(.6512cm,0cm)--(.6512cm,.9076cm) .. controls (.4cm,1cm)and(.1cm,1.1cm)..(0cm,1.5576cm);

\draw (0cm,1.5576cm).. controls (.12cm,1.2cm)and(.45cm,1.1cm)..(.8118cm,.9918cm)--(.8118cm,.0931cm)--(.9764cm,.2014cm)--(.9764cm,1.0681cm) .. controls (.45cm,1.12cm)and(.15cm,1.31cm)..(0cm,1.5576cm);

\draw (0cm,1.5576cm).. controls (.2cm,1.32cm)and(.7cm,1.21cm)..(1.141cm,1.1644cm)--(1.141cm,.3418cm)--(1.3016cm,.6227cm)--(1.3016cm,1.2727cm) .. controls (.7cm,1.3cm)and(.2cm,1.4cm)..(0cm,1.5576cm);

\draw (0cm,1.5576cm).. controls (.2cm,1.47cm)and(.7cm,1.3cm)..(1.3016cm,1.4212cm)--(1.3016cm,1.5576cm) .. controls (.7cm,1.45cm)and(.2cm,1.5cm)..(0cm,1.5576cm);

\end{tikzpicture}

\end{document}


The desired output:

Output of the MWE:

This is the picture which shows the problem I want to solve, I want to define the center of the arc. Also, instead of draw an arc, I'd like to include curve paths to include different radius.

-
You can draw everything as a rectangle and clip with the outer shield-like path (or book pages?). –  percusse Feb 2 '13 at 16:17
@percuße Thanks for answering. Which command can I use with your advice? –  Isai Feb 2 '13 at 16:24
We can help you much better if you can also include what the result should be about. Do you have problems with the lower right parts of the shape? I mean the arcs are not following smoothly. –  percusse Feb 2 '13 at 16:30
Oh I see, the screenshot is not what you have already. Let me put your output too so there is no ambiguity –  percusse Feb 2 '13 at 16:37
Simply add --cycle; at the end of each \draw command, that will complete the path, enabling it to be filled. Then add [fill=<color>] and you will have your figure. Furthermore, you are probably not requiring the black drawed edge. Thus you should do \path[fill=<color>] <path construction> -- cycle;. Apparently ..cycle has not been added to the function of curves with control points. –  zeroth Feb 2 '13 at 20:34

Here is my take. First, the result:

Now the code, and after it, the explanations.

\documentclass{standalone}
\usepackage{ifthen}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}[x=3mm, y=3mm]
\coordinate (spine) at (-4,4);
\def\contour{(spine) -- ++(8,0) -- ++(0, -6)
to[out=-110, in=30] ++(-4,-4)
to[out=150, in=-70] ++(-4, 4) -- cycle
}

% Clipping to the above contour
\clip\contour;
% Draw each page
\foreach \xx in {6,5,...,0} {
% Following coordinates are tricky
\coordinate (corner) at (\xx,0.75*\xx);
\coordinate (center) at ($(spine)!.5!(corner)!5*\xx*\xx+2 cm!90:(corner)$);

\ifthenelse{\isodd{\xx}}   % Alternating colors
{\edef\mycolor{white}}
{\edef\mycolor{red!80!black!80!white}}

\fill[fill=\mycolor]   % Tricky code again
let \p1 = ($(center)-(spine)$),
\p2 = ($(center)-(corner)$),
\n0 = {veclen(\x1,\y1)},
\n1 = {atan2(\x1,\y1)},
\n2 = {atan2(\x2,\y2)}
in
(spine) arc(\n1:\n2:-\n0) -- +(0, -10) -| (spine) -- cycle ;
% Debugging commands
%    \draw (center) [fill=red] circle(2pt) node[above] {c\xx};
%    \draw (corner) [fill=red] circle(2pt) node[above] {\xx};
}
% Debugging command
%  \draw \contour;
\end{tikzpicture}
\end{document}


# Explanations

Percusse gave me the idea in one comment of drawing each page as a rectangle and then clipping the result. However each page is not a rectangle because of the curly top border.

Obviously that border is a circular arc, but it is not clear what is the radius of each one. In absence of a design guide for the logo, I had to guess some things from the image.

First, I assumed that the corners of each "page" in the book lay in a straight line (even those which are not seen because of the clipping). Second, I assumed that the radius of the arc in the page top, is different for each page (it looks more "curved" for the front pages).

Then, the syntax used by tikz to draw arcs is inconvenient, because it needs a starting angle, ending angle and radius, and all those quantities are unknown. I used the syntax let ... in to draw the arc in a more convenient way, that is, knowing it starting point ((spine) node), its ending point ((corner) node, which is different for each page in the book) and its center, which is still unknown.

The center of each arc has to be neccessarily in a perpendicular to the middle point of the line (spine)--(corner), so I used the syntax ($(spine)!.5!(corner)$) to find that point, and from it, I used the syntax ($(point)!amount cm!90:(corner)$) to find a point which is at 90 degrees of the line (point)--(corner) and at a distance amount cm of (point). Basically this way I find the center of the arc, and amount cm is the radius.

Now I had to invent a formula to achieve a variable radius, depending on the page. I came to 2cm + 5n^2, being n the number of the page. I found this by trial and error.

Now, if you want to see the "behind the scenes" picture, only have to comment the \clip line (which reveals all the rectangles which made the pages of the book), and uncomment the last lines about debugging, which draw the clipping contour and the centers of each arc. This is what you'll get:

-
Thanks a lot, this is a hard answer. –  Isai Feb 2 '13 at 22:03