I am trying to see if I can replicate CSS stager animation in d3. This is what I tried.
The motion for blue and green circles was done through respectively CSS and d3. I was hoping to achieve the same animation for green circles as the blue ones. But they are not the same.
I donât have the bandwidth right now, but the idea is that you animate all elements via the same transition instead of starting a separate one in .each(). If you specify a custom easing you can then offset t based on the element index, e.g. (t + i / 3) % 1.
In seems very odd to me to attempt to generate this animation as an infinite sequence of transitions when itâs very easy to describe the motions exactly as three sinusoids that happen to be slightly out of phase. More generally, CSS is not a programming language and I think itâs a mistake to try reproduce animations produced by CSS by emulating the code that you see there.
I would generate this motion using something like the techniques in this notebook. The key step is to describe the displacement of the i^{\text{th}} particle as
-Math.cos((t - T0 - 100 * i) / 400)
where t is the current time, T0 is the starting time, and i is the index of the particle. If you want to sync this with some other animation, of course, youâll need to tweek the parameters.
@mcmcclur many thanks for this. One follow up Q; in order for me to apply this in the prod item, I need to be generating the parameters programmatically. Hence, the question- how are you coming up with 100 and 400 in the following expression?
@mootari sounds like an interesting approach; however, I could not make that work. Whenever you have time and get a chance, if you can please demonstrate the idea you are proposing would be great.
Iâm guessing you know that in an expression involving time T like
-\cos(\omega T - \varphi)
that \varphi controls the phase and that \omega controls the frequency, which the reciprocal of the period. In the formula you refer to,
T = t-T_0,
\omega = 1/400 and
\varphi = i/4.
These are really just parameters to speed up/slow down or shift the motion. I didnât do anything technical to compute those values; I just fiddled with them until the animation looked something like what you want. I suppose it might be worth mentioning that, if we take
\omega = 2\pi/1000,
then the frequency should be 1s. That is, we should observe one complete back and forth motion every second.
If you can obtain whatever frequency and phase arises from the process youâre modelling, you should be able to fit the motion.