将顶点缓冲区对象与线一起使用#

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