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)

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.


1 Answer 1


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

enter image description here

  \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);
  • Perhaps you can use Path following color gradient in TikZ May 11, 2016 at 12:18
  • It's exactly what I wanted! The spiral is part of a bigger design and the gradient will involve better looking colors, but the thing is that my problem is solved. Thanks! :) May 11, 2016 at 13:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .