def rect(): gc = GraphicsContext((500, 500)) gc.clear() gc.rect(100, 100, 300, 300) gc.draw_path() file_path = tempfile.mktemp(suffix='.bmp') gc.save(file_path) return file_path
def test_clip_stack(gc): sub_windows = ( (10.5, 250, 200, 200), (220.5, 250, 200, 200), (430.5, 250, 200, 200), (10.5, 10, 200, 200), (220.5, 10, 200, 200), (430.5, 10, 200, 200), ) gc.set_line_width(2) gc.set_stroke_color(BLACK) gc.rects(sub_windows) gc.stroke_path() img = GraphicsContext((200, 200)) main_rects = ((40.5, 30.5, 120, 50), (40.5, 120.5, 120, 50)) disjoint_rects = ((60.5, 115.5, 80, 15), (60.5, 70.5, 80, 15)) vert_rect = (60.5, 10.5, 55, 180) # Draw the full image draw_sub_image(img, 200, 200) gc.draw_image(img, sub_windows[0]) img.clear() # First clip img.clip_to_rects(main_rects) draw_sub_image(img, 200, 200) gc.draw_image(img, sub_windows[1]) # Second Clip with img: img.clear() img.clip_to_rects(main_rects) img.clip_to_rect(*vert_rect) draw_sub_image(img, 200, 200) gc.draw_image(img, sub_windows[2]) # Pop back to first clip img.clear() draw_sub_image(img, 200, 200) gc.draw_image(img, sub_windows[3]) # Adding a disjoing set of rects img.clear() with img: img.clip_to_rects(main_rects) img.clip_to_rects(disjoint_rects) draw_sub_image(img, 200, 200) gc.draw_image(img, sub_windows[4]) # Pop back to first clip img.clear() draw_sub_image(img, 200, 200) gc.draw_image(img, sub_windows[5])
def test_clip_stack(gc): sub_windows = ((10.5, 250, 200, 200), (220.5, 250, 200, 200), (430.5, 250, 200, 200), (10.5, 10, 200, 200), (220.5, 10, 200, 200), (430.5, 10, 200, 200)) gc.set_line_width(2) gc.set_stroke_color(black) gc.rects(sub_windows) gc.stroke_path() img = GraphicsContext((200, 200)) main_rects = ((40.5, 30.5, 120, 50), (40.5, 120.5, 120, 50)) disjoint_rects = ((60.5, 115.5, 80, 15), (60.5, 70.5, 80, 15)) vert_rect = (60.5, 10.5, 55, 180) # Draw the full image draw_sub_image(img, 200, 200) gc.draw_image(img, sub_windows[0]) img.clear() # First clip img.clip_to_rects(main_rects) draw_sub_image(img, 200, 200); gc.draw_image(img, sub_windows[1]) # Second Clip with img: img.clear() img.clip_to_rects(main_rects) img.clip_to_rect(*vert_rect) draw_sub_image(img, 200, 200) gc.draw_image(img, sub_windows[2]) # Pop back to first clip img.clear() draw_sub_image(img, 200, 200) gc.draw_image(img, sub_windows[3]) # Adding a disjoing set of rects img.clear() with img: img.clip_to_rects(main_rects) img.clip_to_rects(disjoint_rects) draw_sub_image(img, 200, 200) gc.draw_image(img, sub_windows[4]) # Pop back to first clip img.clear() draw_sub_image(img, 200, 200) gc.draw_image(img, sub_windows[5])
def simple(): gc = GraphicsContext((100, 100)) gc.clear() gc.set_line_cap(constants.CAP_SQUARE) gc.set_line_join(constants.JOIN_MITER) gc.set_stroke_color((1, 0, 0)) gc.set_fill_color((0, 0, 1)) gc.rect(0, 0, 30, 30) gc.draw_path() file_path = tempfile.mktemp(suffix='.bmp') gc.save(file_path) return file_path
font = Font(face_name="Arial", size=32) gc.set_font(font) gc.translate_ctm(100.0, 100.0) gc.move_to(-5, 0) gc.line_to(5, 0) gc.move_to(0, 5) gc.line_to(0, -5) gc.move_to(0, 0) gc.stroke_path() txtRot = agg.rotation_matrix(PI / 6) gc.set_text_matrix(txtRot) gc.show_text("Hello") txtRot.invert() gc.set_text_matrix(txtRot) gc.show_text("inverted") if __name__ == "__main__": tests = ( (test_clip_stack, "clip_stack.png"), (test_arc_to, "arc_to.png"), (test_handling_text, "handling_text.png"), ) for test_func, filename in tests: img = GraphicsContext((800, 600)) img.clear(WHITE) test_func(img) img.save(filename)
def test_handling_text(gc): font = Font(face_name="Arial", size = 32) gc.set_font(font) gc.translate_ctm(100.0, 100.0) gc.move_to(-5,0) gc.line_to(5,0) gc.move_to(0,5) gc.line_to(0,-5) gc.move_to(0,0) gc.stroke_path() txtRot = agg.rotation_matrix(PI/6) gc.set_text_matrix(txtRot) gc.show_text("Hello") txtRot.invert() gc.set_text_matrix(txtRot) gc.show_text("inverted") if __name__ == "__main__": tests = ((test_clip_stack, "clip_stack.png"), (test_arc_to, "arc_to.png"), (test_handling_text, "handling_text.png")) for test_func, filename in tests: img = GraphicsContext((800, 600)) img.clear(white) test_func(img) img.save(filename)
def test_handling_text(gc): font = Font(face_name="Arial", size=32) gc.set_font(font) gc.translate_ctm(100.0, 100.0) gc.move_to(-5, 0) gc.line_to(5, 0) gc.move_to(0, 5) gc.line_to(0, -5) gc.move_to(0, 0) gc.stroke_path() txtRot = agg.rotation_matrix(PI / 6) gc.set_text_matrix(txtRot) gc.show_text("Hello") txtRot.invert() gc.set_text_matrix(txtRot) gc.show_text("inverted") if __name__ == "__main__": tests = ((test_clip_stack, "clip_stack.png"), (test_arc_to, "arc_to.png"), (test_handling_text, "handling_text.png")) for test_func, filename in tests: img = GraphicsContext((800, 600)) img.clear(white) test_func(img) img.save(filename)
from enable.kiva_graphics_context import GraphicsContext gc = GraphicsContext((500,500)) gc.clear() gc.rect(100,100,300,300) gc.draw_path() gc.save("rect.bmp")