This is the third in a series of articles about How Many Squares can be drawn using a particular grid of dots.
How Many Squares? (1. Interactive Chart) showed how I built an interactive chart, so someone could use a scrollbar to show any of the squares that can be drawn using the matrix of dots.
How Many Squares? (2. Animated Chart) shows how I used VBA to animate my chart, cycling through all of the squares formed using these dots.
How can I talk about animated charts without showing an animated image?
To make an animated GIF, you need a series of images and a program to combine them into a single animated file.
To make the individual images, I added a
Chart.Export command to the VBA procedure that cycled through the charts, and I removed the timer that paused the display of each image for a specified time.
Sub CycleThroughTheSquares() Dim iMin As Long, iMax As Long iMin = wsDotsAndSquares.Range("ScrollMin").Value2 iMax = wsDotsAndSquares.Range("ScrollMax").Value2 Dim rNow As Range Set rNow = wsDotsAndSquares.Range("ScrollNow") Dim iNow As Long For iNow = iMin To iMax rNow.Value2 = iNow wsDotsAndSquares.Calculate DoEvents wsDotsAndSquares.ChartObjects(1).Chart.Export _ ThisWorkbook.Path & "\Frame" & Format(iNow, "00") & ".gif" Next rNow.Value2 = 0 End Sub
The result is this folder of exported images.
Creating the GIF
Now that I have my individual frames, how did I construct my GIF? My two favorite image editing programs, IrfanView and SnagIt, do not have the capability to combine individual frames into an animated GIF. But a simple web search turned up numerous free online GIF generators. I used EZGIF.com, which was easy to use and has capabilities that far exceed the requirements for my simple animated image. I uploaded the individual images, set a time for each to appear (I used 0.2 or 0.25 seconds), and in a moment I could download my animated picture.
Here is the resulting animated GIF:
And here is the random order animated GIF: