def getstravabargraph(): global totaldistance totaldistance = 0 activitiesthisyear = client.get_activities( after=mondaypst, limit=500) # Download all activities this year for activity in activitiesthisyear: totaldistance += float(stravalib.unithelper.miles( activity.distance)) #add up the total distance limit = 0 bargraph = [] #Get the most recent 5 activities to draw the bar chart for activity in sorted(activitiesthisyear, key=sortby, reverse=True): bargraph.append( int( math.ceil( float(stravalib.unithelper.miles(activity.distance)) / km_per_pixel))) limit += 1 if limit == 5: #only get most recent 5 activities (1 per row of pixels) break bargraph.reverse() return bargraph # def drawgraph(values): scrollphat.clear_buffer() for row, value in enumerate(values): for col in range(0, 11): if value <= col: scrollphat.set_pixel(col, row, False) else: scrollphat.set_pixel(col, row, True) scrollphat.update()
def clear(fast=False): log_str('clear scroll') if not fast: for x in range(11): for y in range(5): scrollphat.set_pixel(x, y, 0) sleep(0.015) scrollphat.update() scrollphat.clear_buffer() scrollphat.clear() scrollphat.update()
def scrollphat_output(days, hours, minutes, seconds, total): global start_seconds start_seconds = start_seconds or total bar = int(5 * (float(total) / start_seconds)) scrollphat.clear_buffer() s = str(seconds) indent = 2 if len(s) == 1: indent = 4 scrollphat.write_string(s, indent) for y in range(bar): scrollphat.set_pixel(0, y, 1) scrollphat.update()
def render(): # LED check scrollphat.clear_buffer() for col in range(0, 13): if col > 1: scrollphat.set_col(col - 2, 0) if col < 11: scrollphat.set_col(col, 0b11111) scrollphat.update() time.sleep(.1) time.sleep(.3) while _running: scrollphat.clear_buffer() # ``_output`` access should be thread-safe; de-referenced just once for rend, value in zip(DISPLAY, _output): try: rend(value, scrollphat) except ValueError as e: logging.warn(e, exc_info=True) scrollphat.update() time.sleep(.05)
while True: my_delta = datetime.datetime(year=YEAR,month=1,day=1,hour=0,minute=0) - datetime.datetime.now() days_left = math.floor(my_delta.days + (my_delta.seconds/86400)) hours_left = math.ceil((my_delta.days * 24) + (my_delta.seconds/3600)) minutes_left = math.ceil((my_delta.days * 24 * 60) + (my_delta.seconds/60)) seconds_left = math.ceil((my_delta.days * 24 * 3600) + my_delta.seconds) if hours_left >= 55: count_string = '{0}D'.format(days_left) elif minutes_left >= 60: count_string = '{0}H'.format(hours_left) elif seconds_left >= 60: count_string = '{0}M'.format(minutes_left) else: count_string = '{0}S'.format(seconds_left) if count_string != last_time: scrollphat.clear_buffer() for i in range(11): scrollphat.scroll() time.sleep(0.01) scrollphat.clear_buffer() scrollphat.write_string(count_string, 11) for i in range(scrollphat.buffer_len()-12): scrollphat.scroll() time.sleep(0.05) last_time = count_string time.sleep(0.2) except KeyboardInterrupt: scrollphat.clear() sys.exit(-1)
def show_str(string=TEST_STRING): log_str(string) scrollphat.clear_buffer() scrollphat.write_string(string)
def main(win): direction = "RIGHT" snakeX=[2, 1, 0] snakeY=[2, 2, 2] snakeLength = 3 score = 0 gameOver = False scrollphat.set_brightness(5) scrollphat.write_string(" PI SNAKE") length = scrollphat.buffer_len() for i in range(length): scrollphat.scroll() time.sleep(0.06) fruitX = random.randint(0,10) fruitY = random.randint(0,4) fruitBlink = True win.nodelay(True) key="" while 1: if gameOver == False: # move snake head forward in the direction its travelling if direction == "RIGHT": if snakeX[0] < 10: snakeX[0] = snakeX[0] + 1 if direction == "LEFT": if snakeX[0] > 0: snakeX[0] = snakeX[0] - 1 if direction == "UP": if snakeY[0] > 0: snakeY[0] = snakeY[0]- 1 if direction == "DOWN": if snakeY[0] < 4: snakeY[0] = snakeY[0] + 1 # check if the new head position is illegal for i in range(1, snakeLength): if snakeX[i] == snakeX[0] and snakeY[i] == snakeY[0]: gameOver = True # check if the new head position is at a fruit if snakeX[0] == fruitX and snakeY[0] == fruitY: snakeLength = snakeLength + 1 score = score + 1 snakeX.append(fruitX) snakeY.append(fruitY) fruitX = random.randint(0,10) fruitY = random.randint(0,4) time.sleep(0.15) scrollphat.clear_buffer() # shift all the snake parts forward for i in range(1, snakeLength): snakeX[snakeLength - i] = snakeX[snakeLength - i - 1] snakeY[snakeLength - i] = snakeY[snakeLength - i - 1] # draw the snake for i in range(0, snakeLength): scrollphat.set_pixel(snakeX[i],snakeY[i],True) # blink the fruit if fruitBlink: scrollphat.set_pixel(fruitX,fruitY,True) fruitBlink = False else: scrollphat.set_pixel(fruitX,fruitY,False) fruitBlink = True scrollphat.update() else: # game over gameOverText = "GAME OVER - SCORE: " + str(score) + " PRESS SPACE TO RESTART" time.sleep(0.7) scrollphat.clear_buffer() scrollphat.write_string(gameOverText,len(gameOverText)) win.clear() win.addstr(gameOverText) while True: try: scrollphat.scroll() time.sleep(0.07) key = win.getkey() if str(key) == " ": break except Exception as e: # No input pass direction = "RIGHT" snakeX=[2, 1, 0] snakeY=[2, 2, 2] snakeLength = 3 score = 0 gameOver = False try: key = win.getkey() win.clear() win.addstr("PI SNAKE - SCORE: ") win.addstr(str(score)) if str(key) == "KEY_RIGHT": direction = "RIGHT" if str(key) == "KEY_LEFT": direction = "LEFT" if str(key) == "KEY_UP": direction = "UP" if str(key) == "KEY_DOWN": direction = "DOWN" if key == os.linesep: break except Exception as e: # No input pass