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
    评论
Learn and use Python and PyGame to design and build cool arcade games. In Program Arcade Games: With Python and PyGame, Second Edition, Dr. Paul Vincent Craven teaches you how to create fun and simple quiz games; integrate and start using graphics; animate graphics; integrate and use game controllers; add sound and bit-mapped graphics; and build grid-based games. After reading and using this book, you'll be able to learn to program and build simple arcade game applications using one of today's most popular programming languages, Python. You can even deploy onto Steam and other Linux-based game systems as well as Android, one of today's most popular mobile and tablet platforms. You'll learn: How to create quiz games How to integrate and start using graphics How to animate graphics How to integrate and use game controllers How to add sound and bit-mapped graphics How to build grid-based games Audience This book assumes no prior programming knowledge. Table of Contents Chapter 1: Before Getting Started… Chapter 2: Create a Custom Calculator Chapter 3: What Is a Computer Language? Chapter 4: Quiz Games and If Statements Chapter 5: Guessing Games with Random Numbers and Loops Chapter 6: Introduction to Graphics Chapter 7: Back to Looping Chapter 8: Introduction to Lists Chapter 9: Introduction to Animation Chapter 10: Functions Chapter 11: Controllers and Graphics Chapter 12: Bitmapped Graphics and Sound Chapter 13: Introduction to Classes Chapter 14: Introduction to Sprites Chapter 15: Libraries and Modules Chapter 16: Searching Chapter 17: Array-Backed Grids Chapter 18: Sorting Chapter 19: Exceptions Chapter 20: Recursion Chapter 21: Formatting Chapter 22: Exercises
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值