[cairo-commit] [cairo-www] src/pycairo.mdwn

Carl Worth cworth at freedesktop.org
Fri Jul 6 07:55:53 PDT 2007


 src/pycairo.mdwn |   30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

New commits:
commit 1b831ea6d093f3199a71f74d969fde7dcd7cc3d6
Author: vchahun <vchahun at gmail.com>
Date:   Fri Jul 6 07:55:52 2007 -0700

    Restoring the original example for archive.org (it was previously a copy of the ocaml copy of this program)

diff --git a/src/pycairo.mdwn b/src/pycairo.mdwn
index 3a1658b..0cec4aa 100644
--- a/src/pycairo.mdwn
+++ b/src/pycairo.mdwn
@@ -29,28 +29,30 @@ examples in the examples/ directory of the tarball release.
 
 This simple examples draws a blue triangle into a png file.
 
-	import cairo
+	#!/usr/bin/env python
 
-	width,height = 400,400
+	import cairo
 
-	# Cairo Setup
+	WIDTH, HEIGHT = 400, 400
 
-	surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) # Drawing surface
-	ctx = cairo.Context(surface) # Drawing context
+	# Setup Cairo
+	surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
+	ctx = cairo.Context(surface)
 
-	# Triangle
+	# Set thickness of brush
+	ctx.set_line_width(15)
 
-	ctx.move_to(200,100)
-	ctx.line_to(300,300)
-	ctx.rel_line_to(-200,0)
+	# Draw out the triangle using absolute coordinates
+	ctx.move_to(200, 100)
+	ctx.line_to(300, 300)
+	ctx.rel_line_to(-200, 0)
 	ctx.close_path()
 
-	ctx.set_line_width(15) # Set thickness of brush
-	ctx.set_source_rgb(0.1, 0.1, 0.5) # Set stroke color
-	ctx.stroke() # Stroke path
+	# Apply the ink
+	ctx.stroke()
 
-	# Output to PNG
-	surface.write_to_png("example.png")
+	# Output a PNG file
+	surface.write_to_png("triangle.png")
 
 Several other [[pycairo_resources|resources]] are available.
 


More information about the cairo-commit mailing list