I defined a new shape that draws a flower with predefined filling and coloring:
\makeatletter
\pgfdeclareshape{flower}{
\savedanchor{\center}{%
\pgfpointorigin}
\anchor{center}{\center}
\backgroundpath{%
\begingroup
\tikz@mode
\iftikz@mode@draw
\foreach \a in {60,120,...,360} {
\pgftransformrotate{\a}
\pgfpathellipse{\pgfpointxy{0}{0.7}}{\pgfpointxy{0.25}{0}}{\pgfpointxy{0}{0.5}}
}
\pgfpathcircle{\pgfpoint{0}{0}}{0.4cm}
\let\my@color\tikz@strokecolor!60!\tikz@fillcolor
\foreach \a in {30,60,...,360} {%
\pgftransformrotate{\a+7}%
\pgfpathmoveto{\pgfpointxy{0}{0.1}}
\def\y{0.6+0.05*rand}
\pgfpathlineto{\pgfpointxy{0}{\y}}
\pgfpathcircle{\pgfpointxy{0}{\y}}{0.05cm}
}
\fi
\iftikz@mode@fill
\begin{scope}
\foreach \a in {60,120,...,360} {
\pgftransformrotate{\a}
\pgfpathellipse{\pgfpointxy{0}{0.7}}{\pgfpointxy{0.25}{0}}{\pgfpointxy{0}{0.5}}
}
\pgfusepath{clip}
\pgfpathcircle{\pgfpointxy{0}{0}}{1.2cm}
\pgfutil@colorlet{tikz@radial@outer}{\tikz@fillcolor!70}
\pgfutil@colorlet{tikz@radial@inner}{\tikz@fillcolor!60!\tikz@strokecolor}
\pgfshadepath{radial}{0}
\pgfusepath{}
\end{scope}
% \tikz@mode@clipfalse
\let\my@strokecolor\tikz@strokecolor
\let\my@fillcolor\tikz@fillcolor
\pgfsetfillcolor{\my@strokecolor}
\pgfpathcircle{\pgfpointxy{0}{0}}{0.4cm}
\pgfusepath{fill}
\foreach \a in {30,60,...,360} {%
\pgftransformrotate{\a+7}%
\pgfpathmoveto{\pgfpointxy{0}{0.1}}
\def\y{0.5+0.05*rand}
\pgfpathlineto{\pgfpointxy{0}{\y}}
\pgfpathcircle{\pgfpointxy{0}{\y}}{0.05cm}
}
\let\my@color\my@fillcolor
\pgfutil@colorlet{\my@color}{\my@strokecolor!60!\my@fillcolor}
\pgfsetstrokecolor{\my@color}
\pgfsetfillcolor{\my@color}
\pgfusepath{stroke,fill}
\fi
\endgroup
}
}
\makeatother
which results in a nicely filled and colored flower when used as:
\node[flower, fill=pink, draw=purple] {};

Still, I have several problems and questions, for which I am not able to find an answer myself.
1) if I do not use \begin{scope} and \end{scope}, I do not know how to stop clipping which I do in the filling section. Is there a way to avoid using scopes? Or it is completely fine to have them there?
2) In the drawing of stamens, their height can be slightly changed using random function
\def\y{0.6+0.05*rand}
\pgfpathlineto{\pgfpointxy{0}{\y}}
\pgfpathcircle{\pgfpointxy{0}{\y}}{0.05cm}
but each time the value of \y is recalculated and I do not know how to fix it here.
3) If I do not specify the colors of stroke and fill
fill=pink, draw=purple
I get compiling errors. I even get errors if I use
\node[flower, fill, color=red] {};
In that case, how can I use the default colors?
4) I would like to define a new decoration that would decorate a path with flowers of random size, moreover I expect these flowers to be exactly the same as on the picture above. Here is the code of my decoration:
\pgfdeclaredecoration{flowers}{initial}{
\state{initial}[width=1cm]
{
\pgfmathparse{round(rnd*90)}
\pgftransformrotate{\pgfmathresult}
\pgfmathparse{0.2+rand*0.1}
\pgftransformscale{\pgfmathresult}
\pgfsetlinewidth{\pgfmathresult*\pgflinewidth}
\pgfsetcolor{pink}
\pgfsetfillcolor{pink}
\pgfsetstrokecolor{purple}
\pgfnode{flower}{center}{}{}{\pgfusepath{stroke,fill}}
}
\state{final}
{
\pgfpathmoveto{\pgfpointdecoratedpathlast}
}
}
My first problem is that I get "plain" flowers by calling
\draw[decorate, decoration={flowers}] (-4,-3) -- (4,-3);

instead of a nice filling/coloring. What should I modify in the definition of flower?
Then, I would prefer to use random step between the flowers, how it can be done?


drawkey should always be given with a color which might give some headache later. Also now you should be able to post images. – percusse Apr 22 '13 at 14:10\beckgroundpath: If you want to specify that something should “always” happen when this shape is drawn (for example, if the shape is a stop-sign, we always want it to be filled with a red color), you can use commands like\beforebackgroundpath, explained below. — Could you describe what you intended with your code? Ifdrawandfillis both active you actually over-fill all that stuff that is drawn previously. – Qrrbrbirlbel Apr 22 '13 at 15:08\let\my@color\tikz@strokecolor!60!\tikz@fillcolorwon’t work (but you don’t even use it their). Use\edef\pgf@tempa{\tikz@strokecolor!60!\tikz@fillcolor} \let\my@color\pgf@tempainstead. Later you do\let\my@color\my@fillcolor, even though you overwrite\my@colorin the very next line. — You can check with\ifx\tikz@fillcolor\pgfutil@emptywhether a color is set. – Qrrbrbirlbel Apr 22 '13 at 15:15\pgfutil@colorlet(which internally usescolorx’\colorlet) doesn’t save the color definition in the macro\my@colorbut internally in a macro that contains what\my@colorexpands to. You can simply use\pgfutil@colorlet{my@color}or\pgfutil@colorlet{temporary color that is only used here and thrown away after that}. ;) – Qrrbrbirlbel Apr 22 '13 at 15:42\pgfscope ... \endpgfscopefor a more "low-level" feel. Re Qn 3: What should happen if only one colour is specified? You use the draw and fill colours to provide the shading so if they are the same then there is no shading and it is filled uniformly. Here's where you might want to consider defining new keys for these colours rather than use the fill and draw ones. The\iftikz@mode@drawpart seems to be missing a\pgfusepath{stroke}, is this right or am I missing something? – Andrew Stacey Apr 22 '13 at 16:18