1"""
2Using a Vertex Buffer Object With Lines
3
4If Python and Arcade are installed, this example can be run from the command line with:
5python -m arcade.examples.lines_buffered
6"""
7import arcade
8import random
9
10# Do the math to figure out our screen dimensions
11SCREEN_WIDTH = 800
12SCREEN_HEIGHT = 600
13SCREEN_TITLE = "Vertex Buffer Object With Lines Example"
14
15
16class MyGame(arcade.Window):
17 """
18 Main application class.
19 """
20
21 def __init__(self, width, height, title):
22 """
23 Set up the application.
24 """
25 super().__init__(width, height, title)
26
27 self.shape_list = arcade.ShapeElementList()
28 point_list = ((0, 50),
29 (10, 10),
30 (50, 0),
31 (10, -10),
32 (0, -50),
33 (-10, -10),
34 (-50, 0),
35 (-10, 10),
36 (0, 50))
37 colors = [
38 getattr(arcade.color, color)
39 for color in dir(arcade.color)
40 if not color.startswith("__")
41 ]
42 for i in range(200):
43 x = SCREEN_WIDTH // 2 - random.randrange(SCREEN_WIDTH)
44 y = SCREEN_HEIGHT // 2 - random.randrange(SCREEN_HEIGHT)
45 color = random.choice(colors)
46 points = [(px + x, py + y) for px, py in point_list]
47
48 my_line_strip = arcade.create_line_strip(points, color, 5)
49 self.shape_list.append(my_line_strip)
50
51 self.shape_list.center_x = SCREEN_WIDTH // 2
52 self.shape_list.center_y = SCREEN_HEIGHT // 2
53 self.shape_list.angle = 0
54
55 arcade.set_background_color(arcade.color.BLACK)
56
57 def on_draw(self):
58 """
59 Render the screen.
60 """
61 # This command has to happen before we start drawing
62 arcade.start_render()
63
64 self.shape_list.draw()
65
66 def on_update(self, delta_time):
67 self.shape_list.angle += 1
68 self.shape_list.center_x += 0.1
69 self.shape_list.center_y += 0.1
70
71
72def main():
73 MyGame(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
74 arcade.run()
75
76
77if __name__ == "__main__":
78 main()