Following code must be changed into an animation. In the code where the "foreach" is, will be corresponding to one frame for each number, given 20 frames in total. Hence, when the animation is running the line is been drawn in real time.



\path[use as bounding box] (0,0) rectangle (11.5,12);

\foreach \x in {-2.9,-2.85,-2.8,...,-1.9}
        \draw (\oldx+8.5,\oldy+11) -- (\x+8.5,\y+11);


enter image description here

The code so far. However, the line change for each iteration.



                \foreach [count=\i] \j in {a,...,u}
                \node [scale=0.02] (\j) at (\i*0.30,0+rand*0.2) {};},
                \foreach [remember=\j as \k (initially a)] \j in {b,...,\alph{upperbound}} {
                    \draw (\k) -- (\j);
  • Is tex.stackexchange.com/questions/281354/… helpful? Oct 16, 2017 at 17:59
  • Something like this. However everytime the code runs the \foreach in the multiframe block, the rand will be different. Hence, every time a new block of the line is added, the previous line there is ready drawn will change.
    – Jesper H
    Oct 17, 2017 at 9:47

1 Answer 1


Frames of the animated graph are built by repeatedly appending a new line segment to the previously saved state of the graph. Saving the states of a graph ensures that the random number is only calculated once per line segment. The solution makes use of the xsavebox package:




%empty first frame:
\xsbox{mygraph}{\tikz \path[use as bounding box] (5.5,8.95) rectangle (6.6,9.65);}%

      %repeat previous graph
      %append new line segment
      \path[use as bounding box] (5.5,8.95) rectangle (6.6,9.65);
      \draw [line cap=round] (\oldx+8.5,\oldy+11) -- (\rx+8.5,\y+11);


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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