TikZ – How to Use Left, Middle, and Right Color in Draw Argument

shadingtikz-pgf

I'm forced to define colors within my tikzset for one of my projects. This requires me to use the draw command within my tikzset to set a color.

Normally I can just use, say \draw command to just set an argument of [top color=#1,bottom color=#3, middle color=#2] to get the desired result, but in this case I want to use the draw within my tikzset to define fading colors in similar fashion.

I doubt there are any workarounds barring perhaps the shading command for which I have not found an argument equivalent (?) in the PGF manual v3.00, see page 694.

Code:

\tikzset{
mal/.style={->, >=stealth,
single arrow, line width=16mm,
single arrow head extend=.5cm, single arrow head indent=.25cm}
}

And the object itself:

\begin{tikzpicture}[scale=2,node distance=1cm, auto,baseline=-.5ex]
\node (dummy) at (-5,-10) {}; 
\begin{scope}[remember picture,overlay,shift={(dummy.center)}]

\def\malpath{(8.75,4.25) arc (440:130:7.75)}
\draw[mal] 
\malpath;
\end{scope}

Best Answer

Well yet another polar transformation hack. We are lucky since the path is circular so we can pull off this. For other curve shapes, it's quite more involved, if not impossible

Here, the x coordinate becomes the angle so by moving up and down we control the radius. By moving left and right we play with the rotation. I placed two nodes inside and outside the transformation scope. It is pleasing enough to fool around. Notice that the arrow tip is also distorted.

\documentclass[tikz]{standalone}
\usepgfmodule{nonlineartransformations}
\usetikzlibrary{curvilinear,shapes.arrows}
\tikzset{arrownode/.style={
    transform shape nonlinear=true,
    shape=single arrow,
    shape border rotate=180,
    draw,
    top color=red,
    bottom color=blue,
    middle color=black
    }
}
\makeatletter
\def\polartransformation{% Directly from the manual
\pgfmathsincos@{\pgf@x}
\pgf@x=\pgfmathresultx\pgf@y%
\pgf@y=\pgfmathresulty\pgf@y%
}
\makeatother

\begin{document}
\begin{tikzpicture}
\node[arrownode,text height=1cm,middle color=white] at (0,3) {\phantom{\hspace{10cm}}};
\begin{scope}
\pgftransformnonlinear{\polartransformation}
\node[arrownode,text height=1cm] at (0,3) {\phantom{\hspace{10cm}}};
% rotate shading angle !!
\node[arrownode,shading angle=60] at (pi,-2) {\phantom{\hspace{10cm}}};
\end{scope}
\node[arrownode,middle color=white] at (pi,-2) {\phantom{\hspace{10cm}}};
\end{tikzpicture}
\end{document}

enter image description here