Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random;random.seed()
- import json
- import time
- import pygame, pygame.gfxdraw
- data = {}
- hue_shift = 1.5
- cycle_time = 10 * 1000
- saturation = 70
- lightness = 85
- stroke_size = 5
- cell_padding_width = 1.2
- cell_padding_height = 1.1
- txt_color = (255,255,255)
- instructors = []
- actions = []
- with open("pie.json") as f:
- data = json.load(f)
- data["instructors"] = list(map(str.title,data.get('instructors',instructors)))
- instructors = data["instructors"]
- actions = list(map(str.capitalize,data.get("actions",actions)))
- data["actions"] = actions
- scores = data.get("scores",{})
- data["scores"] = scores
- for instructor in instructors:
- scores[instructor] = scores.get(instructor,{})
- for action in data["actions"]:
- scores[instructor][action] = scores[instructor].get(action,0)
- def generate_actions():
- while True:
- axn = random.choice(actions)
- victim = random.choice(instructors)
- yield axn, victim
- pygame.display.init()
- pygame.font.init()
- font = pygame.font.SysFont(pygame.font.get_default_font(),54)
- clock = pygame.time.Clock()
- trigger = pygame.time.Clock()
- window = pygame.display.set_mode((0,0),pygame.FULLSCREEN|pygame.HWSURFACE)
- gen = generate_actions()
- width, height = window.get_size()
- center_x = width // 2
- center_y = width // 2
- delay = 30
- wait = 5 * 1000
- passed = wait
- alive = True
- fmtstr = "{} {}.".format
- color_rate = hue_shift // ((360//hue_shift))
- color_passed = 0
- bg_color = pygame.Color(0,0,0)
- bg_color.hsla = (0,saturation,lightness,100)
- overlay_surf = pygame.Surface((width, height),pygame.SRCALPHA)
- overlay_surf.fill((0,0,0,60))
- window.fill(bg_color)
- instructor = ""
- action = ""
- nsurf = None
- action_surfs = {axn:font.render(axn,True,txt_color) for axn in actions+["Instructor"]}
- instructor_surfs = {person:font.render(person,True,txt_color) for person in instructors}
- twidth = 0
- theight = 0
- for action in action_surfs.values():
- twidth += action.get_width() * cell_padding_width + stroke_size
- theight = max(theight,action.get_height() * cell_padding_height + stroke_size)
- for instructor in instructor_surfs.values():
- theight += instructor.get_height() * cell_padding_height
- #table = pygame.Surface((twidth * cell_padding_width, theight * cell_padding_height),pygame.SRCALPHA)
- #table.blit(action_surfs["Instructor"],())
- #pygame.gfxdraw.vline(table,action_surfs["Instructor"].get_width(),0,table.get_height(),txt_color)
- while alive:
- nt = clock.tick(delay)
- passed += nt
- color_passed += nt
- if passed >= wait:
- passed = 0
- action,instructor = next(gen)
- msg = fmtstr(action,instructor)
- nsurf = font.render(msg,True,txt_color)
- overlay_surf = pygame.Surface((width, nsurf.get_height()*2),pygame.SRCALPHA)
- overlay_surf.fill((0,0,0,60))
- if color_passed >= color_rate:
- h,s,l,a = bg_color.hsla
- color_passed = 0
- h += hue_shift
- if h>=360:
- h = 0
- bg_color.hsla = (h,s,l,a)
- window.fill(bg_color)
- #window.blit(overlay_surf,(0,0))
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- alive = False
- if event.type == pygame.KEYDOWN:
- if event.key == pygame.K_ESCAPE:
- alive = False
- if event.key == pygame.K_SPACE:
- scores[instructor][action] += 1
- # draw the present action.
- x = (width-nsurf.get_width()) // 2
- y = (height-nsurf.get_height()) // 2
- window.blit(overlay_surf,(0,y-(nsurf.get_height())//2))
- window.blit(nsurf,(x,y))
- #window.blit(table,(0,0))
- pygame.display.flip()
- with open("pie.json","w") as f:
- json.dump(data,f)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement