def lightup_2ch_vu(matrix_past, matrix_LED, remain_LED, dBSc, colorHue, fgt): for x in range(0, 2): for y in range(0, 16): color = -0.15+y/30 if color < 0: color = 0.0 if y+1>(15-matrix_past[x]): if y==(15-matrix_past[x]): sat = remain_LED[x]*1.0/dBSc else: sat = 1.0 # unicornhathd.set_pixel_hsv(15-8*x , y, color, 1-(y/colorHue), sat) unicornhathd.set_pixel_hsv(15-8*x-1, y, color, 1-(y/colorHue), sat) unicornhathd.set_pixel_hsv(15-8*x-2, y, color, 1-(y/colorHue), sat) unicornhathd.set_pixel_hsv(15-8*x-3, y, color, 1-(y/colorHue), sat) unicornhathd.set_pixel_hsv(15-8*x-4, y, color, 1-(y/colorHue), sat) unicornhathd.set_pixel_hsv(15-8*x-5, y, color, 1-(y/colorHue), sat) unicornhathd.set_pixel_hsv(15-8*x-6, y, color, 1-(y/colorHue), sat) # unicornhathd.set_pixel_hsv(15-8*x-7, y, color, 1-(y/colorHue), sat) else: # unicornhathd.set_pixel_hsv(15-8*x , y, color, 1-(y/colorHue), 0.0) unicornhathd.set_pixel_hsv(15-8*x-1, y, color, 1-(y/colorHue), 0.0) unicornhathd.set_pixel_hsv(15-8*x-2, y, color, 1-(y/colorHue), 0.0) unicornhathd.set_pixel_hsv(15-8*x-3, y, color, 1-(y/colorHue), 0.0) unicornhathd.set_pixel_hsv(15-8*x-4, y, color, 1-(y/colorHue), 0.0) unicornhathd.set_pixel_hsv(15-8*x-5, y, color, 1-(y/colorHue), 0.0) unicornhathd.set_pixel_hsv(15-8*x-6, y, color, 1-(y/colorHue), 0.0) # unicornhathd.set_pixel_hsv(15-8*x-7, y, color, 1-(y/colorHue), 0.0) unicornhathd.show() return matrix_past
def game_over(): for i in range(16): hat.set_pixel(i, i, *red) hat.set_pixel(15 - i, i, *red) hat.show() playsound('fail.mp3') sys.exit()
def lightup_8B_gr_hat(matrix_past, matrix_LED, remain_LED, dBSc, colorHue, fgt): for x in range(0, 8): if matrix_past[x]<matrix_LED[x]: matrix_past[x]=matrix_LED[x] for y in range(0, 16): # Bars color = -0.25+y/30 if color < 0: color = 0.0 if y+1>(15-matrix_LED[x]): if y==(15-matrix_LED[x]): #sat = remain_LED[x]*1.0/dBSc sat = 1.0 else: sat = 1.0 unicornhathd.set_pixel_hsv(15-2*x, y, color, 1-(y/colorHue), sat) unicornhathd.set_pixel_hsv(15-2*x-1, y, color, 1-(y/colorHue), sat) else: unicornhathd.set_pixel_hsv(15-2*x, y, color , 1-(y/colorHue), 0.0) unicornhathd.set_pixel_hsv(15-2*x-1, y, color , 1-(y/colorHue), 0.0) # Hats if y==(15-matrix_past[x]): unicornhathd.set_pixel_hsv(15-2*x, y-1, 2*x/15, 0.0, 0.7) unicornhathd.set_pixel_hsv(15-2*x-1, y-1, 2*x/15, 0.0, 0.7) unicornhathd.show() return matrix_past
def draw_icon(image): width, height = unicornhathd.get_shape() for x in range(width): for y in range(height): pixel = image.getpixel((y,x)) r, g, b = int(pixel[0]),int(pixel[1]),int(pixel[2]) unicornhathd.set_pixel(x, y, r, g, b) unicornhathd.show()
def main(): # rotate so the bottom right is the origin rather # than the bottom left. unicornhathd.clear() unicornhathd.rotation(90) # rotate display 90 deg # print the border (in blue) for x in range(16): # First two columns, last two # columns, and the first and # last two rows if (x < 4) or (x > 11): for y in range(16): # pass the horizontal pos, # vertical pos, then the # amount of red, grn, blue unicornhathd.set_pixel(x, y, 0, 0, 64) else: for y in (0, 1, 14, 15): unicornhathd.set_pixel(x, y, 0, 0, 64) try: while True: # get the date values and place them in a tuple # so we can access each value serially dt = datetime.now().timetuple() # Create and empty list to hold binary values bins = [] # convert to $width digit binaries # We access the first 6 values in the tuple # which include the fields we are interested in for field in range(6): bins.append(numpy.binary_repr(dt[field], width)) # and now for each of the binary values stored # in bins for x in range(len(bins)): # set the column number to decrease left to # right as the Unicorn hat is numbered col = 10 - x # create a character accessible list of each # binary number binNums = list(bins[x]) for c in range(len(binNums)): # we want to access the chars in binNums, # but we also need to start at row 2 row = c + 2 if binNums[c] == '0': unicornhathd.set_pixel(col, row, 255, 0, 0) else: unicornhathd.set_pixel(col, row, 0, 255, 0) # display the pixels unicornhathd.show() except KeyboardInterrupt: print("Exiting...") unicornhathd.off()
def lightup_16B_rb(matrix_past, matrix_LED, remain_LED, dBSc, colorHue, fgt): for x in range(0, 16): for y in range(0, 16): if y+1>(15-matrix_past[x]): if y==(15-matrix_past[x]): sat = remain_LED[x]*1.0/dBSc else: sat = 1.0 unicornhathd.set_pixel_hsv(15-x, y, x/15, 1-(y/colorHue), sat) else: unicornhathd.set_pixel_hsv(15-x, y, x/15, 1-(y/colorHue), 0.0) unicornhathd.show() return matrix_past
def lightup_8B_gr(matrix_past, matrix_LED, remain_LED, dBSc, colorHue, fgt): for x in range(0, 8): for y in range(0, 16): color = -0.15+y/30 if color < 0: color = 0.0 if y+1>(15-matrix_past[x]): if y==(15-matrix_past[x]): sat = remain_LED[x]*1.0/dBSc else: sat = 1.0 unicornhathd.set_pixel_hsv(15-2*x, y, color, 1-(y/colorHue), sat) unicornhathd.set_pixel_hsv(15-2*x-1, y, color, 1-(y/colorHue), sat) else: unicornhathd.set_pixel_hsv(15-2*x, y, color , 1-(y/colorHue), 0.0) unicornhathd.set_pixel_hsv(15-2*x-1, y, color , 1-(y/colorHue), 0.0) unicornhathd.show() return matrix_past
def flash_quadrant(quadrant): if quadrant == 1: for i in range(8): for j in range(8): hat.set_pixel(i, j, *green) elif quadrant == 2: for i in range(8): for j in range(8): hat.set_pixel(i, j + 8, *red) elif quadrant == 3: for i in range(8): for j in range(8): hat.set_pixel(i + 8, j, *yellow) elif quadrant == 4: for i in range(8): for j in range(8): hat.set_pixel(i + 8, j + 8, *blue) hat.show() playsound('short-beep.mp3')
def clear_all(): for i in range(16): for j in range(16): hat.set_pixel(i, j, *white) hat.show()
#!/usr/bin/env python # Adapted from @tanurai's "Be Still, My Beating Heart" # https://learn.pimoroni.com/tutorial/tanya/be-still-my-beating-heart from unicorn_hat_sim import unicornhathd as unicorn import time, colorsys from emoji import list unicorn.brightness(1) unicorn.rotation(270) for emoji in list: for y in range(16): for x in range(16): h = emoji.h s = emoji.s v = emoji.bitmap[x, y] rgb = colorsys.hsv_to_rgb(h, s, v) r = int(rgb[0] * 255.0) g = int(rgb[1] * 255.0) b = int(rgb[2] * 255.0) unicorn.set_pixel(x, y, r, g, b) unicorn.show() time.sleep(0.005) time.sleep(10)