可旋转的顶点缓冲对象和彩色折线条示例

"""
顶点缓冲对象和彩色折线条示例
"""
import arcade
import random

# Do the math to figure out our screen dimensions
SCREEN_WIDTH = 480
SCREEN_HEIGHT = 360
SCREEN_TITLE = "顶点缓冲对象和彩色折线条示例,www.lixingqiu.com"

class MyGame(arcade.Window):
    """
    Main application class.
    """

    def __init__(self, width, height, title):
        """
        设置应用程序
        """
        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("__") ]
        print(colors)
        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.
        """
        # 开始渲染
        arcade.start_render()

        self.shape_list.draw()

    def 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()

顶点缓冲对象和彩色折线条示例,www.lixingqiu.com