I enjoy TikZ styles and decorations a lot, but I still dabble with them. I know how to draw ribbons with a style, if they aren't meant to twist. But I'd like to define a style that has a twist of the ribbon along the way, and the ribbon should have different colours on the front and on the back.
The ribbon should be able to bend along the curved path. Is this possible? Maybe by defining a decoration? Or maybe it is possible to insert Bézier curves along the path?
\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikzset{
ribbon/.style={
preaction={
preaction={
draw,
line width=0.25cm,
white
},
draw,
line width=0.2cm,
black!30!#1
},
line width=0.15cm,
#1
},
ribbon/.default=gray
}
Ribbons are easy, just with my previously defined style:
\begin{tikzpicture}
\draw[ribbon=green] (0,0) to[out=0,in=90] (2,0) to[out=270,in=270] (4,2);
\draw[ribbon] (0,1) to[out=30,in=150] (2,1) to[out=-30,in=120] (4,-1);
\end{tikzpicture}
How can I make a twisted ribbon a style?
\newcommand{\myangle}{20}
\begin{tikzpicture}[looseness=0.5]
\fill[green] (0,-0.1) to[out= 0,in=180+\myangle] (2,0) to[out=180-\myangle,in= 0] (0,0.1);
\fill[red] (4,-0.1) to[out=180,in= -\myangle] (2,0) to[out= \myangle,in=180] (4,0.1);
\draw (0,-0.1) to[out= 0,in=180+\myangle] (2,0) to[out= \myangle,in=180] (4,0.1);
\node[inner sep=1.5pt,fill,white] at (2,0) {};
\draw (4,-0.1) to[out=180,in= -\myangle] (2,0) to[out=180-\myangle,in= 0] (0,0.1);
\end{tikzpicture}
Ideally, I'd like to use this like so:
\begin{verbatim}
\draw[twistedribbon={red,green}] (0,0) -- (4,0);
\end{verbatim}
\end{document}
Best Answer
Let us fix this meta-path.
First I created a decoration that draws a parallel line on the left of the meta-path.
Next I created another one that cross from left to right.
So if we draw such lines multiple times with different, we get a ribbon.
To color the front and back different, we need two half ribbons meeting each other.
Repeating it with different color, we are done.