| 1 |
|
| 2 |
"""cairo/cairo-demo/png/hering.c translated into Python""" |
| 3 |
|
| 4 |
import math |
| 5 |
|
| 6 |
|
| 7 |
def draw(ctx, width, height): |
| 8 |
LINES = 32 |
| 9 |
MAX_THETA = .80 * math.pi * 2 |
| 10 |
THETA_INC = 2.0 * MAX_THETA / (LINES - 1) |
| 11 |
|
| 12 |
ctx.set_source_rgb(0, 0, 0) |
| 13 |
ctx.set_line_width(2.0) |
| 14 |
|
| 15 |
ctx.save() |
| 16 |
|
| 17 |
ctx.translate(width / 2, height / 2) |
| 18 |
ctx.rotate(MAX_THETA) |
| 19 |
|
| 20 |
for _ in range(LINES): |
| 21 |
ctx.move_to(-2 * width, 0) |
| 22 |
ctx.line_to(2 * width, 0) |
| 23 |
ctx.stroke() |
| 24 |
|
| 25 |
ctx.rotate(- THETA_INC) |
| 26 |
|
| 27 |
ctx.restore() |
| 28 |
|
| 29 |
ctx.set_line_width(6) |
| 30 |
ctx.set_source_rgb(1, 0, 0) |
| 31 |
|
| 32 |
ctx.move_to(width / 4.0, 0) |
| 33 |
ctx.rel_line_to(0, height) |
| 34 |
ctx.stroke() |
| 35 |
|
| 36 |
ctx.move_to(3 * width / 4.0, 0) |
| 37 |
ctx.rel_line_to(0, height) |
| 38 |
ctx.stroke() |