One option for creating animated GIFs from your visual python program is add the pillow package that allows you to export images of your vpython window from within your program. You can then use GIMP to create an animation such as the one shown here.

To use python’s image library, you can install the “pillow” package, and then use the line

from PIL import ImageGrab

to import the necessary functionality. To take an image of your vpython display, add the following

im = ImageGrab.grab((0, 0, 600, 600))
im.save('filename.jpg')

This code specifies that the image should be taken starting at the top left of your screen and extending down 600 pixels and right 600 pixels.

Once you have created a set of images, you can create the animated GIF using GIMP as follows:

Open GIMP and go to File > Open as Layers

Select all your images and click “Open”

Go to Filters > Animation > Playback to see your animation

Go to Filters > Animation > Optimize for GIF

When you are ready, go to File > Export As

Rename the image with the “.gif” extension.

Select the “animation” checkbox and the frame rate

The visual python code used to create the animation of the simple pendulum above, is shown below. Notice that I set the window size for convenience, and I placed the image-grabbing code in a loop, but only took an image every five iterations.