home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / python-cairo / examples / spiral.py < prev    next >
Encoding:
Python Source  |  2006-01-20  |  782 b   |  37 lines

  1. #!/usr/bin/env python
  2. """cairo/cairo-demo/png/spiral.c translated into Python
  3. """
  4.  
  5. import cairo
  6.  
  7. WIDTH, HEIGHT = 600, 600
  8.  
  9. def draw_spiral (ctx, width, height):
  10.     wd = .02 * width
  11.     hd = .02 * height
  12.  
  13.     width -= 2
  14.     height -= 2
  15.  
  16.     ctx.move_to (width + 1, 1-hd)
  17.     for i in range(9):
  18.     ctx.rel_line_to (0, height - hd * (2 * i - 1))
  19.     ctx.rel_line_to (- (width - wd * (2 *i)), 0)
  20.     ctx.rel_line_to (0, - (height - hd * (2*i)))
  21.     ctx.rel_line_to (width - wd * (2 * i + 1), 0)
  22.  
  23.     ctx.set_source_rgb (0, 0, 1)
  24.     ctx.stroke()
  25.  
  26.  
  27. surface = cairo.ImageSurface (cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
  28. ctx = cairo.Context(surface)
  29.  
  30. ctx.set_source_rgb (1, 1, 1)
  31. ctx.set_operator (cairo.OPERATOR_SOURCE)
  32. ctx.paint()
  33.  
  34. draw_spiral (ctx, WIDTH, HEIGHT)
  35.  
  36. surface.write_to_png('spiral.png')
  37.