In last weeks article I included some animations of some plots from the examples. While doing that I remembered that we have received a couple of questions recently about how to get result animations in a PowerPoint or a Website. In this article we will talk about the tool I use and give some tips on making the process better. And, it give me an excuse to write about some software other than ANSYS, Inc.
Animated GIFs and Why we Need Them
As you know, an animation is simply a series of still images shown one right after another. When we create Video on a computer we generally make something with 30 still frames shown every second. Although the various formats for video have gotten much better, that is still a lot of pixels to send around. That makes a big file that may not be best for your web page or PowerPoint. However, with modern high-speed internet and fast computers, that is not the problem it used to be. It is still a concern.
What we really have to deal with is making sure that whatever we are using to present our animation can play it. Can the person’s web browser show it? Can PowerPoint show it? Although YouTube is a possibility more and more, you really want a portable format that you can imbed in your document or site and that everyone can see. If you research… the only format that fits that bill is an animated GIF.
The gif format is compact, and because the early Netscape Navigator browser supported it, it became a default format. Even Microsoft decided to support it. So, as in some ways, it is the least common denominator that works for everyone. Another cool thing is that the programs treat it as an image, not as a video or animation. You copy and paste it, insert it, place it, edit its size just like you would any JPEG, PNG, or TIFF image.
You can learn about the format on Wikipedia. But if the binary info that greats you on that page causes your eyes to glaze over, you only really need to know the following:
- It is a file format that supports multiple images all contained in one image file
- You can specify how long to play a given image (frame)
- It supports transparency
- It is a standard and all web browsers and PowerPoint will display it
- You can imbed it in a PowerPoint so you don’t have to worry about carrying your animation files around in a folder with your PowerPoint.
- It only supports 256 colors. This is the downside of GIF’s
Unfortunately non of the ANSYS products make an animated GIF file. They generally make an AVI, which is the most common video file, but something that most people can’t display on their website or put in a PowerPoint. So we need to convert the AVI to a GIF, or create a GIF from a series of images.
There is one option we should mention, and that is creating an Adobe Flash file. This is a more modern and capable format but it has problems. First and foremost, iPhones and iPads don’t display flash. Second, to show a flash animation in PowerPoint you have to make sure a special flash player is installed. So again, lowly GIF wins out.
GIF Movie Gear
I use a program called GIF Movie Gear. If you Google “AVI to GIF” you will find other tools. I picked this one because it had the features I wanted, it was cheap, and it works so far just fine. Over time, I have found it to be very robust as well. It is from a company called Gamani, and you can download a trial version or purchase it for $29.95. They have a nice website that lists all the features and offers some tutorials at: www.gamani.com
Once you have it installed check it out. If you have not tried similar tools in the past, go through the tutorial. It is worth the time.
For the ANSYS user, here are the important features:
- It will import an AVI and break it into individual images (frames)
- You can crop and resize
- You can set the speed of the animation
- It is easy to use (important, since if you are like me you only need it once in a while)
- You can easily make a ping-pong animation (copy frames then reverse them)
- You can make an animation by reading in a series of images (important for MAPDL users that want to make a high quality animation)
There are a ton more features, but these are the ones that matter to us ANSYS types.
Building Animations from Images
If you are using Mechanical APDL (MAPDL) you can use the ANIM command to build an animation of your model as an AVI. The problem with this is that the AVI file format that ANSYS uses compresses the images to save space, and to do so it really reduces the quality of the image. So instead, you can write your own animation macro and save a PNG file for each frame, then use GIF Movie Gear to make an animation.
To learn about how to make the images for your own animation, check out an old Focus article in Issue 49 from 2006, on page 6. It talks about the program we used to use to make an AVI instead of a GIF, but it works the same. You basically make a plot and save it as a PNG then modify your image and make the next one. We use that macro in the examples below and put it here for you to use. Take a good long look at it
You probably also want to reread (because I know you read it when we put it out) the more recent article on making pretty images from March of this year.
A Simple Example
To get the gist of how this all works, let’s build a simple tower model, put a pressure on the side, then animate it’s displacement. Download this macro and run it in MAPDL. If you look at the macro the last thing it does is make a contour plot of the total deflection (PLNSOL, U, SUM). This is what we want to animate.
So we simply type: “agif_anm1,10” into the command line to run the animation macro and it will make 10 PNG file. Look in your working directory and you will see twrexmp000.png through twrexmp009.png. These are the frames. Now on to making our GIF.
Start GIF Movie Gear and you will get the little start wizard:
Click on Insert Frames. This opens a file selection dialog box. Shift-select the 10 frames we just made and click open:
You will now see the upper right corner of the first frame… Don’t panic. this is the size of your image and the window is small. Click the little zoom in icon (magnifying glass with a minus sign) until you see a couple of frames. If you click the play icon, you will see your animation play very fast. Not what we want.
So the first thing we will do is change the animation speed by changing the duration of each frame. It is 0 by default. Go to Animation->Timing and it will show your hyper animation again. At the bottom, change the 0 to a 20 and hit return:
That calmed things down a bit. Close that window.
At this point you can simply save your animation and be done: File->Save and give it a name. And this is what you get:
The Blogging software resizes it. Click on the image to get the full size version.
Changing the Size
That may not be the shape, size, or content you want. To resize the image, use Animation->Resize:
Make sure that “Maintain aspect ratio” is checked. If you don’t, your image can get distorted. Then set the width or height to what you want. I’ll use a width of 400. Make sure the Bicubic is picked for your resizing. The other method is slower to run but makes bad images unless you have only a few colors. If you save this image you get the following:
Now, we may want to crop. We do that the same way: Animation->Crop. Now this is the only feature I don’t like. It shows the image in a small window.
So click on the Zoom In icon till you can see your image and drag to where you want it and click OK. Save that and you get:
One of the coolest things about GIF files is that you can tell the display program to not show a certain color, to make your image transparent. This is great for PowerPoints. To do this you need to mark one of the colors in your animation as “transparent.”
Go to Animation->Properties then click on the Global Frame tab:
Click on Transparent and it will bring up your color Pallet. Click on the black background or the black color in the table and that will be the transparent color. Now you need to set the bottom menu to “Restore to Background before drawing next frame”. If you don’t do this you will see ghosting.
Click OK. Save that and you get:
Not too exciting on this blog because the background is white. But imagine we had some fancy background. Copy and paste this into your corporate PowerPoint template and you will see:
Converting for AVI’s
What, you are not a gray-haired throwback to a past time. You use CDF Post or ANSYS Mechanical? You can skip a lot of the first steps and just go straight from an AVI to an Animated GIF.
Regardless of which tool you are using, you simply need to save an AVI to get started. For ANSYS Mechanical you do that by using the animation viewer to get the animation you want then click on the “Export Video File” Icon. Remember to make sure you have turned off the fancy Aero window stuff.
To make a CFD animation read Clinton’s Article
Now that you have the AVI file you can make a GIF. Start GIF Movie Gear and click on Open File this time. Choose the AVI and you will see all the frames in the AVI (zoom out if you need to). If you like what you see, just do a File->Save As and save as a GIF.
Just like the animations made from images, you can adjust the size of the image, crop, and set animations.
One thing you may notice is the banding on the background. This is in the AVI due to compression in the AVI. So if you are making animation we recommend you create a solid background (set in the project schematic->Tools->Options->Appearance) :
And once you have done that, you can use transparency:
Other Things You Should Know
When setting transparencies above we talk about making sure it says: “Restore to Background before drawing next frame” If you don’t, this is what your animation will look like:
For debugging it is kind of a pain to place in PowerPoint then view as slide show. A faster way to view an animated GIF is to RMB on it in the explorer and say Open With… and choose Internet Explorer. You can also drag it into your browser. Much faster.
The program has an Undo. Use it. Try stuff, save the file, look at it, then undo if you need to.
Another thing to be aware of is Ping-Pong. If you remember our first animation of the deflected tower, it only goes to the max deflection then snaps back to the beginning. It would be much nicer if it went back. You can do that by going to Animation->Rearrange Frames –>Ping-Pong Animation.
Now save and you have an “up and back” animation. The original is on the left, the ping-pong is on the right.
This tool is also a great way to grab a single frame from an animation. Say you have an animation and you need a picture, and you don’t want to go back into the program to make it. Simply read the AVI into this program, find the frame you want, then do a File->Save As. Pick your format and set “Save as Style” to Individual Image(s). Then select the “Only selected frames(s)”
That is about it. I hope this will help you make better presentations and cool websites.
Do you have seizures yet?