1

I would like to do a Tikz image animation of growing lines with a certain randomness with regard to their initial rotation angle (and potentially also with a certain randomness in their initial x and y coordinates). I am aware that Tikz provides a rand and a random function (see example code) which work nicely for static images. However, inside of an animation they create a new random number for each frame. How could the random number be passed such that it is only evaluated initially?

\documentclass{standalone}

\usepackage{tikz}
\usepackage{animate}

\begin{document}

\begin{animateinline}[autoplay, loop]{24}
    \multiframe{100}{ry=0.05+0.02}{
    \begin{tikzpicture}
        \foreach \x in {0,1,...,5}
        {
        \draw [thick, rotate around={random*10:(\x,0)}] ({\x},0) -- ++(0,\ry);
        }
        \path [use as bounding box] (0,0) rectangle (5,2.1);
    \end{tikzpicture}}
\end{animateinline}

\end{document}

Example animation obtained with code above

3
  • Have you tried to set a seed? \pgfmathsetseed{<integer>}: Explicitly sets the seed for the pseudo-random number generator (see pgf manual).
    – Unknown
    Commented May 14, 2022 at 13:53
  • Thank you very much! It works if the \pgfmathseed{} command is inserted within the multiframe environment.
    – LeonC
    Commented May 14, 2022 at 14:05
  • I added a answer based on my comment. Please accept it, when it solved your problem.
    – Unknown
    Commented May 14, 2022 at 14:12

1 Answer 1

1

To solve this problem one can set a seed with:

\pgfmathsetseed{<integer>}

Description from the PGF/TikZ-Manual: Explicitly sets the seed for the pseudo-random number generator. By default it is set to the value of \time×\year.

You must log in to answer this question.

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