Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4912

Beginners • Re: Clock ident on TV

$
0
0
try this...

Code:

#!/usr/bin/env python3import pygame, sysimport timefrom pygame.locals import *import datetimeimport mathwidth  = 800height = 480clock = pygame.image.load('clock.jpg')pygame.init()windowSurfaceObj = pygame.display.set_mode((width, height), pygame.NOFRAME, 24)yellow = pygame.Color(240,200,0)while True:   now = datetime.datetime.now()   newtime = now.strftime("%H%M%S")   windowSurfaceObj.blit(clock, (0, 0))   # show hour hand   newhrs = (int(newtime[0:2]) + (int(newtime[2:4])/60))   rad = math.radians(newhrs * 21.8)   v1 = int(height/2 +(30 * math.sin(rad)))   h1 = int(width/2  +(30 * math.cos(rad)))   v2 = int(height/2 +(147 * math.sin(rad)))   h2 = int(width/2  +(147 * math.cos(rad)))   pygame.draw.line(windowSurfaceObj,yellow,[h1,v1],[h2, v2],6)   # show minute hand   newmins = (int(newtime[2:4]) + (int(newtime[4:6])/60))   rad = math.radians((newmins -15) * 6)   v1 = int(height/2 +(30 * math.sin(rad)))   h1 = int(width/2  +(30 * math.cos(rad)))   v2 = int(height/2 +(180 * math.sin(rad)))   h2 = int(width/2  +(180 * math.cos(rad)))   pygame.draw.line(windowSurfaceObj,yellow,[h1,v1],[h2, v2],4)   # show seconds hand   newsecs = (int(newtime[4:6]))   rad = math.radians((newsecs - 15) * 6)   v1 = int(height/2 +(30 * math.sin(rad)))   h1 = int(width/2  +(30 * math.cos(rad)))   v2 = int(height/2 +(200 * math.sin(rad)))   h2 = int(width/2  +(200 * math.cos(rad)))   pygame.draw.line(windowSurfaceObj,yellow,[h1,v1],[h2, v2],2)   pygame.display.update()   time.sleep(0.1)      # read mouse or keyboard   for event in pygame.event.get():       if event.type == QUIT:          pygame.quit()          sys.exit()       elif event.type == MOUSEBUTTONUP or event.type == KEYDOWN:          kz = 0          if event.type == KEYDOWN:             kz = event.key             if kz == K_ESCAPE:                pygame.quit()                sys.exit()
clock.jpg

Statistics: Posted by gordon77 — Sun Oct 13, 2024 10:35 am



Viewing all articles
Browse latest Browse all 4912

Trending Articles