With PGF/TikZ one can produce fadings, like
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fadings}
\begin{document}
\begin{tikzpicture}
\fill[green,path fading=south] (90:4) -- (210:4) -- (-30:4) -- cycle;
\end{tikzpicture}
\end{document}
Now I would like to rotate this picture by 120°, so that the fading starts at the left corner. TikZ has a fading angle
key, so that I thought the following should work:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fadings}
\begin{document}
\begin{tikzpicture}
\fill[green,path fading=south, fading angle=120] (90:4) -- (210:4) -- (-30:4) -- cycle;
\end{tikzpicture}
\end{document}
To my surprise, this produces the following picture:
Note that the fading doesn't start immediately at the corner and doesn't fade all the way to white (the upper vertex is at 25% saturation and the right one at 33%).
What is going on here and how can I produce the correct rotated picture?
Best Answer
The thing to remember about fadings is that they work by putting a rectangle behind the object, fading the rectangle and then clipping to the object. If you fade a rectangle with
fade angle=120
then you'll see that it does get to white, but only in the upper right corner of the rectangle, which isn't seen by the triangle.One way to get the fading to rotate correctly is to apply a canvas transformation. Of course, this can get a bit tricky working out all the coordinates! But as you can see below, this does work.
The images below are:
transform canvas={rotate=120},path fading=south
.rotate=120
: viz, the triangle is rotated but the fading isn't.path fading=south
path fading=south,fading angle=120