Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In order to make it simple, I want to draw concentric circles fading out with something like

\foreach \x in {1,1.5,...,4}
\draw[color=black!{100-10*\x}!white] (0,0) circle (\x);

The problem is I don't know if there is a way to make some maths in the parameters of the \draw function. Is there a way ?

(I could solve the problem by doing something like

\foreach \x in {10,15,...,40}
\draw[color=white!\x!black] (5,0) circle ({0.1*\x});

But I really want to know if its possible to do it the other way)

Also, why something like

\foreach \x in {10,15,...,40}
\draw[color=white!\x!black] (5,0) circle ({0.1*\x} cm); %note the cm

does not work?

share|improve this question
1  
related: tex.stackexchange.com/questions/174902/… –  Jubobs Aug 7 at 7:49
    
@Jubobs Thanks! –  mwoua Aug 13 at 18:35

2 Answers 2

up vote 7 down vote accepted

You can do some thing like this:

\documentclass{article}
\usepackage{tikz}

\begin{document}
  \begin{tikzpicture}
      \foreach \x in {1,1.5,...,4}
       \pgfmathtruncatemacro{\tmp}{100-\x*20}
       \draw[color=blue!\tmp!green] (0,0) circle (\x);
  \end{tikzpicture}
\end{document}

enter image description here

Calculate the value outside, store it in a macro (possibly truncate if you want as I did) and then use the macro.

Applying the same strategy to your last query:

\documentclass{article}
\usepackage{tikz}

\begin{document}
  \begin{tikzpicture}
      \foreach \x in {10,15,...,40}
        \pgfmathsetmacro{\tmp}{0.1*\x}
        \draw[color=white!\x!black] (5,0) circle (\tmp cm);       
  \end{tikzpicture}
\end{document}

enter image description here

Another option as suggested by Torbjørn T. is to use evaluate:

\documentclass[border=5mm]{standalone}
\usepackage{tikz}

\begin{document}
  \begin{tikzpicture}
      \foreach [evaluate=\x as \y using 100-20*\x] \x in {1,1.5,...,4} 
      \draw[color=blue!\y!green] (0,0) circle (\x);
  \end{tikzpicture}
\end{document}
share|improve this answer
2  
In your last example every second circle is the same size as the previous because you've used \pgfmathtruncatemacro, use \pgfmathsetmacro instead. You could also add a solution with evaluate, i.e. \foreach [evaluate=\x as \y using 100-10*\x] \x in {1,1.5,...,8} \draw[color=black!\y!white,very thick] (0,0) circle (\x); –  Torbjørn T. Aug 7 at 5:51
    
@TorbjørnT. My bad. I didn't notice it. Now corrected. I have added evaluate option too. Many thanks for both suggestions :-) –  Harish Kumar Aug 7 at 7:03

With \multido you can define more than one variable:

\documentclass{article}
\usepackage{tikz,multido}
\begin{document}
  \begin{tikzpicture}
      \multido{\r=1+0.5,\i=80+-5}{8}{%
       \draw[color=blue!\i!green] (0,0) circle (\r);}
  \end{tikzpicture}
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.