# Tikz: How to mirror things with complex shaders such as the colour wheel

I wanted to depict a point moving over the unit circle using a rainbow circle. I managed to do that using the colour wheel. However, the colour wheel goes clockwise, and I need it to go counterclockwise, so I need to mirror it somehow.

I tried a negative scaling factor, but that didn't work because shading is applied after any transformation like this. Is there any way by which I can invert the colour wheel.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[->, ultra thick] (-2.7,0) -- (2.7,0);
\draw[->, ultra thick] (0,-2.7) -- (0,2.7);
\begin{scope}[xscale=-1]
(0,0) arc (45:405:2.5) (-0.03,-0.03) arc (45:405:2.45);
\end{scope}
\draw[, ultra thick] (-1.8,-1.8) -- (1.8,1.8);
\end{tikzpicture}
\end{document}


which produces:

• In principle, you could take one of these wheels. However, at least I fail to exactly reproduce the output there, but perhaps you are more fortunate. – marmot Mar 27 '18 at 21:07

Please forget about my previous answer. All you need to do is to issue a transform canvas.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[->, ultra thick] (-2.7,0) -- (2.7,0);
\draw[->, ultra thick] (0,-2.7) -- (0,2.7);
\begin{scope}[transform canvas={xscale=-1}]
(0,0) arc (45:405:2.5) (-0.03,-0.03) arc (45:405:2.45);
\end{scope}
\draw[, ultra thick] (-1.8,-1.8) -- (1.8,1.8);
\end{tikzpicture}
\end{document}


I really did not appreciate the transform canvas until I came across this post.

Historical artifacts: This is surprisingly tricky and the following is certainly not my answer, but just stolen from this answer. It turns out that there are some subtleties I was not aware of. The shading seems to call some low-level postscript commands that I fail to understand. Even worse, the outcome depends on the viewer. This is in particular true for the code that follows.

\documentclass[tikz,border=5]{standalone}

\makeatletter
\newtoks\pgf@ps@toks
\newcount\c@pgf@ps

\def\pgf@ps@sp{ }

\def\pgf@ps@esettoks#1{\edef\pgf@ps@tmp{#1}\pgf@ps@toks\expandafter{\pgf@ps@tmp}}

\def\pgf@ps@repop#1#2{%
\c@pgf@countb=#2\relax%
\def\pgf@ps@op{#1}%
\def\pgf@ps@ops{}\pgf@ps@@repop}
\def\pgf@ps@@repop{%
\ifnum\c@pgf@countb<1\relax%
\else%
\edef\pgf@ps@ops{\pgf@ps@op\pgf@ps@ops}%
\expandafter\pgf@ps@@repop%
\fi%
}

\def\pgf@ps@generate@ps{%
\c@pgf@counta=\pgf@ps@ncol\relax%
\c@pgf@countb=\c@pgf@counta%
\pgf@ps@esettoks{ \noexpand\pgf@ps@interp{col@\the\c@pgf@counta}{col@\the\c@pgf@countb} }%
\pgfmathloop
\ifnum\c@pgf@counta<2\relax%
\else%
\c@pgf@countb=-\c@pgf@counta%
\pgf@ps@repop{pop\pgf@ps@sp}{\c@pgf@countb}%
\c@pgf@countb=\c@pgf@counta%
\ifnum\c@pgf@countb=0\relax%
\c@pgf@countb=\pgf@ps@ncol\relax%
\fi%
\pgf@ps@esettoks{ \the\c@pgf@counta\pgf@ps@sp eq { \pgf@ps@ops \noexpand\pgf@ps@interp{col@\the\c@pgf@counta}{col@\the\c@pgf@countb} }{ \the\pgf@ps@toks } ifelse}%
\repeatpgfmathloop%
\c@pgf@counta=\pgf@ps@ncol\relax%
\pgf@ps@repop{dup\pgf@ps@sp}{\c@pgf@counta}%
\pgf@ps@esettoks{ \pgf@ps@ops \the\pgf@ps@toks }%
}

\def\pgf@ps@colorstorgb#1{%
\c@pgf@ps=1\relax%
\pgfutil@for\pgf@ps@:={#1}\do{%
\pgf@ps@coltorgb{\pgf@ps@}{col@\the\c@pgf@ps}%
}

\def\pgf@ps@coltorgb#1#2{%
\expandafter\pgf@ps@marshal\expandafter{\csname#2\endcsname}%
}

\def\pgf@ps@rgb#1{\csname#1\endcsname}
\def\pgf@ps@interp#1#2{%
\pgf@ps@rgb{#1red} mul exch \pgf@ps@rgb{#2red} mul add
5 1 roll
\pgf@ps@rgb{#1green} mul exch \pgf@ps@rgb{#2green} mul add
3 1 roll
\pgf@ps@rgb{#1blue} mul exch \pgf@ps@rgb{#2blue} mul add
}

\pgf@ps@getcols{#3}%
\pgfmathparse{mod(#2+360/\pgf@ps@ncol-90,360)}%
\pgf@x=\pgfmathresult pt\relax%
\ifdim\pgf@x<0pt\relax%
\fi%
\edef\pgf@ps@rot{\pgfmath@tonumber{\pgf@x}}%
\pgf@ps@generate@ps%
\pgf@ps@esettoks{%
{\noexpand\pgfpoint{-50bp}{-50bp}}{\noexpand\pgfpoint{50bp}{50bp}}%
{\noexpand\pgf@ps@colorstorgb{#3}}%
{%
2 copy abs exch abs add 0.0001 ge { atan } { pop } ifelse
\pgf@ps@rot\pgf@ps@sp add dup 360 ge { -360 add } { } ifelse
360 \pgf@ps@ncol\pgf@ps@sp
div div dup floor dup 3 1 roll neg add dup neg 1 add exch
2 copy 2 copy 7 -1 roll 1 add
\the\pgf@ps@toks}}%
\edef\pgf@ps@marshal{\the\pgf@ps@toks}%
\pgf@ps@marshal}

\def\pgf@ps@getcols#1{%
\c@pgf@ps=0\relax%
\edef\pgf@ps@ncol{\the\c@pgf@ps}%
}

\begin{document}

\begin{tikzpicture}
\draw[->, ultra thick] (-2.7,0) -- (2.7,0);
\draw[->, ultra thick] (0,-2.7) -- (0,2.7);
\begin{scope}

This screenshot is made with acroread, with which I can confirm the screenshots from this answer, but for instance with preview I can't. What is, however, surprising to me is that the original color wheel looks the same in both viewers. Note also that the code in pgflibraryshadings.code.tex looks quite different from the one above. One possible interpretation is that the code pgflibraryshadings.code.tex` is more failsafe in the sense that the outcome won't depend that much the viewer. but these are only my speculations. If you know postscript well enough, you may just change the code there. I played with it but despite some partial successes I never arrived at something really useful. I hope you'll get a better answer than this one.