show rotating spinner when block download out of date, tick otherwise
[novacoin.git] / scripts / make_spinner.py
1 #!/usr/bin/env python
2 # W.J. van der Laan, 2011
3 # Make spinning .mng animation from a .png
4 # Requires imagemagick 6.7+
5 from __future__ import division
6 from os import path
7 from PIL import Image
8 from subprocess import Popen
9
10 SRC='img/reload_scaled.png'
11 DST='../src/qt/res/movies/update_spinner.mng'
12 TMPDIR='/tmp'
13 TMPNAME='tmp-%03i.png'
14 NUMFRAMES=35
15 FRAMERATE=10.0
16 CONVERT='convert'
17 CLOCKWISE=True
18
19 im_src = Image.open(SRC)
20
21 if CLOCKWISE:
22     im_src = im_src.transpose(Image.FLIP_LEFT_RIGHT)
23
24 def frame_to_filename(frame):
25     return path.join(TMPDIR, TMPNAME % frame)
26
27 frame_files = []
28 for frame in xrange(NUMFRAMES):
29     rotation = (frame + 0.5) / NUMFRAMES * 360.0
30     if CLOCKWISE:
31         rotation = -rotation
32     im_new = im_src.rotate(rotation, Image.BICUBIC)
33     outfile = frame_to_filename(frame)
34     im_new.save(outfile, 'png')
35     frame_files.append(outfile)
36
37 p = Popen([CONVERT, "-delay", str(FRAMERATE), "-dispose", "2"] + frame_files + [DST])
38 p.communicate()
39
40
41