"""
带缓冲的形状ShapeElementList
展示如何使用SahpeElementList这个列表
"""
import arcade
import random
# 常量定义,屏幕宽高和高度与标题
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCREEN_TITLE = "带缓冲的形状列表_旋转矩形_改编:李兴球"
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()
self.shape_list.center_x = SCREEN_WIDTH // 2
self.shape_list.center_y = SCREEN_HEIGHT // 2
self.shape_list.angle = 0
# 得到所有颜色,arcade.color是一个模块,它存储了颜色字符串
colors = [getattr(arcade.color, color) for color in dir(arcade.color) if not color.startswith("__") ]
point_list = ((0, 0),(200, 0),(200, 100),(0,100))
poly = arcade.create_polygon(point_list, (155, 90, 210), 5)
# <arcade.buffered_draw_commands.Shape object at 0x0000000006DF5F28>
print(poly)
self.shape_list.append(poly) # 添加到形状列表,(shape_list以屏幕中心为原点)
arcade.set_background_color(arcade.color.BLACK)
def on_draw(self):
"""
Render the screen.
"""
# This command has to happen before we start drawing
arcade.start_render()
self.shape_list.draw()
def update(self, delta_time):
"""更新坐标等"""
self.shape_list.angle += 0.2
#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()