In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "how to achieve a good-looking clock effect in python". The editor shows you the operation process through an actual case. The operation method is simple and fast, and it is practical. I hope this article "how to achieve a good-looking clock effect in python" can help you solve the problem.
The game uses trigonometric functions used in middle and high school and other knowledge development, to make a long story short, on the complete program.
#-*-coding:utf-8-*-import sys,random,math,pygamefrom pygame.locals import * from datetime import datetime,date,timedef print_text (font,x,y,text,color= (255255255)): imgText=font.render (text,True,color) screen.blit (imgText, (xmemy)) def wrap_angle (angle): return angle% 360pygame.init () screen=pygame.display.set_mode ([600500]) pygame.display.set_caption ("AnalogClock") font = pygame.font.Font (None) 36) orange=220,180,0white=255255255yellow=255,255,0pink=255100100pos_x=300pos_y=250radius=250angle=260while True: screen.fill ([0Power0100]) for event in pygame.event.get (): if event.type==QUIT: sys.exit () keys=pygame.key.get_pressed () if Keys [K _ ESCAPE]: sys.exit () screen.fill ([0mem0100]) pygame.draw.circle (screen,white, (pos_x,pos_y), radius 6) for n in range (1B13): angle=math.radians (n * (360 + 12)-90) x=math.cos (angle) * (radius-20)-10 y=math.sin (angle) * (radius-20)-10 print_text (font, pos_x+x, pos_y+y) Str (n) today=datetime.today () hours=today.hour% 12 minutes=today.minute seconds=today.second hour_angle=wrap_angle (hours* (360 up 12)-90) hour_angle=math.radians (hour_angle) hour_x=math.cos (hour_angle) * (radius-80) hour_y=math.sin (hour_angle) * (radius-80) target= (pos_x+hour_x,pos_y+hour_y) pygame.draw.line (screen,pink, (pos_x,pos_y), target 25) min_angle=wrap_angle (minutes* (260amp 60)-90) min_angle=math.radians (min_angle) min_x=math.cos (min_angle) * (radius-60) min_y=math.sin (min_angle) * (radius-60) target= (pos_x+min_x,pos_y+min_y) pygame.draw.line (screen,orange, (pos_x,pos_y), target 12) sec_angle=wrap_angle (seconds* (360 amp 60)-90) sec_angle=math.radians (sec_angle) sec_x=math.cos (sec_angle) * (radius-40) sec_y=math.sin (sec_angle) * (radius-40) target= (pos_x+sec_x,pos_y+sec_y) pygame.draw.line (screen,yellow, (pos_x,pos_y), target,6) pygame.draw.circle (screen,white, (pos_x,pos_y)) 20) print_text (font, 0,0, str (hours) + ":" + str (minutes) + ":" + str (seconds)) pygame.display.update ()
The compiled result is:
This is the end of the content about "how to achieve a good-looking clock effect in python". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.