""" 基本的雷达扫描动画 """ import arcade import math # Set up the constants SCREEN_WIDTH = 800 SCREEN_HEIGHT = 600 SCREEN_TITLE = "基本的雷达扫描动画lixingqiu.com" # 常量定义 CENTER_X = SCREEN_WIDTH // 2 CENTER_Y = SCREEN_HEIGHT // 2 RADIANS_PER_FRAME = 0.02 SWEEP_LENGTH = 250 def on_draw(delta_time): """ 使用这个函数画所有的 """ # 角度增加 on_draw.angle += RADIANS_PER_FRAME # 每帧所转角度 # 计算雷达的终点,使用了三角函数 x = SWEEP_LENGTH * math.sin(on_draw.angle) + CENTER_X y = SWEEP_LENGTH * math.cos(on_draw.angle) + CENTER_Y # 开始渲染 arcade.start_render() # 画雷达线 arcade.draw_line(CENTER_X, CENTER_Y, x, y, arcade.color.OLIVE, 4) # 画圆圈 arcade.draw_circle_outline(CENTER_X, CENTER_Y, SWEEP_LENGTH, arcade.color.DARK_GREEN, 10) # 给函数增加属性值 on_draw.angle = 0 def main(): # 打开窗口 arcade.open_window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) arcade.set_background_color(arcade.color.BLACK) # 80份之一秒执行一次on_draw arcade.schedule(on_draw, 1 / 80) # 运行程序 arcade.run() # 按窗口关闭按钮则关闭窗口 arcade.close_window() if __name__ == "__main__": main()