I am trying to draw a RGB cube using Tikz. Until now I managed to create this cube with color gradients:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{3d}
\usetikzlibrary{shadings}
\definecolor{mypurple}{rgb}{1.0,0.0,1.0}
\begin{document}
\begin{tikzpicture}[x = {(0.5cm,0.5cm)},
y = {(0.95cm,-0.25cm)},
z = {(0cm,0.9cm)}]
\begin{scope}[canvas is yz plane at x=-1]
\shade[lower right=mypurple, lower left=blue, upper right=white, upper left=cyan] (-1,-1) rectangle (1,1);
\end{scope}
\begin{scope}[canvas is xz plane at y=1]
\shade[lower right=red, lower left=mypurple, upper right=yellow, upper left=white] (-1,-1) rectangle (1,1);
\end{scope}
\begin{scope}[canvas is yx plane at z=1]
\shade[lower right=white, lower left=cyan, upper right=yellow, upper left=green] (-1,-1) rectangle (1,1);
\end{scope}
\end{tikzpicture}
\end{document}
Result:
It seems that the reference points upper/lower left/right are interpreted to be relative to the bounding rectangle of the particular rectangle.
How can I set the corners as reference points?
Best Answer
Unfortunately, you can't, as the manual states
Here, rectangle seems to mean "a shape whose sides are parrallel to the page's edges". Fortunately, you can interpolate the shading yourself.
A few hints:
\colorlet{<name>}[<model>]{<definition>}
. If you leave out the<model>
, then sometimes a different model is chosen resulting in strange color effects.(\x+0.1)
and(\y+0.1)
parts in the second coordinates). If you use the exact size you'll see tiny gaps between the tiles. That's also why I added a\clip
at the beginning of eachscope
as otherwise the faces would be to big.externalize
facilities.\makeatletter
and\makeatother
fix a bug in the implementation ofcanvas is xy plane at z=
of the 3d library. This patch was written by Jake in this answerCode
Output