python-arcade时钟

最近开始学习arcade的图形库,感觉功能很丰富,尝试画了个时钟,显示如下:

 

贴上调整好的代码:

 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()
View Code

 

使用的是python 3.6.4版本

转载于:https://www.cnblogs.com/lq147760524/p/8309000.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值