Sophie

Sophie

distrib > Mandriva > 2010.2 > i586 > media > contrib-backports > by-pkgid > 480400831775432e21887c0bb26fd401 > files > 914

python-enthought-enable-3.4.0-1mdv2010.2.i586.rpm

from __future__ import with_statement

from numpy import cos, sin, arange, pi, array
from enthought.kiva.image import GraphicsContext
from enthought.kiva.constants import *

def draw_circle(gc,radius=2):
    gc.begin_path()
    angle = 0
    gc.move_to(radius*cos(angle), radius*sin(angle))
    for angle in arange(pi/4.,2*pi,pi/4.):
        gc.line_to(radius*cos(angle), radius*sin(angle))
    gc.close_path()
    gc.fill_path()

star_points = [(-20,-30),
               (0, 30),
               (20,-30),
               (-30,10),
               (30,10),
               (-20,-30)]
ring_point = (0,35)                   
ring_radius = 5

fill_color = array((200.,184.,106.))/255.
point_color = array((.3,.3,.3))
line_color = point_color

for i in range(len(star_points)+1):
    gc = GraphicsContext((800,800))
    gc.scale_ctm(8.0,8.0)
    gc.translate_ctm(50,50)

    # draw star
    gc.set_alpha(.5)
    x,y = star_points[0]
    gc.move_to(x,y)
    for x,y in star_points[1:]:
        gc.line_to(x,y)    
    gc.close_path()
    gc.set_fill_color(fill_color)
    gc.get_fill_color()
    gc.fill_path()
    
      
    gc.set_alpha(.4)
    gc.set_stroke_color(line_color)
    gc.set_fill_color(line_color)
    gc.set_line_width(12)
    
    if i > 0:
        with gc:
            x,y = star_points[0]
            gc.translate_ctm(x,y)
            draw_circle(gc)
            
    if i > 1:
        points = star_points[:i]
        with gc:
            x,y = points[0]
            gc.move_to(x,y)        
            for x,y in points[1:]:
                gc.line_to(x,y)                      
            gc.stroke_path()  
             
    """
    for x,y in points:
        with gc:
            gc.translate_ctm(x,y)
            draw_circle(gc)
    """
    gc.save("star_path%d.bmp" % i)
    
# draw star
line_color = (0.0,0.0,0.0)
gc = GraphicsContext((800,800))
gc.scale_ctm(8.0,8.0)
gc.translate_ctm(50,50)
gc.set_stroke_color(line_color)
gc.set_fill_color(fill_color)
gc.set_line_width(12)
x,y = star_points[0]
gc.move_to(x,y)
for x,y in star_points[1:]:
    gc.line_to(x,y)    
gc.close_path()
gc.set_fill_color(fill_color)
gc.get_fill_color()
gc.draw_path()
gc.save("star_path7.bmp")

# draw star
gc = GraphicsContext((1700,400))
line_color = (0.0,0.0,0.0)
gc.scale_ctm(4.0,4.0)

offsets = array(((0,0),(80,0),(160,0),(240,0),(320,0)))
modes = [FILL, EOF_FILL, STROKE, FILL_STROKE, EOF_FILL_STROKE]
pairs = zip(modes, offsets)
center = array((50,50))
for mode, offset in pairs:
    with gc:
        xo,yo = center+offset
        gc.translate_ctm(xo,yo)
        gc.set_stroke_color(line_color)
        gc.set_fill_color(fill_color)
        gc.set_line_width(12)
        x,y = star_points[0]
        gc.move_to(x,y)
        for x,y in star_points[1:]:
            gc.line_to(x,y)    
        gc.close_path()
        gc.set_fill_color(fill_color)
        gc.get_fill_color()
        gc.draw_path(mode)
gc.save("star_path8.bmp")