|
| 1 | +# Basic arcade program using objects |
| 2 | +# Draw shapes on screen |
| 3 | + |
| 4 | +# Imports |
| 5 | +import arcade |
| 6 | + |
| 7 | +# Constants |
| 8 | +SCREEN_WIDTH = 600 |
| 9 | +SCREEN_HEIGHT = 650 |
| 10 | +SCREEN_TITLE = "Draw Shapes" |
| 11 | + |
| 12 | +# Classes |
| 13 | + |
| 14 | + |
| 15 | +class Welcome(arcade.Window): |
| 16 | + """Our main welcome window |
| 17 | + """ |
| 18 | + |
| 19 | + def __init__(self): |
| 20 | + """Initialize the window |
| 21 | + """ |
| 22 | + |
| 23 | + # Call the parent class constructor |
| 24 | + super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) |
| 25 | + |
| 26 | + # Set the background window |
| 27 | + arcade.set_background_color(arcade.color.WHITE) |
| 28 | + |
| 29 | + def on_draw(self): |
| 30 | + """Called whenever we need to draw our window |
| 31 | + """ |
| 32 | + |
| 33 | + # Clear the screen and start drawing |
| 34 | + arcade.start_render() |
| 35 | + |
| 36 | + # Draw a blue arc |
| 37 | + arcade.draw_arc_filled(100, 100, 40, 40, arcade.color.BLUE, 0, 125) |
| 38 | + |
| 39 | + # Draw a red ellipse |
| 40 | + arcade.draw_ellipse_outline( |
| 41 | + 300, 100, 60, 30, arcade.color.RED, border_width=2 |
| 42 | + ) |
| 43 | + |
| 44 | + # Draw some purple lines |
| 45 | + arcade.draw_line(500, 100, 550, 100, arcade.color.PURPLE) |
| 46 | + arcade.draw_line(500, 90, 550, 90, arcade.color.PURPLE, line_width=2) |
| 47 | + arcade.draw_line(500, 80, 550, 80, arcade.color.PURPLE, line_width=3) |
| 48 | + |
| 49 | + # Draw an orange parabola |
| 50 | + arcade.draw_parabola_filled(100, 100, 130, 120, arcade.color.ORANGE) |
| 51 | + |
| 52 | + # Draw a black point |
| 53 | + arcade.draw_point(300, 300, arcade.color.BLACK, 20) |
| 54 | + |
| 55 | + # Draw a green polygon |
| 56 | + points_list = [ |
| 57 | + [500, 300], |
| 58 | + [550, 300], |
| 59 | + [575, 325], |
| 60 | + [550, 350], |
| 61 | + [525, 340], |
| 62 | + ] |
| 63 | + arcade.draw_polygon_outline( |
| 64 | + points_list, arcade.color.GREEN, line_width=5 |
| 65 | + ) |
| 66 | + |
| 67 | + # Draw some rectangles |
| 68 | + arcade.draw_rectangle_filled(100, 500, 150, 75, arcade.color.AZURE) |
| 69 | + arcade.draw_lrtb_rectangle_filled( |
| 70 | + 150, 250, 575, 525, arcade.color.AMARANTH_PINK |
| 71 | + ) |
| 72 | + arcade.draw_xywh_rectangle_filled( |
| 73 | + 200, 550, 150, 75, arcade.color.ASPARAGUS |
| 74 | + ) |
| 75 | + |
| 76 | + # Draw some triangles |
| 77 | + arcade.draw_triangle_filled( |
| 78 | + 400, 500, 500, 500, 450, 575, arcade.color.DEEP_RUBY |
| 79 | + ) |
| 80 | + |
| 81 | + |
| 82 | +# Main code entry point |
| 83 | +if __name__ == "__main__": |
| 84 | + app = Welcome() |
| 85 | + arcade.run() |
0 commit comments