[cairo-commit] pycairo/examples/cairo_snippets/snippets
arc_negative.py, NONE, 1.1 arc.py, NONE, 1.1 clip.py, NONE,
1.1 curve_rectangle.py, NONE, 1.1 curve_to.py, NONE,
1.1 fill_and_stroke2.py, NONE, 1.1 fill_and_stroke.py, NONE,
1.1 gradient.py, NONE, 1.1 __init__.py, NONE, 1.1 libsvg.py,
NONE, 1.1 operator_add.py, NONE, 1.1 operator_atop.py, NONE,
1.1 operator_atop_reverse.py, NONE, 1.1 operator_in.py, NONE,
1.1 operator_in_reverse.py, NONE, 1.1 operator_out.py, NONE,
1.1 operator_out_reverse.py, NONE, 1.1 operator_over.py, NONE,
1.1 operator_over_reverse.py, NONE, 1.1 operator_saturate.py,
NONE, 1.1 operator_xor.py, NONE, 1.1 path.py, NONE,
1.1 set_line_cap.py, NONE, 1.1 set_line_join.py, NONE,
1.1 text_align_center.py, NONE, 1.1 text_extents.py, NONE,
1.1 text.py, NONE, 1.1
Steve Chaplin
commit at pdx.freedesktop.org
Wed Apr 6 06:54:12 PDT 2005
- Previous message: [cairo-commit]
pycairo/examples/cairo_snippets c_to_python.py, NONE,
1.1 snippets_gtk.py, NONE, 1.1 snippets_png.py, NONE, 1.1
- Next message: [cairo-commit]
pycairo/examples/cairo_snippets/data freedesktop.svg, NONE,
1.1 home.svg, NONE, 1.1 romedalen.png, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Committed by: stevech1097
Update of /cvs/cairo/pycairo/examples/cairo_snippets/snippets
In directory gabe:/tmp/cvs-serv23095/examples/cairo_snippets/snippets
Added Files:
arc_negative.py arc.py clip.py curve_rectangle.py curve_to.py
fill_and_stroke2.py fill_and_stroke.py gradient.py __init__.py
libsvg.py operator_add.py operator_atop.py
operator_atop_reverse.py operator_in.py operator_in_reverse.py
operator_out.py operator_out_reverse.py operator_over.py
operator_over_reverse.py operator_saturate.py operator_xor.py
path.py set_line_cap.py set_line_join.py text_align_center.py
text_extents.py text.py
Log Message:
SC 2005/04/06
--- NEW FILE: arc_negative.py ---
xc = 0.5
yc = 0.5
radius = 0.4
angle1 = 45.0 * (M_PI/180.0) #/* angles are specified */
angle2 = 180.0 * (M_PI/180.0) #/* in radians */
snippet_normalize (cr, width, height)
cr.arc_negative (xc, yc, radius, angle1, angle2)
cr.stroke ()
#/* draw helping lines */
cr.set_rgb_color (1,0.2,0.2)
cr.set_alpha (0.6)
cr.arc (xc, yc, 0.05, 0, 2*M_PI)
cr.fill ()
cr.set_line_width (0.03)
cr.arc (xc, yc, radius, angle1, angle1)
cr.line_to (xc, yc)
cr.arc (xc, yc, radius, angle2, angle2)
cr.line_to (xc, yc)
cr.stroke ()
--- NEW FILE: arc.py ---
xc = 0.5
yc = 0.5
radius = 0.4
angle1 = 45.0 * (M_PI/180.0) #/* angles are specified */
angle2 = 180.0 * (M_PI/180.0) #/* in radians */
snippet_normalize (cr, width, height)
cr.arc (xc, yc, radius, angle1, angle2)
cr.stroke ()
#/* draw helping lines */
cr.set_rgb_color (1,0.2,0.2)
cr.set_alpha (0.6)
cr.arc (xc, yc, 0.05, 0, 2*M_PI)
cr.fill ()
cr.set_line_width (0.03)
cr.arc (xc, yc, radius, angle1, angle1)
cr.line_to (xc, yc)
cr.arc (xc, yc, radius, angle2, angle2)
cr.line_to (xc, yc)
cr.stroke ()
--- NEW FILE: clip.py ---
snippet_normalize (cr, width, height)
cr.arc (0.5, 0.5, 0.3, 0, 2 * M_PI)
cr.clip ()
cr.new_path () #/* current path is not
# consumed by cairo_clip() */
cr.rectangle (0, 0, 1, 1)
cr.fill ()
cr.set_rgb_color (0, 1, 0)
cr.move_to (0, 0)
cr.line_to (1, 1)
cr.move_to (1, 0)
cr.line_to (0, 1)
cr.stroke ()
--- NEW FILE: curve_rectangle.py ---
#/* a custom shape, that could be wrapped in a function */
x0 = 0.1 #/*< parameters like cairo_rectangle */
y0 = 0.1
rect_width = 0.8
rect_height = 0.8
radius = 0.4 #/*< and an approximate curvature radius */
snippet_normalize (cr, width, height)
x1=x0+rect_width
y1=y0+rect_height
#if (!rect_width || !rect_height)
# return
if rect_width/2<radius:
if rect_height/2<radius:
cr.move_to (x0, (y0 + y1)/2)
cr.curve_to (x0 ,y0, x0, y0, (x0 + x1)/2, y0)
cr.curve_to (x1, y0, x1, y0, x1, (y0 + y1)/2)
cr.curve_to (x1, y1, x1, y1, (x1 + x0)/2, y1)
cr.curve_to (x0, y1, x0, y1, x0, (y0 + y1)/2)
else:
cr.move_to (x0, y0 + radius)
cr.curve_to (x0 ,y0, x0, y0, (x0 + x1)/2, y0)
cr.curve_to (x1, y0, x1, y0, x1, y0 + radius)
cr.line_to (x1 , y1 - radius)
cr.curve_to (x1, y1, x1, y1, (x1 + x0)/2, y1)
cr.curve_to (x0, y1, x0, y1, x0, y1- radius)
else:
if rect_height/2<radius:
cr.move_to (x0, (y0 + y1)/2)
cr.curve_to (x0 , y0, x0 , y0, x0 + radius, y0)
cr.line_to (x1 - radius, y0)
cr.curve_to (x1, y0, x1, y0, x1, (y0 + y1)/2)
cr.curve_to (x1, y1, x1, y1, x1 - radius, y1)
cr.line_to (x0 + radius, y1)
cr.curve_to (x0, y1, x0, y1, x0, (y0 + y1)/2)
else:
cr.move_to (x0, y0 + radius)
cr.curve_to (x0 , y0, x0 , y0, x0 + radius, y0)
cr.line_to (x1 - radius, y0)
cr.curve_to (x1, y0, x1, y0, x1, y0 + radius)
cr.line_to (x1 , y1 - radius)
cr.curve_to (x1, y1, x1, y1, x1 - radius, y1)
cr.line_to (x0 + radius, y1)
cr.curve_to (x0, y1, x0, y1, x0, y1- radius)
cr.close_path ()
#/* and fill/stroke it */
cr.save ()
cr.set_rgb_color (0.5,0.5,1)
cr.fill ()
cr.restore ()
cr.set_alpha (0.5)
cr.set_rgb_color (0.5, 0,0)
cr.stroke ()
--- NEW FILE: curve_to.py ---
x, y = 0.1, 0.5
x1, y1 = 0.4, 0.9
x2, y2 = 0.6, 0.1
x3, y3 = 0.9, 0.5
snippet_normalize (cr, width, height)
cr.move_to (x, y)
cr.curve_to (x1, y1, x2, y2, x3, y3)
cr.stroke ()
cr.set_rgb_color (1,0.2,0.2)
cr.set_alpha (0.6)
cr.set_line_width (0.03)
cr.move_to (x,y); cr.line_to (x1,y1)
cr.move_to (x2,y2); cr.line_to (x3,y3)
cr.stroke ()
--- NEW FILE: fill_and_stroke2.py ---
snippet_normalize (cr, width, height)
cr.move_to (0.5, 0.1)
cr.line_to (0.9, 0.9)
cr.rel_line_to (-0.4, 0.0)
cr.curve_to (0.2, 0.9, 0.2, 0.5, 0.5, 0.5)
cr.close_path ()
cr.move_to (0.25, 0.1)
cr.rel_line_to (0.2, 0.2)
cr.rel_line_to (-0.2, 0.2)
cr.rel_line_to (-0.2, -0.2)
cr.close_path ()
cr.save ()
cr.set_rgb_color (0, 0, 1)
cr.fill ()
cr.restore ()
cr.stroke ()
--- NEW FILE: fill_and_stroke.py ---
snippet_normalize (cr, width, height)
cr.move_to (0.5, 0.1)
cr.line_to (0.9, 0.9)
cr.rel_line_to (-0.4, 0.0)
cr.curve_to (0.2, 0.9, 0.2, 0.5, 0.5, 0.5)
cr.save ()
cr.set_rgb_color (0, 0, 1)
cr.fill ()
cr.restore ()
cr.close_path ()
cr.stroke ()
--- NEW FILE: gradient.py ---
snippet_normalize (cr, width, height)
pat = cairo.Pattern.create_linear (0.0, 0.0, 0.0, 1.0)
pat.add_color_stop (1, 0, 0, 0, 1)
pat.add_color_stop (0, 1, 1, 1, 1)
cr.rectangle (0,0,1,1)
cr.set_pattern (pat)
cr.fill ()
pat = cairo.Pattern.create_radial (0.45, 0.4, 0.1,
0.4, 0.4, 0.5)
pat.add_color_stop (0, 1, 1, 1, 1)
pat.add_color_stop (1, 0, 0, 0, 1)
cr.set_pattern (pat)
cr.arc (0.5, 0.5, 0.3, 0, 2 * M_PI)
cr.fill ()
--- NEW FILE: __init__.py ---
# snippet list generation
import os
# list of snippet files
snip_list = [x[:-3] for x in os.listdir (os.path.dirname (__file__)) if not x.startswith('_') and x.endswith('.py')]
snip_list.sort()
# function used by some or all snippets
def snippet_normalize (ctx, width, height):
ctx.scale (width, height)
ctx.set_line_width (0.04)
def snippet_set_bg_svg (ctx, filename):
import cairo.svg
svg_cr = cairo.svg.Context()
svg_cr.parse (filename)
w, h = svg_cr.size
ctx.save()
ctx.scale (1.0/w, 1.0/h)
svg_cr.render (ctx)
ctx.restore()
--- NEW FILE: libsvg.py ---
import cairo.svg
snippet_normalize (cr, width, height)
svg_cr = cairo.svg.Context()
svg_cr.parse ("data/home.svg")
w, h = svg_cr.size
cr.scale (1.0/w, 1.0/h)
svg_cr.render (cr)
--- NEW FILE: operator_add.py ---
snippet_normalize (cr, width, height)
snippet_set_bg_svg (cr, "data/freedesktop.svg")
cr.set_operator (cairo.OPERATOR_ADD)
cr.set_alpha (0.5)
cr.set_rgb_color (1,0,0)
cr.rectangle (0.2,0.2, 0.5,0.5)
cr.fill ()
cr.set_rgb_color (0,1,0)
cr.rectangle (0.4,0.4, 0.4,0.4)
cr.fill ()
cr.set_rgb_color (0,0,1)
cr.rectangle (0.6,0.6, 0.3,0.3)
cr.fill ()
--- NEW FILE: operator_atop.py ---
snippet_normalize (cr, width, height)
snippet_set_bg_svg (cr, "data/freedesktop.svg")
cr.set_operator (cairo.OPERATOR_ATOP)
cr.set_alpha (0.5)
cr.set_rgb_color (1,0,0)
cr.rectangle (0.2,0.2, 0.5,0.5)
cr.fill ()
cr.set_rgb_color (0,1,0)
cr.rectangle (0.4,0.4, 0.4,0.4)
cr.fill ()
cr.set_rgb_color (0,0,1)
cr.rectangle (0.6,0.6, 0.3,0.3)
cr.fill ()
--- NEW FILE: operator_atop_reverse.py ---
snippet_normalize (cr, width, height)
snippet_set_bg_svg (cr, "data/freedesktop.svg")
cr.set_operator (cairo.OPERATOR_ATOP_REVERSE)
cr.set_alpha (0.5)
cr.set_rgb_color (1,0,0)
cr.rectangle (0.2,0.2, 0.5,0.5)
cr.fill ()
cr.set_rgb_color (0,1,0)
cr.rectangle (0.4,0.4, 0.4,0.4)
cr.fill ()
cr.set_rgb_color (0,0,1)
cr.rectangle (0.6,0.6, 0.3,0.3)
cr.fill ()
--- NEW FILE: operator_in.py ---
snippet_normalize (cr, width, height)
snippet_set_bg_svg (cr, "data/freedesktop.svg")
cr.set_operator (cairo.OPERATOR_IN)
cr.set_alpha (0.5)
cr.set_rgb_color (1,0,0)
cr.rectangle (0.2,0.2, 0.5,0.5)
cr.fill ()
cr.set_rgb_color (0,1,0)
cr.rectangle (0.4,0.4, 0.4,0.4)
cr.fill ()
cr.set_rgb_color (0,0,1)
cr.rectangle (0.6,0.6, 0.3,0.3)
cr.fill ()
--- NEW FILE: operator_in_reverse.py ---
snippet_normalize (cr, width, height)
snippet_set_bg_svg (cr, "data/freedesktop.svg")
cr.set_operator (cairo.OPERATOR_IN_REVERSE)
cr.set_alpha (0.5)
cr.set_rgb_color (1,0,0)
cr.rectangle (0.2,0.2, 0.5,0.5)
cr.fill ()
cr.set_rgb_color (0,1,0)
cr.rectangle (0.4,0.4, 0.4,0.4)
cr.fill ()
cr.set_rgb_color (0,0,1)
cr.rectangle (0.6,0.6, 0.3,0.3)
cr.fill ()
--- NEW FILE: operator_out.py ---
snippet_normalize (cr, width, height)
snippet_set_bg_svg (cr, "data/freedesktop.svg")
cr.set_operator (cairo.OPERATOR_OUT)
cr.set_alpha (0.5)
cr.set_rgb_color (1,0,0)
cr.rectangle (0.2,0.2, 0.5,0.5)
cr.fill ()
cr.set_rgb_color (0,1,0)
cr.rectangle (0.4,0.4, 0.4,0.4)
cr.fill ()
cr.set_rgb_color (0,0,1)
cr.rectangle (0.6,0.6, 0.3,0.3)
cr.fill ()
--- NEW FILE: operator_out_reverse.py ---
snippet_normalize (cr, width, height)
snippet_set_bg_svg (cr, "data/freedesktop.svg")
cr.set_operator (cairo.OPERATOR_OUT_REVERSE)
cr.set_alpha (0.5)
cr.set_rgb_color (1,0,0)
cr.rectangle (0.2,0.2, 0.5,0.5)
cr.fill ()
cr.set_rgb_color (0,1,0)
cr.rectangle (0.4,0.4, 0.4,0.4)
cr.fill ()
cr.set_rgb_color (0,0,1)
cr.rectangle (0.6,0.6, 0.3,0.3)
cr.fill ()
--- NEW FILE: operator_over.py ---
snippet_normalize (cr, width, height)
snippet_set_bg_svg (cr, "data/freedesktop.svg")
cr.set_operator (cairo.OPERATOR_OVER)
cr.set_alpha (0.5)
cr.set_rgb_color (1,0,0)
cr.rectangle (0.2,0.2, 0.5,0.5)
cr.fill ()
cr.set_rgb_color (0,1,0)
cr.rectangle (0.4,0.4, 0.4,0.4)
cr.fill ()
cr.set_rgb_color (0,0,1)
cr.rectangle (0.6,0.6, 0.3,0.3)
cr.fill ()
--- NEW FILE: operator_over_reverse.py ---
snippet_normalize (cr, width, height)
snippet_set_bg_svg (cr, "data/freedesktop.svg")
cr.set_operator (cairo.OPERATOR_OVER_REVERSE)
cr.set_alpha (0.5)
cr.set_rgb_color (1,0,0)
cr.rectangle (0.2,0.2, 0.5,0.5)
cr.fill ()
cr.set_rgb_color (0,1,0)
cr.rectangle (0.4,0.4, 0.4,0.4)
cr.fill ()
cr.set_rgb_color (0,0,1)
cr.rectangle (0.6,0.6, 0.3,0.3)
cr.fill ()
--- NEW FILE: operator_saturate.py ---
snippet_normalize (cr, width, height)
snippet_set_bg_svg (cr, "data/freedesktop.svg")
cr.set_operator (cairo.OPERATOR_SATURATE)
cr.set_alpha (0.5)
cr.set_rgb_color (1,0,0)
cr.rectangle (0.2,0.2, 0.5,0.5)
cr.fill ()
cr.set_rgb_color (0,1,0)
cr.rectangle (0.4,0.4, 0.4,0.4)
cr.fill ()
cr.set_rgb_color (0,0,1)
cr.rectangle (0.6,0.6, 0.3,0.3)
cr.fill ()
--- NEW FILE: operator_xor.py ---
snippet_normalize (cr, width, height)
snippet_set_bg_svg (cr, "data/freedesktop.svg")
cr.set_operator (cairo.OPERATOR_XOR)
cr.set_alpha (0.5)
cr.set_rgb_color (1,0,0)
cr.rectangle (0.2,0.2, 0.5,0.5)
cr.fill ()
cr.set_rgb_color (0,1,0)
cr.rectangle (0.4,0.4, 0.4,0.4)
cr.fill ()
cr.set_rgb_color (0,0,1)
cr.rectangle (0.6,0.6, 0.3,0.3)
cr.fill ()
--- NEW FILE: path.py ---
snippet_normalize (cr, width, height)
cr.move_to (0.5, 0.1)
cr.line_to (0.9, 0.9)
cr.rel_line_to (-0.4, 0.0)
cr.curve_to (0.2, 0.9, 0.2, 0.5, 0.5, 0.5)
cr.stroke ()
--- NEW FILE: set_line_cap.py ---
snippet_normalize (cr, width, height)
cr.set_line_width (0.12)
cr.set_line_cap (cairo.LINE_CAP_BUTT) #/* default */
cr.move_to (0.25, 0.2); cr.line_to (0.25, 0.8)
cr.stroke ()
cr.set_line_cap (cairo.LINE_CAP_ROUND)
cr.move_to (0.5, 0.2); cr.line_to (0.5, 0.8)
cr.stroke ()
cr.set_line_cap (cairo.LINE_CAP_SQUARE)
cr.move_to (0.75, 0.2); cr.line_to (0.75, 0.8)
cr.stroke ()
#/* draw helping lines */
cr.set_rgb_color (1,0.2,0.2)
cr.set_line_width (0.01)
cr.move_to (0.25, 0.2); cr.line_to (0.25, 0.8)
cr.move_to (0.5, 0.2); cr.line_to (0.5, 0.8)
cr.move_to (0.75, 0.2); cr.line_to (0.75, 0.8)
cr.stroke ()
--- NEW FILE: set_line_join.py ---
snippet_normalize (cr, width, height)
cr.set_line_width (0.16)
cr.move_to (0.3, 0.33)
cr.rel_line_to (0.2, -0.2)
cr.rel_line_to (0.2, 0.2)
cr.set_line_join (cairo.LINE_JOIN_MITER) #/* default */
cr.stroke ()
cr.move_to (0.3, 0.63)
cr.rel_line_to (0.2, -0.2)
cr.rel_line_to (0.2, 0.2)
cr.set_line_join (cairo.LINE_JOIN_BEVEL)
cr.stroke ()
cr.move_to (0.3, 0.93)
cr.rel_line_to (0.2, -0.2)
cr.rel_line_to (0.2, 0.2)
cr.set_line_join (cairo.LINE_JOIN_ROUND)
cr.stroke ()
--- NEW FILE: text_align_center.py ---
utf8 = "cairo"
snippet_normalize (cr, width, height)
cr.select_font ("Sans",
cairo.FONT_SLANT_NORMAL,
cairo.FONT_WEIGHT_NORMAL)
cr.scale_font (0.2)
x_bearing, y_bearing, width, height, x_advance, y_advance = cr.text_extents (utf8)
x = 0.5-(width/2 + x_bearing)
y = 0.5-(height/2 + y_bearing)
cr.move_to (x, y)
cr.show_text (utf8)
#/* draw helping lines */
cr.set_rgb_color (1,0.2,0.2)
cr.set_alpha (0.6)
cr.arc (x, y, 0.05, 0, 2*M_PI)
cr.fill ()
cr.move_to (0.5, 0)
cr.rel_line_to (0, 1)
cr.move_to (0, 0.5)
cr.rel_line_to (1, 0)
cr.stroke ()
--- NEW FILE: text_extents.py ---
utf8 = "cairo"
snippet_normalize (cr, width, height)
cr.select_font ("Sans",
cairo.FONT_SLANT_NORMAL,
cairo.FONT_WEIGHT_NORMAL)
cr.scale_font (0.4)
x_bearing, y_bearing, width, height, x_advance, y_advance = cr.text_extents (utf8)
x=0.1
y=0.6
cr.move_to (x,y)
cr.show_text (utf8)
#/* draw helping lines */
cr.set_rgb_color (1,0.2,0.2)
cr.set_alpha (0.6)
cr.arc (x, y, 0.05, 0, 2*M_PI)
cr.fill ()
cr.move_to (x,y)
cr.rel_line_to (0, -height)
cr.rel_line_to (width, 0)
cr.rel_line_to (x_bearing, -y_bearing)
cr.stroke ()
--- NEW FILE: text.py ---
snippet_normalize (cr, width, height)
cr.select_font ("Sans", cairo.FONT_SLANT_NORMAL,
cairo.FONT_WEIGHT_BOLD)
cr.scale_font (0.35)
cr.move_to (0.04, 0.53)
cr.show_text ("Hello")
cr.move_to (0.27, 0.65)
cr.text_path ("void")
cr.save ()
cr.set_rgb_color (0.5,0.5,1)
cr.fill ()
cr.restore ()
cr.set_line_width (0.01)
cr.stroke ()
#/* draw helping lines */
cr.set_rgb_color (1,0.2,0.2)
cr.set_alpha (0.6)
cr.arc (0.04, 0.53, 0.02, 0, 2*M_PI)
cr.arc (0.27, 0.65, 0.02, 0, 2*M_PI)
cr.fill ()
- Previous message: [cairo-commit]
pycairo/examples/cairo_snippets c_to_python.py, NONE,
1.1 snippets_gtk.py, NONE, 1.1 snippets_png.py, NONE, 1.1
- Next message: [cairo-commit]
pycairo/examples/cairo_snippets/data freedesktop.svg, NONE,
1.1 home.svg, NONE, 1.1 romedalen.png, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the cairo-commit
mailing list