1

How to reduce distance between circles ? and how to colorize each circle ?

\documentclass{article}
\usepackage[paperheight=30cm,paperwidth=35cm,margin=1in,heightrounded]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc}


\begin{document}
\fbox{\begin{tikzpicture}[scale=0.8] % 
% center
\path  (0,0) coordinate(A);
% circles
\foreach \rr in {2,...,10}{
  \draw  (A) circle (\rr);
}
\end{tikzpicture}}
\end{document}
3

1 Answer 1

2

Since you're using a range in \foreach, I'm presuming that the number of circles is flexible; therefore, the number of colours involved should also be flexible.

Here is how I would do it.

  • Make the loop variable (called \n, below) vary over a range of integers (from 1 to the total number of circles to be drawn).
  • Use the \foreach's evaluate key to generate the value of each radius (called \rr below) on the basis of that loop variable.
  • Use \foreach's evaluate key to generate a value between 0 and 100 (called \sat below) and use that value to change the circles' colour linearly between two colours (red and blue, for instance).

enter image description here

\documentclass{article}
\usepackage[paperheight=30cm,paperwidth=35cm,margin=1in,heightrounded]{geometry}
\usepackage{tikz}

\begin{document}
\fbox{\begin{tikzpicture}[scale=0.8] % 
% center
\path  (0,0) coordinate(A);
% circles
\def\Rfactor{0.5}                   % multiplying factor
\pgfmathtruncatemacro\nbcircles{9}  % number of circles to draw
\foreach[
  var=\n,
  evaluate=\n as \rr using \Rfactor*(\n+1),
  evaluate=\n as \sat using 100/(\nbcircles-1)*(\n-1),
] \rr in {1,...,\nbcircles}
{
  \draw[blue!\sat!red]  (A) circle (\rr);
}
\end{tikzpicture}}
\end{document}

You must log in to answer this question.

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