Is there a simple way to make and save an animation with Pygame?

让人想犯罪 __ 提交于 2020-01-12 10:51:14

问题


I made a very simple fractal generator that prints out each step; I want to put it in a presentation I made. The tool with which I'm making the presentation obviously doesn't support pygame, is there any way to save it as a video? Preferably as an animated .gif or the like.


回答1:


Not directly. But you can save a screencast of your program with one of the many available utilities that do this.

I don't know about Windows or OSX, but if you are on Ubuntu or other gnome-based desktop you can either use the gnome-shell built-in functionality (standard keybinding is Control+Shift+Alt+R) or istanbul (more info here).

Googling screencast <your-os-here> should help if you are not on Ubuntu.

EDIT: One you saved the video you can easily convert its format - if you so like - with other utilities. Here is a how-to on how to convert from ogv (the standard output for linux screencasting) to animated gif.




回答2:


http://visvis.googlecode.com/hg/vvmovie/images2gif.py -- python package for making animated gifs.

I used it recently for the first time (in conjunction with pygame), so this is not guaranteed to be best practices, but it did work. Here's the code, here's the result

--

UPDATE: Over time I've decided that images2gif.py is mediocre (produces unnecessarily large files) and unreliable (sometimes randomly fails to load and run). My new preference is to call imagemagick using subprocess. Example code here. Here is a shorter example in Windows (from the comments).



来源:https://stackoverflow.com/questions/10922285/is-there-a-simple-way-to-make-and-save-an-animation-with-pygame

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!