This is copied from a larger project that lets you flip through multiple animations, so there's no defsketch
here. If you want to get it up and running, you can insert the code into the fun-mode example.
The basic way this works is that we have a vector that basically determines the size of each square. Each frame, we make each one a bit bigger. Since larger objects appear closer and should look like they're moving faster, we want to make them a percentage bigger rather than a constant amount.
When using Quil and live reloading, the state tends to get out of whack, so I use a few tricks to help reset it if necessary:
initialized?
andinitialize-state
functions that check if the state seems to be invalid, and reset it, respectively.- Binding the R key to a function that clears the state. This causes
initialized?
to be false andinitialize-state
to add the animation-specific starting state. - Namespaced keywords (notice the double semicolons
::positions
). This is unnecessary for most Quil projects, but is good here because there are multiple animations, each in its own namespace and that way they won't clobber each other's state if they happen to have a keyword of the same name.