2

I'm trying to combine animate's \multiframe command with a TikZ \fill command so that in every fourth frame, the top of my rectangle is moved by one unit:

\multiframe{20}{rya=10+-0.25}{
  \fill[green!10] (4,0) rectangle (6,\rya);
}

The problem with my current approach is that instead of resizing the rectangle by one unit every fourth frame, it gets resized by a quarter unit in each frame.

What I'm after is some kind of "floor" function that I could apply to \rya, or any kind of alternative way to achieve the same result.

(There are some other things being animated at the same time, preventing me from simply lowering the frame rate and using iya=10+-1 instead of rya=10+-0.25. I left them out here for the sake of brevity.)

5
  • There is a built-in floor function in TikZ, so you might just be able to write floor(\rya). Commented May 9, 2013 at 9:20
  • @JohnWickerson You may need some braces around that as well, {floor(\rya)}. Commented May 9, 2013 at 9:22
  • Thanks, but I get "undefined control sequence". Even leaving out the \rya part and simply trying the variation (6,{floor(3.5)}) will give me that. I'm currenly only doing \usepackage{tikz}, so maybe I need to include something else?
    – Thomas
    Commented May 9, 2013 at 9:49
  • Shouldn't be necessary, for example \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \fill (0,0) rectangle +(1,{floor(1.9)}); \fill (1.1,0) rectangle +(1,1.9); \end{tikzpicture} \end{document} works fine here. Could you create a complete, minimal example (an MWE ) that demonstrates the problem? Commented May 9, 2013 at 10:37
  • Alright, I'm an idiot. I must have kept messing up the syntax of floor but eventually got it right. Thanks a lot. Could someone please make this into an answer that I can accept?
    – Thomas
    Commented May 10, 2013 at 7:19

1 Answer 1

1

There is a floor function in PGF's math engine (see section 63.2 Functions of the manual), and this can be used in TikZ coordinates, e.g.

\node at (1,{floor(1.6)}) {text};

will place a node at (1,1). The braces surrounding floor() is necessary so that the closing parenthesis of floor isn't read as the closing parenthesis of the coordinate. Leaving them out will give an error.

enter image description here

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\newcommand\rya{1.8}
\begin{document}
\begin{tikzpicture}
\fill (0,0) rectangle +(1,\rya);
\fill (1.1,0) rectangle +(1,{floor(\rya)});
\end{tikzpicture}
\end{document}

You must log in to answer this question.

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