I would like to draw some circles and some squares and I would like to put in into a loop. But that does not seem to work. Any help would be great.
\documentclass[tikz]{standalone}
\usepackage{xfp} % floating point unit f\"ur fpeval
\usepackage{tikz}
\usetikzlibrary{quotes}
\begin{document}
\begin{tikzpicture}
\edef\r{1.0}
\draw circle (\r);
\draw (-1.0*\r,\r) to (\r,\r); % oben
\draw (-1.0*\r,-1.0*\r) to (1.0*\r,-1.0*\r); % unten
\draw (-1.0*\r,0) to ["\fpeval{\r}"] (-1.0*\r,1.0*\r); % Mitte
\draw (-1.0*\r,-1.0*\r) to (-1.0*\r,1.0*\r); % links
\draw (1.0*\r,-1.0*\r) to (1.0*\r,1.0*\r); % rechts
\pgfmathparse{sqrt(\r^2 + \r^2)}\edef\r{\pgfmathresult};
\draw circle (\r);
\draw (-1.0*\r,\r) to (\r,\r); % oben
\draw (-1.0*\r,-1.0*\r) to (1.0*\r,-1.0*\r); % unten
\draw (-1.0*\r,0) to ["\fpeval{\r}"] (-1.0*\r,1.0*\r); % Mitte
\draw (-1.0*\r,-1.0*\r) to (-1.0*\r,1.0*\r); % links
\draw (1.0*\r,-1.0*\r) to (1.0*\r,1.0*\r); % rechts
\pgfmathparse{sqrt(\r^2 + \r^2)}\edef\r{\pgfmathresult};
\draw circle (\r);
\draw (-1.0*\r,\r) to (\r,\r); % oben
\draw (-1.0*\r,-1.0*\r) to (1.0*\r,-1.0*\r); % unten
\draw (-1.0*\r,0) to ["\fpeval{\r}"] (-1.0*\r,1.0*\r); % Mitte
\draw (-1.0*\r,-1.0*\r) to (-1.0*\r,1.0*\r); % links
\draw (1.0*\r,-1.0*\r) to (1.0*\r,1.0*\r); % rechts
\pgfmathparse{sqrt(\r^2 + \r^2)}\edef\r{\pgfmathresult};
\draw circle (\r);
\draw (-1.0*\r,\r) to (\r,\r); % oben
\draw (-1.0*\r,-1.0*\r) to (1.0*\r,-1.0*\r); % unten
\draw (-1.0*\r,0) to ["\fpeval{\r}"] (-1.0*\r,1.0*\r); % Mitte
\draw (-1.0*\r,-1.0*\r) to (-1.0*\r,1.0*\r); % links
\draw (1.0*\r,-1.0*\r) to (1.0*\r,1.0*\r); % rechts
\pgfmathparse{sqrt(\r^2 + \r^2)}\edef\r{\pgfmathresult};
\draw circle (\r);
\draw (-1.0*\r,\r) to (\r,\r); % oben
\draw (-1.0*\r,-1.0*\r) to (1.0*\r,-1.0*\r); % unten
\draw (-1.0*\r,0) to ["\fpeval{\r}"] (-1.0*\r,1.0*\r); % Mitte
\draw (-1.0*\r,-1.0*\r) to (-1.0*\r,1.0*\r); % links
\draw (1.0*\r,-1.0*\r) to (1.0*\r,1.0*\r); % rechts
\pgfmathparse{sqrt(\r^2 + \r^2)}\edef\r{\pgfmathresult};
\foreach \I in {1, ..., 5}{
\draw circle (\r);
\draw (-1.0*\r,\r) to (\r,\r); % oben
\draw (-1.0*\r,-1.0*\r) to (1.0*\r,-1.0*\r); % unten
\draw (-1.0*\r,0) to ["\fpeval{\r}"] (-1.0*\r,1.0*\r); % Mitte
\draw (-1.0*\r,-1.0*\r) to (-1.0*\r,1.0*\r); % links
\draw (1.0*\r,-1.0*\r) to (1.0*\r,1.0*\r); % rechts
\pgfmathparse{sqrt(\r^2 + \r^2)}\edef\r{\pgfmathresult};
}
\end{tikzpicture}
\end{document}
\foreach
loop are local. You'll need\xdef
(which is\global\edef
) or use theevaluate
and theremember
option of\foreach
.