I’ve done a handful of animations lately:
- Gas Prices – Animated Bar Chart for Excel
- Gas Prices – Animated Bar Chart for Excel 2
- Gapminder for Excel
- Rolling Wheel Animation
This example shows the position and path of a moving projectile which is launched at a given velocity and angle. The math is high school physics, with a little calculus and trig thrown in. If you want to see that, download the workbook (link below), or consult a textbook or a smart kid.
The workbook has a data entry area and my usual animation controls. When the angle and velocity are entered, a results table shows how long the projectile will be in flight, how long it will take to get to maximum altitude, and what altitude and distance the projectile will reach. Some assumptions were made to simplify the model, as in all physics problems. The ground is flat at sea level, and the effect of air resistance is neglected.
Set the angle to 45° and the velocity to 100 m/s, and start the animation.
Here is the end of the animation for 30° and 7 m/s.
And this one is for 75° and 100 m/s
The workbook containing this model can be downloaded here: Ballistics.zip.
DaleW says
Jon,
Sometimes — as when GapMinder.org excels — animation is very useful because we’ve run out of spatial dimensions to visualize our data, and we need time to serve as an extra dimension for grasping the effect of time.
Other times — using animation such as this ballistics demo provides — the animation might serve as a cute icebreaker: an orienting introduction that helps draw the audience into considering more complex charts with higher data density.
Thank you for teaching such methods. I’m trying to find situations where such Excel animations could be useful.
Peter Lambrineas says
Greetings Jon,
I’ve observed that your Excel Ballistics animation file behaves differently when run in Excel 2010 or Excel 2016 on the same PC. (The effects below can be observed with the default data set, but are easier to observe if the number ot data points used for the animation are increased significantly e.g.>1000).
Behaviour in Excel 2016:
Click on either the Forward or Reverse buttons, and while the animation is still in progess click on the opposite direction button without using the Pause button. The animation changes direction without any problems. Can continue to click on the opposite direction button (while the animation is still active) to the current direction of the animation and the animation continues to work without any problems.
Behaviour in Excel 2010:
Firstly, the speed of the animation in Excel 2010 is about 2-4 times faster than the animation when run in Excel 2016. Any idea of why this may be occuring?
Secondly; Click on either the Forward or Reverse buttons, and while the animation is still in progess click on the opposite direction button without using the Pause button. The direction of the animation changes and the mouse cursor now turns into the “busy” mouse symbol and it remains in the “busy” mode until the animation reaches the end of the current animation direction, at which time it changes direction automatically and the animation continues to move in this direction until it reaches the end of the now current animation direction, at which time the animation stops. At some point on this last “leg” of the animation the mouse cursor changes from the “busy” symbol back to the normal mouse cursor. However, if at any time in the above process while the mouse cursor is in the “busy” mode an attempt is made to click on any of the animation control buttons Excel 2010 will crash and will need to be restarted.
Any ideas about how to modify the Ballistics animation file VBA code so the above User actions do not cause Excel 2010 to crash?
Thanks for your excellent site.
Cheers, Peter
Jon Peltier says
Peter –
Animations worked very smoothly and very quickly in Excel versions up to 2003. With Excel 2007 came a new, buggy chart engine. Animations were a disaster, with very slow, jerky motion. Sometimes intermediate states weren’t even displayed. Excel 2010 was a bit better, still erratic, but by then I’d given up on animated charts in Excel.
Not long ago (early in 2019) I had cause to build an animated chart, in Office 365, and I was surprised how well it ran. Not as well as I recall animations working in 2003, for sure, but relatively smoothly. I had to play some tricks with DoEvents, but in fact, most of the other tricks I may have tried and which others have tried and posted about online, had little or no effect on the animation.
I’ve been meaning to write about my recent experience with animations, and I still may do so. Keep posted.
Peter Lambrineas says
Greetings Jon,
Thanks for your response to my previous post. Based on you comments I did some further investigation. I’ve run the Ballistics animation using Excel 2003, 2007, 2010, 2013 and 2016. The behaviour of the Ballistics animation in Excel 2003 and 2007 is identical to the behaviour I described for Excel 2010 (except for the busy cursor, none in 2003, an hour glass in 2007 and an animated circle in 2010). Excel 2013 behaviour for the Ballistics animation is identical to that previously described for Excel 2016.
I tried splitting the “bPause “ parameter into two, a “bPauseR” and a “bPauseF” parameter such that if the Forward direction button is clicked it would first set “bPauseR” to “True” and if the Reverse direction button was clicked it would set the “bPauseF” parameter to “True”. After updating the Forward_Click, Reverse_Click and Pause_Click subroutines to use these new parameters, there is some improvement in the Ballistics animation behaviour in Excel 2003, 2007 and 2010.
When either the Forward or Reverse buttons are clicked and the opposite direction button is then clicked while the animation is still active without first clicking on the Pause button the animation will now stop when it first reaches the end of the animation, instead of reversing direction and continuing in the opposite direction to the other end of the animation before stopping. However, if at any time while the mouse cursor is in the “busy” mode (i.e. between the second direction click and reaching the end of the animation) an attempt is made to click on any of the animation control buttons, Excel 2003, 2007 and 2010 will still crash.
Do you have any suggestions about how to alter the VBA code to avoid/prevent the above crash behaviour when the Pause button is not used prior to changing directions during and active Ballistics animation?
Thanks for your help.
Cheers, Peter
Jon Peltier says
Peter –
I recently changed the handling routines to the following. There is a variable
iDirection
that tracks which way the animation is running, 1 forward, -1 reverse, 0 paused.Click the Forward button, iDirection changes to 1 and the forward loop starts from the current position; click it again and iDirection changes to 0. While looping, if iDirection is not 1 (i.e., a button was clicked), exit the loop.
Click the Reverse button, iDirection changes to -1, and the reverse loop starts from its current position; click it again and iDirection changes to 0. While looping, if iDirection is not -1 (i.e., a button was clicked), exit the loop.
Click the Pause button, and iDirection changes to 0.
Forward and Reverse now function like toggles, click once to go, click again to stop. When iDirection changes to 0 because of any button being clicked, the animation stops. When animation is going in one direction, clicking the other button reverses the animation.
Peter Lambrineas says
Greetings Jon,
Thanks for sharing your updated code for handling the animation control button routines in the Ballistics animation file. Your code is certainly more elegant than my approach of splitting the bPause parameter into two. Unfortunately however, your updated code displays exactly the same behaviour as my initially modified code, it still crashes Excel 2003, 2007, and 2010 if the Pause button is not used between successive presses of the Forward and Reverse buttons (a third button press – irrespective of which, while the mouse cursor is in the busy mode is what actually causes the crash).
Given that this problem seemes to be associated with the Forward and Reverse buttons, I thought to alter the Forward and Reverse buttons from “Form Control” buttons to “ActiveX Control” command buttons and then set the Enabled parameter to “False” i.e. grey out (disable) the opposite direction command button until the current direction command button was no longer active.
I used the same code from my modified “Forward_Click” and “Reverse_Click” Form Control subroutines in the new, ”ForwardButton_Click” and ReverseButton_Click” ActiveX Control subroutines respectively. After making appropriate adjustments for the scope of subroutines and dimension definitions, the new ActiveX Control “Forward” and “Reverse” command buttons can be pressed repeatedly without using the Pause button and Excel 2003, 2007, 2010, 2013 and 2016 will not crash.
Hence, it was not necessary to use the “Enabled” parameter to disable the opposite direction button. Simply changing from “Form Control” to “ActiveX Control” command buttons for the Forward and Reverse buttons was sufficient to correct the previous crash behaviour and ensure that in this updated version of the Ballistics animation file, no combination of animation control button presses will cause a crash of Excel in all versions of Excel from 2003 to 2016 inclusive.
I hope the above will be of some use to you and other users of your web site.
Cheers, Peter
Jon Peltier says
Hi Peter –
I hadn’t tried my newest code in older versions than 2016, so after reading your comment I did so. Several times I crashed both 2010 and 2007 regularly while clicking the forward and reverse buttons in close succession. 2016 and 2013 were not subject to this problem. This doesn’t bother me too much, since I no longer support Excel 2007 (nor does Microsoft) and it’s rare that any clients use 2010 any longer.
When I replaced the Form buttons with ActiveX buttons, using the same code, 2010 and 2007 no longer crashed, and 2013 and 2016 showed no difference.
I would not have expected this, because sometimes the ActiveX buttons suffer from strange behavior. And you have to keep in mind that ActiveX buttons will not work on the Mac.