# demo1.py # draw a series of rotated trianges with different colors and different transparencies import PyArt,math ident = [1, 0, 0, 1, 0, 0] canvas = PyArt.Canvas(256,156, bg=0x7f7f7f) canvas.gstate.fill = 0x0000FF canvas.gstate.fill_opacity = .5 # define the triangle path p p = PyArt.Path() yu = 36.95 p.moveto(0,-yu) p.lineto(-32,yu/2.0) p.lineto(32,yu/2.0) p.close() p.end() # paint the first triangle x0,y0 = 96, 96 sc = 2.0 canvas.translate(x0,y0) canvas.scale(sc,sc) canvas.fill(p) # paint the second triangle, rotating & scaling relative to the first canvas.gstate.CTM = ident canvas.translate(x0+32,y0) canvas.rotate(35) sc = sc/math.sqrt(3.0) canvas.scale(sc,sc) canvas.gstate.fill = 0x00FF00 # green canvas.fill(p) # paint the next triangle canvas.gstate.CTM = ident canvas.translate(x0+32*2,y0) canvas.rotate(35*2) sc = sc/math.sqrt(3.0) canvas.scale(sc,sc) canvas.gstate.fill = 0xFF0000 # red canvas.gstate.fill_opacity = canvas.gstate.fill_opacity/2.0 canvas.fill(p) # last triangle canvas.gstate.CTM = ident canvas.translate(x0+32*2.5,y0) canvas.rotate(35*3) sc = sc/math.sqrt(3.0) canvas.scale(sc,sc) canvas.gstate.fill = 0x00FFFF canvas.gstate.fill_opacity = canvas.gstate.fill_opacity/2.0 canvas.fill(p) canvas.save("demo1.png")