| 1 | #!/usr/bin/env python |
| 2 | """cairo/cairo-demo/png/spiral.c translated into Python""" |
| 3 | |
| 4 | |
| 5 | def draw(ctx, width, height): |
| 6 | wd = .02 * width |
| 7 | hd = .02 * height |
| 8 | |
| 9 | width -= 2 |
| 10 | height -= 2 |
| 11 | |
| 12 | ctx.move_to(width + 1, 1 - hd) |
| 13 | for i in range(9): |
| 14 | ctx.rel_line_to(0, height - hd * (2 * i - 1)) |
| 15 | ctx.rel_line_to(-(width - wd * (2 * i)), 0) |
| 16 | ctx.rel_line_to(0, -(height - hd * (2 * i))) |
| 17 | ctx.rel_line_to(width - wd * (2 * i + 1), 0) |
| 18 | |
| 19 | ctx.set_source_rgb(0, 0, 1) |
| 20 | ctx.stroke() |