[cairo-commit] pycairo/examples .cvsignore, 1.1, 1.2 hering.py, NONE, 1.1 spiral.py, NONE, 1.1

Carl Worth commit at pdx.freedesktop.org
Tue Nov 2 17:24:08 PST 2004


Committed by: cworth

Update of /cvs/cairo/pycairo/examples
In directory gabe:/tmp/cvs-serv11216/examples

Modified Files:
	.cvsignore 
Added Files:
	hering.py spiral.py 
Log Message:

        * examples/spiral.py:
        * examples/hering.py: New examples from Steve Chaplin to
        demonstrate PNG and PS output.

        * cairo/pycairo-context.c (pycairo_set_target_ps)
        (pycairo_set_target_png): Fixes from Steve Chaplin.
        (pycairo_set_pattern): Disable set_pattern as this wrapper is
        currently broken.
        (pycairo_methods): Fix binding of copy_page.

        * cairo/Makefile.am (gtk_la_LIBADD): Add CAIRO_LIBS which was
        mistakenly dropped in a recent change.


Index: .cvsignore
===================================================================
RCS file: /cvs/cairo/pycairo/examples/.cvsignore,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- .cvsignore	23 Sep 2003 12:50:27 -0000	1.1
+++ .cvsignore	3 Nov 2004 01:24:06 -0000	1.2
@@ -1,2 +1,4 @@
 *.pyc
 *.pyo
+hering.png
+spiral.ps

--- NEW FILE: hering.py ---
#!/usr/bin/env python
"""cairo/cairo-demo/png/hering.c translated into Python
"""

from math import pi
import cairo

WIDTH  = 300
HEIGHT = 600

def draw_hering (ctx, width, height):
    LINES= 32
    MAX_THETA = .80 * pi * 2
    THETA_INC = 2.0 * MAX_THETA / (LINES-1)

    ctx.set_rgb_color (0, 0, 0)
    ctx.set_line_width (2.0)

    ctx.save()

    ctx.translate (width / 2, height / 2)
    ctx.rotate (MAX_THETA)
	
    for i in range (LINES):
        ctx.move_to (-2 * width, 0)
        ctx.line_to (2 * width, 0)
        ctx.stroke()
	    
        ctx.rotate (- THETA_INC)

    ctx.restore()

    ctx.set_line_width (6)
    ctx.set_rgb_color (1, 0, 0)

    ctx.move_to (width / 4.0, 0)
    ctx.rel_line_to (0, height)
    ctx.stroke()

    ctx.move_to (3 * width / 4.0, 0)
    ctx.rel_line_to (0, height)
    ctx.stroke()


try:
    fileObject = file('hering.png', 'wb')
except IOError, exc:
    raise SystemExit("%s: %s" % (exc.filename, exc.strerror))

ctx = cairo.Context()
ctx.set_target_png (fileObject, cairo.FORMAT_ARGB32, WIDTH, HEIGHT)

ctx.rectangle (0, 0, WIDTH, HEIGHT)
ctx.set_rgb_color (1, 1, 1)
ctx.fill()

draw_hering (ctx, WIDTH, HEIGHT)

ctx.show_page()
fileObject.close()

--- NEW FILE: spiral.py ---
#!/usr/bin/env python
"""cairo/cairo-demo/png/spiral.c translated into Python
Modified to produce PostScript output
"""

import cairo

DPI = 72.0
PAGE_W_IN, PAGE_H_IN = 8.5, 11.0
WIDTH_IN, HEIGHT_IN = 4, 4

def draw_spiral (ctx, width, height):
    wd = .02 * width
    hd = .02 * height

    width -= 2
    height -= 2

    ctx.move_to (width + 1, 1-hd)
    for i in range(9):
	ctx.rel_line_to (0, height - hd * (2 * i - 1))
	ctx.rel_line_to (- (width - wd * (2 *i)), 0)
	ctx.rel_line_to (0, - (height - hd * (2*i)))
	ctx.rel_line_to (width - wd * (2 * i + 1), 0)

    ctx.set_rgb_color (0, 0, 1)
    ctx.stroke()


try:
    fileObject = file('spiral.ps', 'wb')
except IOError, exc:
    raise SystemExit("%s: %s" % (exc.filename, exc.strerror))

ctx = cairo.Context()
ctx.set_target_ps (fileObject, PAGE_W_IN, PAGE_H_IN, DPI, DPI)

# center on page
tx = (PAGE_W_IN - WIDTH_IN ) * DPI / 2.0
ty = (PAGE_H_IN - HEIGHT_IN) * DPI / 2.0
matrix = cairo.Matrix (tx=tx, ty=ty)
ctx.set_matrix (matrix)

width, height = WIDTH_IN *DPI, HEIGHT_IN *DPI
ctx.rectangle (0, 0, width, height)
ctx.set_rgb_color (1, 1, 1)
ctx.fill()

draw_spiral (ctx, width, height)

ctx.show_page()
fileObject.close()




More information about the cairo-commit mailing list