最近开始学习arcade的图形库,感觉功能很丰富,尝试画了个时钟,显示如下:
贴上调整好的代码:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 import arcade 2 import math,time 3 4 SCREEN_WIDTH = 800 5 SCREEN_HEIGHT = 600 6 # These constants control the particulars about the radar 7 CENTER_X = SCREEN_WIDTH // 2 8 CENTER_Y = SCREEN_HEIGHT // 2 9 RADIANS_PER_FRAME = 0.01 10 SWEEP_LENGTH = 250 11 12 List = [] 13 def points(): 14 for i in range(1,13): 15 x = 400 + 230*math.sin(2*math.pi*i/12) 16 17 y = 300 + 230*math.cos(2*math.pi*i/12) 18 arcade.draw_text(f"{i}",x,y,arcade.color.WHITE,12) 19 def draw_lines(radius,line_width,rad): 20 x = 400 - radius * math.cos(math.pi / 2 + rad) 21 22 y = 300 + radius * math.sin(math.pi / 2 + rad) 23 line = arcade.draw_line(400, 300, x, y,arcade.color.WHITE,line_width) 24 List.append(line) 25 def on_draw(delta_time): 26 arcade.start_render() 27 #外圆 28 arcade.draw_circle_outline(CENTER_X, CENTER_Y, SWEEP_LENGTH, arcade.color.DARK_GREEN, 10) 29 #数字显示 30 points() 31 32 tm = time.localtime() 33 cur_time2 = time.strftime('%Y-%m-%d %X', time.localtime()) 34 t_hour = 0 35 if tm.tm_hour<=12: 36 t_hour=tm.tm_hour 37 else: 38 t_hour=tm.tm_hour-12 39 rad1=2*math.pi*(t_hour+tm.tm_min/60)/12 40 41 rad2=2*math.pi*(tm.tm_min+tm.tm_sec/60)/60 42 43 rad3=2*math.pi*tm.tm_sec/60 44 45 draw_lines(100,6,rad1) 46 47 draw_lines(140,3,rad2) 48 49 draw_lines(180,1,rad3) 50 arcade.draw_text(f"{cur_time2}",CENTER_X-70,20,arcade.color.WHITE,12) 51 52 def main(): 53 arcade.open_window(SCREEN_WIDTH,SCREEN_HEIGHT,"Radar Sweep Example") 54 arcade.set_background_color(arcade.color.BLACK) 55 arcade.schedule(on_draw,1) 56 arcade.run() 57 58 arcade.close_window() 59 if __name__ == '__main__': 60 main()
使用的是python 3.6.4版本