Hello,
On Tuesday, October 15, 2013 4:07:49 PM UTC+3, Martin Heller wrote:
> > Could you point me to the right direction? I want TeX to calculate the new value of \XX and \YY in each iteration. Looks like, it does not happen - the definition (not expanded?) is still in place instead.
> Since you are already using pgf, you might as well use \foreach
> \begin{tikzpicture}[x=1mm,y=1mm]
> \pgfmathsetmacro{\constA}{60}%
> \foreach[%
> remember=\x as \xx (initially 0),
> remember=\y as \yy (initially 0),
> evaluate=\x using \yy - sin(\xx),
> evaluate=\y using \constA - \xx,
> ] \i in {0,...,50} {%
> \fill(\x,\y) circle(1pt);
> }%
> \end{tikzpicture}
Thanks a lot! I managed to produce what I needed (using slightly different formula but it's OK for now).
But I faced one interesting problem - number of iterations seems to be limited.
This is my code:
\documentclass{minimal}
\usepackage{ifthen}
\usepackage{tikz}
\begin{document}
%% Calculates the #1 % 4
\newcount\dv\newcount\res
\newcommand{\calcmod}[1]{
\dv=#1
\res=\the\dv
\divide\dv by 4
\multiply\dv by -4
\advance\res by \the\dv
}
\begin{tikzpicture}[x=1mm,y=1mm,scale=.35]
\pgfmathsetmacro{\constA}{40}%
\pgfmathsetmacro{\constB}{20}%
\pgfmathsetmacro{\constC}{100}%
\foreach[%
remember=\x as \xx (initially 0),
remember=\y as \yy (initially 0),
evaluate=\x using (\xx>0) ? \yy - sqrt(abs(\constB*\xx-\constC)) : \yy + sqrt(abs(\constB*\xx-\constC)),
evaluate=\y using \constA - \xx,
] \i in {0,...,13000} {%
\calcmod{\i}
\ifnum\res=0 \fill[color=red](\x,\y) circle(1pt);
\fi
\ifnum\res=1 \fill[color=yellow](\x,\y) circle(1pt);
\fi
\ifnum\res=2 \fill[color=blue](\x,\y) circle(1pt);
\fi
\ifnum\res=3 \fill[color=black](\x,\y) circle(1pt);
\fi
}%
\end{tikzpicture}
\end{document}
It works fine up to ~12000 iterations but when I increase the number to 13000 then pdflatex fails with the error message:
! TeX capacity exceeded, sorry [main memory size=5000000].
\pgfsyssoftpath@thepath ...h@curvetosupportbtoken
{-100.15211pt}{-145.2793pt...
l.36 }
%
I
Is there any solution for this issue?
Thanks a lot for your help! I am new to tikz and was not aware of this foreach's nice feature.