def get_smiley_pixmap(width, height): """Gets a smiley face image Arguments: width: the width of the pixmap height: the height of the pixmap """ global _demo_image if not _demo_image: demo_image_context = Grx.Context.new(27, 27) save = Grx.save_current_context() Grx.set_current_context(demo_image_context) Grx.clear_context(Grx.color_get(0, 0, 255)) Grx.draw_filled_circle(13, 13, 13, Grx.color_get(255, 255, 0)) Grx.draw_filled_circle(8, 8, 2, Grx.color_get_black()) Grx.draw_filled_circle(18, 8, 2, Grx.color_get_black()) Grx.draw_filled_ellipse_arc(13, 16, 7, 5, 1800, 3600, Grx.ArcStyle.CLOSED_CHORD, Grx.color_get_black()) Grx.set_current_context(save) _demo_image = Grx.Pixmap.new_from_context(demo_image_context) return _demo_image.stretch(width, height)
def activate(app): x = Grx.get_width() // 8 y = Grx.get_height() // 8 r1 = int(x * 0.8) r2 = int(y * 0.8) colors = Grx.color_get_ega_colors() white = colors[Grx.EgaColorIndex.WHITE] checker = demo.get_checkerboard_pixmap() line_opt0 = Grx.LineOptions() # just a plain old ellipse Grx.draw_ellipse(x, y, r1, r2, white) Grx.draw_filled_ellipse(x, y * 3, r1, r2, white) Grx.draw_ellipse_with_pixmap(x, y * 5, r1, r2, line_opt0, checker) Grx.draw_filled_ellipse_with_pixmap(x, y * 7, r1, r2, checker) # quarter a ellipses Grx.draw_ellipse_arc(x * 3, y, r1, r2, 0, 900, Grx.ArcStyle.OPEN, white) Grx.draw_filled_ellipse_arc(x * 3, y * 3, r1, r2, 0, 900, Grx.ArcStyle.OPEN, white) Grx.draw_ellipse_arc_with_pixmap(x * 3, y * 5, r1, r2, 0, 900, Grx.ArcStyle.OPEN, line_opt0, checker) Grx.draw_filled_ellipse_arc_with_pixmap(x * 3, y * 7, r1, r2, 0, 900, Grx.ArcStyle.OPEN, checker) Grx.draw_ellipse_arc(x * 3, y, r1, r2, 1800, 2700, Grx.ArcStyle.CLOSED_CHORD, white) Grx.draw_filled_ellipse_arc(x * 3, y * 3, r1, r2, 1800, 2700, Grx.ArcStyle.CLOSED_CHORD, white) Grx.draw_ellipse_arc_with_pixmap(x * 3, y * 5, r1, r2, 1800, 2700, Grx.ArcStyle.CLOSED_CHORD, line_opt0, checker) Grx.draw_filled_ellipse_arc_with_pixmap(x * 3, y * 7, r1, r2, 1800, 2700, Grx.ArcStyle.CLOSED_CHORD, checker) # stretchy Pac-Man Grx.draw_ellipse_arc(x * 5, y, r1, r2, 450, 3150, Grx.ArcStyle.CLOSED_RADIUS, white) Grx.draw_filled_ellipse_arc(x * 5, y * 3, r1, r2, 450, 3150, Grx.ArcStyle.CLOSED_RADIUS, white) Grx.draw_ellipse_arc_with_pixmap(x * 5, y * 5, r1, r2, 450, 3150, Grx.ArcStyle.CLOSED_RADIUS, line_opt0, checker) Grx.draw_filled_ellipse_arc_with_pixmap(x * 5, y * 7, r1, r2, 450, 3150, Grx.ArcStyle.CLOSED_RADIUS, checker) # line options line_opt = Grx.LineOptions() line_opt.color = colors[Grx.EgaColorIndex.GREEN] line_opt.width = 1 line_opt.n_dash_patterns = 2 line_opt.dash_pattern0 = 2 line_opt.dash_pattern1 = 2 Grx.draw_ellipse_with_options(x * 7, y, r1, r2, line_opt) Grx.draw_ellipse_arc_with_options(x * 7, y * 3, r1, r2, 2250, 1350, Grx.ArcStyle.CLOSED_RADIUS, line_opt) Grx.draw_ellipse_arc_with_pixmap(x * 7, y * 5, r1, r2, 2250, 1350, Grx.ArcStyle.CLOSED_RADIUS, line_opt, checker) # reusable points points = Grx.generate_ellipse(x * 7, y * 7, r1, r2) Grx.draw_polygon(points, white)