jgtrosh

wandgiftest.py

Sep 28th, 2013
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. from wand.image import Image
  4. from wand.drawing import Drawing
  5. from wand.color import Color
  6. import math
  7.  
  8. def drawcircle(cx, cy, r, ns, c):
  9.     draw.fill_color = Color(c)
  10.     sa = 2*math.pi/ns
  11.     for s in xrange(ns):
  12.         x1 = cx + r*math.cos(s*sa)
  13.         y1 = cy + r*math.sin(s*sa)
  14.         x2 = cx + r*math.cos((s+1)*sa)
  15.         y2 = cy + r*math.sin((s+1)*sa)
  16.         draw.line((x1, y1), (x2, y2))
  17.  
  18. nf = 60
  19. fa = 2*math.pi/nf
  20.  
  21. with Image(width=400, height=400) as img:
  22.     draw = Drawing()
  23.     drawcircle(200, 200, 100, 100, 'black')
  24.     circle1 = draw
  25.     circles = []
  26.     for f in xrange(nf):
  27.         frm = Image(width=400, height=400)
  28.         circle1(frm)
  29.         draw = Drawing()
  30.         cx = 200 + 100*math.cos(f*fa)
  31.         cy = 200 + 100*math.sin(f*fa)
  32.         drawcircle(cx, cy, 100, 50, 'black')
  33.         draw(frm)
  34.         for circle in circles:
  35.             circle(frm)
  36.         if f % (nf/6) == 0:
  37.             circles.append(draw)
  38.         img.sequence.append(frm)
  39.         img.sequence[len(img.sequence)-1].delay = 1
  40.         print("frame %d" % f)
  41.     del img.sequence[0]
  42.     img.format = 'gif'
  43.     img.save(filename="test.gif")
Advertisement
Add Comment
Please, Sign In to add comment