Sometimes you've created a nice simulation/animation, and you want to show it off. While you can record a video, that might be a bit overkill to break out your video recording if you just want something to post on twitter. That's where what [GIF](https://en.wikipedia.org/wiki/GIF)s are for.
Also, GIF is pronounced GHIF, not JIF as JIF is not only [peanut butter](https://en.wikipedia.org/wiki/Jif_%28peanut_butter%29), it is also a [different image format](https://filext.com/file-extension/JIF).
## How are we making the GIF?
We're going to create a function using the [gif crate](https://docs.rs/gif/) to encode the actual image.
let mut encoder = image::gif::Encoder::new(output);
for mut data in frames {
let frame = image::gif::Frame::from_rgba_speed(size, size, &mut data, speed);
encoder.encode(&frame)?;
}
Ok(())
}
``` -->
All we need to use this code is the frames of the GIF, how fast it should run, and the size of the GIF (you could use width and height seperately, but I didn't).
## How do we make the frames?
If you checked out the [windowless showcase](../windowless/#a-triangle-without-a-window), you'll know that we render directly to a `wgpu::Texture`. We'll create a texture to render to and a buffer the copy the output to.
save_gif("output.gif", &mut frames, 1, texture_size as u16).unwrap();
```
That's the gist of it. We can improve things using a texture array, and sending the draw commands all at once, but this gets the idea across. With the shader I wrote we get the following GIF.