def gameOverAnimation(color=WHITE, animationSpeed=50): # play all beeps at once, then flash the background origSurf = DISPLAYSURF.copy() flashSurf = pygame.Surface(DISPLAYSURF.get_size()) flashSurf = flashSurf.convert_alpha() BEEP1.play() # play all four beeps at the same time, roughly. BEEP2.play() BEEP3.play() BEEP4.play() r, g, b = color for i in range(3): # do the flash 3 times for start, end, step in ((0, 255, 1), (255, 0, -1)): # The first iteration in this loop sets the following for loop # to go from 0 to 255, the second from 255 to 0. for alpha in range(start, end, animationSpeed * step): # animation loop # alpha means transparency. 255 is opaque, 0 is invisible checkForQuit() flashSurf.fill((r, g, b, alpha)) DISPLAYSURF.blit(origSurf, (0, 0)) DISPLAYSURF.blit(flashSurf, (0, 0)) drawButtons() pygame.display.update() touchphat.all_on() FPSCLOCK.tick(FPS) touchphat.all_off()
def wait_for_server(): while True: # wait for server socket try: touchphat.all_on() s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.settimeout(1) s.connect((args.server, args.port)) s.setblocking(False) return s except socket.error: touchphat.all_off() time.sleep(1)
def display_starting_animation(): """Displays animatation at game start Lights up LEDs in an animation sequence to signal to the player that the game is about to begin. """ time.sleep(0.5) for led in touchphat.NAMES: touchphat.led_on(led) time.sleep(0.1) touchphat.led_off(led) for i in range(3): touchphat.all_on() time.sleep(0.5) touchphat.all_off() time.sleep(0.5)
def handle_touch(event): print('press D event start') for led in range(1,7): touchphat.led_on(led) sleep(0.25) camera.capture('image{0:04d}.jpg'.format(led)) touchphat.led_off(led) sleep(0.25) system('convert -delay 20 -loop 0 image*.jpg animation.gif') touchphat.all_on() sleep(0.25) touchphat.all_off() sleep(0.25) touchphat.all_on() sleep(0.25) touchphat.all_off() print('finished converting to gif animation')
def handle_release(event): global enter global sharp global tone_color global enter_start_time global sharp_start_time global enter_time global sharp_time shutdown_time = 5 if event.name == "Enter": enter = 0 pygame.mixer.stop() enter_stop_time = time.time() enter_time = enter_stop_time - enter_start_time print(enter_time) elif event.name == "Back": sharp = 0 pygame.mixer.stop() sharp_stop_time = time.time() sharp_time = sharp_stop_time - sharp_start_time print(sharp_time) else: if key_dict[event.name] + enter + sharp > 12: print("chage") else: tone[key_dict[event.name] + enter + sharp + tone_color * tone_num].stop() if enter_time > shutdown_time and sharp_time > shutdown_time: print("shutdown") for pad in ['Enter', 'D', 'C', 'B', 'A', 'Back']: touchphat.set_led(pad, True) time.sleep(0.1) touchphat.set_led(pad, False) time.sleep(0.1) for i in range(3): touchphat.all_on() time.sleep(0.1) touchphat.all_off() time.sleep(0.1) os.system("sudo shutdown -h now") print(event.name + " release")
def handle_touch(event): touchphat.led_on("Enter") twitter = Twython( consumer_key, consumer_secret, access_token, access_token_secret ) message = "Selfie-gif at this #PatriotPi #Rjam on a RPi zero with TouchPhat and Camera module" image = open('animation.gif', 'rb') response = twitter.upload_media(media=image) media_id = [response['media_id']] twitter.update_status(status=message, media_ids=media_id) touchphat.led_off("Enter") touchphat.all_on() sleep(0.25) touchphat.all_off() sleep(0.25) touchphat.all_on() sleep(0.25) touchphat.all_off() print('I think it just tweeted. IDK go check it')
def turnonled_all(): touchphat.all_on()