python import vex def game_loop(): window = vex.Window() canvas = vex.Canvas() while True: canvas.clear() canvas.draw_rectangle((100, 100), (200, 200), vex.Color.RED) canvas.draw_text("Hello, World!", (150, 150), vex.Color.WHITE) for event in vex.get_events(): if event.type == vex.EventType.MOUSE_CLICK: print("Mouse clicked!") window.update(canvas) if __name__ == "__main__": game_loop() python import vex def draw_shape(canvas): canvas.clear() canvas.draw_rectangle((100, 100), (200, 200), vex.Color.BLUE) def edit_shape(canvas): selected = False selected_shape = None while True: for event in vex.get_events(): if event.type == vex.EventType.MOUSE_CLICK: if not selected: selected_shape = canvas.get_shape_at_point(event.position) if selected_shape is not None: selected = True else: selected_shape.move(event.position) selected = False canvas.update() if __name__ == "__main__": canvas = vex.Canvas() draw_shape(canvas) edit_shape(canvas) python import vex def draw_bar_chart(data): canvas = vex.Canvas() bar_width = 30 bar_spacing = 20 x = 50 y = 50 for value in data: bar_height = value * 10 canvas.draw_rectangle((x, y + 200 - bar_height), (x + bar_width, y + 200), vex.Color.GREEN) x += bar_width + bar_spacing canvas.update() if __name__ == "__main__": data = [10, 25, 30, 15, 20] draw_bar_chart(data)


上一篇:
下一篇:
切换中文