2
# [SNIPPET_NAME: Hering]
3
# [SNIPPET_CATEGORIES: Cairo]
4
# [SNIPPET_DESCRIPTION: Generate a hering]
5
# [SNIPPET_DOCS: http://www.tortall.net/mu/wiki/CairoTutorial]
6
# [SNIPPET_LICENSE: MPL]
15
def draw_hering (ctx, width, height):
17
MAX_THETA = .80 * math.pi * 2
18
THETA_INC = 2.0 * MAX_THETA / (LINES-1)
20
ctx.set_source_rgb (0, 0, 0)
21
ctx.set_line_width (2.0)
25
ctx.translate (width / 2, height / 2)
26
ctx.rotate (MAX_THETA)
28
for i in range (LINES):
29
ctx.move_to (-2 * width, 0)
30
ctx.line_to (2 * width, 0)
33
ctx.rotate (- THETA_INC)
37
ctx.set_line_width (6)
38
ctx.set_source_rgb (1, 0, 0)
40
ctx.move_to (width / 4.0, 0)
41
ctx.rel_line_to (0, height)
44
ctx.move_to (3 * width / 4.0, 0)
45
ctx.rel_line_to (0, height)
49
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
50
ctx = cairo.Context(surface)
52
ctx.set_source_rgb (1, 1, 1)
53
ctx.set_operator (cairo.OPERATOR_SOURCE)
56
draw_hering (ctx, WIDTH, HEIGHT)
58
# the output is written to your home directory
59
surface.write_to_png(os.path.expanduser("~") + '/hering.png')