From: P. G. C. <ozr...@gm...> - 2008-11-24 08:48:59
|
Hi all. I've been using vpython for simulating a vibrating string and wanted to capture an animated gif as an example of my results for web publishing. There're several methods explained in the FAQ <http://vpython.org/FAQ.html>, but none of them was exactly what I was looking for, so I've choosen my own way and here it is explained (hope to be usefull): I use imagemagick's import command to take a screenshot of each frame. For easily capturing just one window I need to know it's id, so I read it through xprop. I also use date to name each image and keep them in order. - In a file named id.sh I have: xprop | grep 'window id' | grep 'COLORMAP' | cut -d \# -f 2 | tr -d ' ' - In my .py, after creating the scene window: id=string.rstrip(os.popen("sh id.sh").readlines()[0]) - When this command is read, the mouse cursor will ask me for clicking on the window I want to capture, and it's id will be saved as "id". - Then, each frame will be captured as (folder "tmp" should exist): os.popen("import -window "+id+" tmp/$(date +'%s%N').png") - Let the script run and after finished, use imagemagick or the gimp to generate the animation: 1. With imagemagick, in tmp folder: convert -delay 0.04 -loop 1 *.png output.gif 2. With gimp, you can simply open the first one and then "open as layers" all the others. Save as gif, and follow the steps for an animated one (really easy). You can also apply some filters for optimization. And that's all folks! Here're a couple of example gifs generated: <http://nuc5.fis.ucm.es/viajeras.gif> <http://nuc5.fis.ucm.es/fourier.gif> (please, excuse me for my bad English) -- (^< -- http://ozrocberg.blogspot.com //'\ V_/_ |