• 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版本

  • 相关阅读:
    默哀STAND SILENTLY!
    用虚拟机优化Windows(update:2008.4.24)
    UE的心情指数?
    God of War III 的发售日期?
    2009/8/15应该是一个愉快的夜晚.为林肯公园中国10月演唱会做好准备
    北京2008奥运会完美谢幕!
    《The Pursuit of Happyness / 当幸福来敲门》(2006)
    2007林肯公园上海演唱会观后感(实况像片/MP3) update:2008.1.31
    2008早上好
    Active Object C++智能指针实现
  • 原文地址:https://www.cnblogs.com/lq147760524/p/8309000.html
Copyright © 2020-2023  润新知