def tick(): currenttime = time.localtime() currenthour = currenttime.tm_hour currentmin = currenttime.tm_min currentsec = currenttime.tm_sec # Set daytime or nighttime brightness setBrightness(currenttime) d.clear() # Draw the circle around the clock d.circle(O_X, O_Y, R, Color(255, 0, 255)) # Draw the clock hands d.circle_line(O_X, O_Y, R - 1, (-360.0 * (currenthour / 12.0)), Color(255, 0, 0)) d.circle_line(O_X, O_Y, R - 1, (-360.0 * (currentmin / 60.0)), Color(0, 255, 0)) d.circle_line(O_X, O_Y, R - 1, (-360.0 * (currentsec / 60.0)), Color(0, 0, 255)) # draw buffer to hardware d.show() threading.Timer(1, tick).start()
def tick(): currenthour = time.localtime().tm_hour currentmin = time.localtime().tm_min currentsec = time.localtime().tm_sec d.clear() d.circle(O_X, O_Y, R, Color(255, 0, 255)) d.circle_line(O_X, O_Y, R - 1, 360.0 * (currenthour / 60.0), Color(255, 0, 0)) d.circle_line(O_X, O_Y, R - 1, 360.0 * (currentmin / 60.0), Color(0, 255, 0)) d.circle_line(O_X, O_Y, R - 1, 360.0 * (currentsec / 60.0), Color(0, 0, 255)) d.show() threading.Timer(1, tick).start()
def __init__(self, text : str = "", color : Color = Color(255, 255, 255), font : str = "monospace", size : int = 28, name : str = "New Text"): assert(text, str) assert(color , Color) assert(font, str) assert(size, numbers.Number) Renderer.__init__(self, name = name) self.text = text self.color = color #TODO: Create font class self.size = int(size) self.font = pygame.font.SysFont("monospace", self.size)
def tick(): currenttime = time.localtime() currenthour = currenttime.tm_hour currentmin = currenttime.tm_min currentsec = currenttime.tm_sec # Set seconds counter float_sec = (time.time() % 60) / 59.0 seconds_progress = float_sec * 15 # Set daytime or nighttime brightness setBrightness(currenttime) d.clear() # Draw the circle around the clock d.circle(O_X, O_Y, R, Color(22, 0, 22)) if int(time.time()) % 2 == 0: d.circle(O_X, O_Y, R, Color(22, 22, 22)) d.circle(O_X, O_Y, R + 1, Color(22, 0, 22)) d.circle(O_X, O_Y, R + 2, Color(22, 0, 22)) d.circle(O_X, O_Y, R + 3, Color(22, 0, 22)) unicorn.set_pixel(1, 1, 22, 0, 22) unicorn.set_pixel(1, 13, 22, 0, 22) unicorn.set_pixel(13, 13, 22, 0, 22) unicorn.set_pixel(13, 1, 22, 0, 22) # Draw the clock hands d.circle_line(O_X, O_Y, R, (360.0 * (currentmin / 60.0)), Color(152, 83, 80)) d.circle_line(O_X, O_Y, R - 2, (360.0 * ((currenthour % 12) / 12.0)), Color(122, 0, 122)) # Display seconds progress by blinking dot if int(time.time()) % 2 == 0: unicorn.set_pixel(math.floor(seconds_progress), 0, 81, 81, 82) # draw buffer to hardware d.show() threading.Timer(1, tick).start()
import pygame, sys from graphics import Point, Rect, Color, Surface, load_bitmap, load_font, Patch9 box = Patch9(load_bitmap("gui/simple_box.png")) font = load_font('proggy-tiny') text = font('hello user.') background = Color(0x10, 0, 0x50) front = Color(0xA5, 0x56, 0x94) red = Color(0xFF, 0x00, 0x00) redfont = font.recolor(front) redtext = redfont('hi.') redbox = box.recolor(front) def animation_frame(screen): background.paint(screen, screen.rect) front.paint(screen, front.rect.move(Point(10, 10))) box.paint(screen, screen.rect.inset(100, 10, 10, 10)) text.paint(screen, text.rect.move(Point(200, 200))) redtext.paint(screen, redtext.rect.move(Point(200, 216))) redbox.paint(screen, redbox.rect.move(Point(200, 230))) def dispatch(event): if event.type == pygame.QUIT: sys.exit(0)
import pygame import graphics import sys from graphics import Color, Surface font = graphics.load_font('proggy-tiny') greeting = font("Hello world.") background = Color(0x10, 0x30, 0x20) def animation_frame(screen): background.paint(screen, screen.rect) greeting.paint( screen, greeting.rect.move(screen.rect.center - greeting.rect.center)) def dispatch(event): if event.type == pygame.QUIT or event.type == pygame.KEYUP: sys.exit(0) pygame.display.init() screen = Surface(pygame.display.set_mode((320, 240))) while 1: for event in pygame.event.get(): dispatch(event) animation_frame(screen) pygame.display.flip()