3

I want to draw a gradient spiral with tikz and I am encountering problems. My current code:

\draw[line width=0.24mm, rotate=120, color=red] (0,0)
  \foreach \i [evaluate={\r=(\i/1212)^2;}] in {0,5,...,545} {
    -- (\i:\r)
  };

I have seen that if I add a "[color=red!10]" before the last semicolon, it overrides the "color=red" of the first line. However, what I would like to do is to use the \i variable (or a formula including it) instead of the number 10, in something like this:

\draw[line width=0.24mm, rotate=120, color=red] (0,0)
  \foreach \i [evaluate={\r=(\i/1212)^2;}] in {0,5,...,545} {
    -- (\i:\r)
  }[color=red!\i];

The problem is that the reference to "i" is outside the foreach loop, so I encounter a "! Missing number, treated as zero." error.

Is there any way I can use the "i" variable outside the loop? I've tried to define a variable inside the loop to use it outside with no success.

Any other way to draw a gradient spiral will be appreciated too.

Thanks!

1 Answers1

3

I think this works, though I'm not sure it looks that good.

enter image description here

\documentclass[border=4mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=5]
  \foreach \i [
   remember=\i as \previ(initially 0),
   evaluate=\i as \r using {(\i/1212)^2},
   evaluate=\previ as \prevr using {(\previ/1212)^2},
   evaluate=\i as \ired using {\i/5.45}] in {5,10,...,545} {
   \draw[line width=0.24mm, rotate=120, color=red!\ired] (\previ:\prevr) -- (\i:\r);
  };
\end{tikzpicture}
\end{document}
Torbjørn T.
  • 206,688