How to use Tikz to calculate and use successive color values with text?

Yes, you can vary the gray levels, and the following can be used also to general non-gray colors.

\documentclass{standalone}
  \usepackage{tikz}
  \begin{document}
  \begin{tikzpicture}
      \foreach \i [evaluate=\i as \j using {int(\i*10)}] in {0, 1, ..., 10} {
          \draw (\i, 0) node[text=gray!\j!white] {A};
      }
  \end{tikzpicture}
  \end{document}

enter image description here


Just for fun, another foreach solution:

\documentclass{standalone}
  \usepackage{tikz}
  \begin{document}
  \begin{tikzpicture}
      \foreach \i [count=\j] in {0, 10, ..., 100} {
          \draw (\j, 0) node[text=blue!\i!red] {A};
      }
  \end{tikzpicture}
  \end{document}

enter image description here


You can evaluate a variable within the foreach loop itself (see page 904 of 3.0.1a manual).

Here since you want to go from black to white, you can do:

result

\documentclass{standalone}
  \usepackage{tikz}
  \begin{document}
  \begin{tikzpicture}
      \foreach \i [evaluate=\i as \gradient using 100-\i*10] in {0, 1, ..., 10} {
          \draw (\i, 0) node[text=black!\gradient] {A};
      }
  \end{tikzpicture}
  \end{document}

Tags:

Color

Tikz Pgf