Esempio n. 1
0
def dash(sz=(1000, 1000)):
    gc = GraphicsContextArray(sz)
    gc.set_fill_color((1.0, 0.0, 0.0, 0.1))
    gc.set_stroke_color((0.0, 1.0, 0.0, 0.6))

    width = 10
    gc.set_line_width(10)

    phase = width * 2.5
    pattern = width * numpy.array((5, 5))
    gc.set_line_dash(pattern, phase)
    gc.set_line_cap(constants.CAP_BUTT)
    t1 = perf_counter()
    gc.move_to(10, 10)
    gc.line_to(sz[0] - 10, sz[1] - 10)
    gc.line_to(10, sz[1] - 10)
    gc.close_path()
    gc.draw_path()
    t2 = perf_counter()
    with tempfile.NamedTemporaryFile(suffix=".bmp") as fid:
        gc.save(fid.name)
        image = Image.from_file(fid.name,
                                resist_width="weak",
                                resist_height="weak")
    tot_time = t2 - t1
    print("time:", tot_time)
    return image
Esempio n. 2
0
def dash(sz=(1000,1000)):
    gc = GraphicsContextArray(sz)
    gc.set_fill_color((1.0,0.0,0.0,0.1))
    gc.set_stroke_color((0.0,1.0,0.0,0.6))

    width = 10
    gc.set_line_width(10)

    phase = width * 2.5;
    pattern = width * numpy.array((5,5))
    gc.set_line_dash(pattern,phase)
    gc.set_line_cap(constants.CAP_BUTT)
    t1 = time.clock()
    gc.move_to(10,10)
    gc.line_to(sz[0]-10,sz[1]-10)
    gc.line_to(10,sz[1]-10)
    gc.close_path()
    gc.draw_path()
    t2 = time.clock()
    gc.save("dash.bmp")
    tot_time = t2 - t1
    print 'time:', tot_time
def dash(sz=(1000, 1000)):
    gc = GraphicsContextArray(sz)
    gc.set_fill_color((1.0, 0.0, 0.0, 0.1))
    gc.set_stroke_color((0.0, 1.0, 0.0, 0.6))

    width = 10
    gc.set_line_width(10)

    phase = width * 2.5
    pattern = width * numpy.array((5, 5))
    gc.set_line_dash(pattern, phase)
    gc.set_line_cap(constants.CAP_BUTT)
    t1 = time.clock()
    gc.move_to(10, 10)
    gc.line_to(sz[0] - 10, sz[1] - 10)
    gc.line_to(10, sz[1] - 10)
    gc.close_path()
    gc.draw_path()
    t2 = time.clock()
    gc.save("dash.bmp")
    tot_time = t2 - t1
    print('time:', tot_time)
Esempio n. 4
0
# consecutive printing of text.
with gc:
    gc.set_antialias(False)
    gc.set_fill_color((0,1,0))
    gc.translate_ctm(50,50)
    gc.rotate_ctm(3.1416/4)
    gc.show_text("hello")
    gc.translate_ctm(-50,-50)
    gc.set_text_matrix(AffineMatrix())
    gc.set_fill_color((0,1,1))
    gc.show_text("hello")

t2 = time.clock()
print('aliased:', t2 - t1)
gc.save("text_aliased.bmp")

gc = GraphicsContextArray((200,200))

font = Font(family=MODERN)
#print font.size
font.size=8
gc.set_font(font)

t1 = time.clock()

with gc:
    gc.set_antialias(True)
    gc.set_fill_color((0,1,0))
    gc.translate_ctm(50,50)
    gc.rotate_ctm(3.1416/4)
Esempio n. 5
0
        super(Circle, self).__init__(x, y, color=color, line_width=line_width)
        self.radius = radius
        
    def draw(self, image):
        image.set_stroke_color(color_dict[self.color])
        image.set_line_width(self.line_width)
        
        image.arc(self.x, self.y, self.radius, 0, 6.28318)
        image.close_path()
        image.stroke_path()

# Create an image that we can draw our shapes into
image_size = (300,300)
image = Image(image_size)

# Create a box and add it to the image.
box = Square(30, 30, 100, color='green')
box.draw(image)

line = Line(50, 250, 250, 50)
line.draw(image)

rect = Rectangle( 50, 50, 30, 50)        
rect.draw(image)

circle = Circle( 150, 150, 60, color='blue')        
circle.draw(image)

# Save the image out as a png image.
image.save('shapes.png')