![Let's look at all the squares that can be formed by connecting points in our grid](https://97286c.a2cdn1.secureserver.net/wp-content/uploads/2023/04/dots-and-squares-.gif)
Animated GIFs
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.
Generating Images
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.
![Exported images for the animated GIF file](https://97286c.a2cdn1.secureserver.net/wp-content/uploads/2023/05/Frames.png)
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:
![Animated GIF showing squares from a grid of dots](https://97286c.a2cdn1.secureserver.net/wp-content/uploads/2023/04/dots-and-squares-.gif)
And here is the random order animated GIF:
![Animated GIF showing squares from a grid of dots in random order](https://97286c.a2cdn1.secureserver.net/wp-content/uploads/2023/05/dots-and-squares-5-1.gif)
Leave a Reply