def go(): unicorn.brightness(1) unicorn.rotation(90) wrd_rgb = [[154, 173, 154], [0, 255, 0], [0, 200, 0], [0, 162, 0], [0, 145, 0], [0, 96, 0], [0, 74, 0], [0, 0, 0,]] clock = 0 blue_pilled_population = [[randint(0,7), 7]] t_end = time.time() + 10 while time.time() < t_end: for person in blue_pilled_population: y = person[1] for rgb in wrd_rgb: if (y <= 7) and (y >= 0): unicorn.set_pixel(person[0], y, rgb[0], rgb[1], rgb[2]) y += 1 person[1] -= 1 unicorn.show() time.sleep(0.1) clock += 1 if clock % 5 == 0: blue_pilled_population.append([randint(0,7), 7]) if clock % 7 == 0: blue_pilled_population.append([randint(0,7), 7]) while len(blue_pilled_population) > 100: blue_pilled_population.pop(0)
def option_2():###Select a website to create the light show your_webiste_choice = raw_input("Please enter the web address") final_address = "http://%s" %(your_webiste_choice) print "finding", final_address website = urllib2.urlopen(final_address ) ##print website.read() sentence = website.read() print sentence ###Checks the letters in the website, then works out the co- ordinates### for letter in sentence: index = ord(letter)-65 #print index ### remove when complete### if index > 0: x = int(index/8.0) #print x ### remove when complete### #x = x - 4 y = int(index%8) #print (x, y) UH.clear UH.brightness(0.2) UH.set_pixel(y, x, 0, 255, 0) UH.set_pixel(x, y, 0, 255, 0) UH.show() time.sleep(0.02) UH.clear() elif index <= 0: random_sparkle()
def uh_show_matrix(mat, pause = .075): for y in range(len(mat)): for x in range(len(mat[0])): uh.set_pixel(x, y, mat[x][y][0], mat[x][y][1], mat[x][y][2]) uh.show() time.sleep(pause)
def go(): effects = [tunnel, rainbow_search, checker, swirl] unicorn.brightness(1) step = 0 t_end = time.time() + 10 while time.time() < t_end: for i in range(500): for y in range(8): for x in range(8): r, g, b = effects[0](x, y, step) if i > 400: r2, g2, b2 = effects[-1](x, y, step) ratio = (500.00 - i) / 100.0 r = r * ratio + r2 * (1.0 - ratio) g = g * ratio + g2 * (1.0 - ratio) b = b * ratio + b2 * (1.0 - ratio) r = int(max(0, min(255, r))) g = int(max(0, min(255, g))) b = int(max(0, min(255, b))) unicorn.set_pixel(x, y, r, g, b) step += 1 unicorn.show() time.sleep(0.01) effect = effects.pop() effects.insert(0, effect)
def fill(r=0,g=255,b=0): for x in range(8): for y in range(8): unicorn.set_pixel(8-x-1, 8-y-1, r, g, b) unicorn.show() time.sleep(0.05) time.sleep(2)
def drawpet(pet): for y in range(8): for x in range(8): #set pixel with color r, g, b = pet[y][x] unicorn.set_pixel(x,y,r,g,b) unicorn.show()
def draw_dot( x1, y1, r1, g1, b1, str1): "This draws the dot and outputs some text" UH.set_pixel(x1,y1,r1,g1,b1) UH.show() # print (str1 + str(x1) + ' ' + str(y1)) time.sleep(0.1) return
def effect(): # trigger effect for i in range(steps_per * 8): for y in range(8): for x in range(8): r, g, b = background(x, y, i) r = int(max(0, min(255, r))) g = int(max(0, min(255, g))) b = int(max(0, min(255, b))) unicorn.set_pixel(x, y, r, g, b) unicorn.show() time.sleep(0.01) for i in range(200): v = (math.sin(i / 6.0) + 1.0) / 2.0 for y in range(8): for x in range(8): r = 0 b = 0 g = 100 g *= tick_mask[y][x] g *= v r = int(max(0, min(255, r))) g = int(max(0, min(255, g))) b = int(max(0, min(255, b))) unicorn.set_pixel(x, y, r, g, b) unicorn.show() time.sleep(0.02)
def writePixel(pixel): #try: #GPIO.setup(int(pin), GPIO.IN) #if GPIO.input(int(pin)) == True: # response = "Pin number " + pin + " is high!" #else: # response = "Pin number " + pin + " is low!" #except: #response = "There was an error reading pin " + pin + "." color = int(pixel) for i in range(0,8): UH.set_pixel(0,i,color,color,color) UH.show() response="All correct" now = datetime.datetime.now() timeString = now.strftime("%Y-%m-%d %H:%M") templateData = { 'title' : 'Status of Pixel' + str(pixel), 'time': timeString, 'response' : response } return render_template('main.html', **templateData)
def kick_rainbow(): random_r = randint(0,255) random_g = randint(0,255) random_b = randint(0,255) random_math_r = randint(32,640) random_math_g = randint(32,640) random_math_b = randint(32,640) bright = 1 i = 0.0 offset = 30 for q in range(20): #splash a kick for 20 revs i = i + 0.3 for y in range(4): for x in range(8): r = 0#x * 32 g = 0#y * 32 xy = x + y / 4 r = (math.cos((x+i)/2.0) + math.cos((y+i)/2.0)) * 64 + 128.0 g = (math.sin((x+i)/1.5) + math.sin((y+i)/2.0)) * 64 + 128.0 b = (math.sin((x+i)/2.0) + math.cos((y+i)/1.5)) * 64 + 128.0 r = max(0, min(random_r, r + offset)) g = max(0, min(random_g, g + offset)) b = max(0, min(random_b, b + offset)) unicorn.set_pixel(x,y,int(r),int(g),int(b)) unicorn.brightness(bright) unicorn.show() time.sleep(0.001) if bright > 0.3: bright = bright - 0.01 #fade on each pass until black unicorn.clear()
def showTime(time,col,r,g,b): binary = '{0:08b}'.format(time) for y in range(8): if binary[y] == '1': uni.set_pixel(col,y,r,g,b) else: uni.set_pixel(col,y,0,0,0)
def set_build_success(self): self.logger.debug("Last build worked !") for y in range(8): for x in range(8): UH.set_pixel(x, y, 0, 255, 0) UH.show() time.sleep(0.05)
def random_pixel(color_function): """ Generate a randomly positioned pixel with the color returned by color_function. Args: color_function (func): Should return a (R,G,B) color value. """ color = color_function() def random_position(): """ Get the position of a random pixel bound by function_pos. """ x = randint(0, function_pos[load_sparkles]) y = randint(0, (height-1)) return (x,y) selected_pixel = random_position() ''' Aesthetic: If the randomly generated pixel is currently lit, turn it off and try with a new pixel. Also works as sort of a population control on how many pixels will be lit. ''' while sum(unicorn.get_pixel(*selected_pixel)) > 0: unicorn.set_pixel(*(selected_pixel + (0, 0, 0))) selected_pixel = random_position() unicorn.set_pixel(*(selected_pixel + color)) return
def initialize(): for i in range(8): unicorn.set_pixel(0,i, 255,255,255) unicorn.set_pixel(7,i, 255,255,255) unicorn.show() sleep(0.1-i*float(0.01)) ship_pos = [3,7] for i in range(2): unicorn.set_pixel(ship_pos[0],ship_pos[1], ship[1], ship[2], ship[3]) unicorn.show() sleep(0.2) unicorn.set_pixel(ship_pos[0],ship_pos[1], 0,0,0) unicorn.show() sleep(0.2) cell = [None,0,0,0] temp_mat = [] matrix = [] for y in range(0,8): temp_mat.append(list(cell)) for x in range(0,8): matrix.append(list(temp_mat)) matrix[ship_pos[0]][ship_pos[1]] = ship print matrix unicorn.set_pixel(ship_pos[0],ship_pos[1], ship[1], ship[2], ship[3]) unicorn.show() return matrix
def uni_show(prev_x, prev_y): a = np.random.rand(1) b = np.random.rand(1) c = np.random.rand(1) rgb_on = colorsys.hsv_to_rgb(a, b, c) rgb_off = colorsys.hsv_to_rgb(0.5, 0.5, 0.1) r_on = int(rgb_on[0]*255.0) g_on = int(rgb_on[1]*255.0) b_on = int(rgb_on[2]*255.0) r_off = int(rgb_off[0]*255.0) g_off = int(rgb_off[1]*255.0) b_off = int(rgb_off[2]*255.0) a = np.random.rand(1) x = int(a[0] * 8)-1 b = np.random.rand(1) y = int(b[0] * 8)-1 #print x, y if x < 0: x = 0 if y < 0: y = 0 unicorn.set_pixel(x, y, r_on, g_on, b_on) unicorn.set_pixel(prev_x, prev_y, r_off, g_off, b_off) unicorn.show() return x, y
def load_rainbow(update_rate=5): """ A lightly modified version of Pimeroni's "rainbow" example. Displays a moving rainbow of colors that increases with load. Args: update_rate (float): How often to update the load value (seconds). """ i = 0.0 offset = 30 function_values[load_fetcher] = 1 threading.Thread(target=load_fetcher).start() while True: load_function = function_values[load_fetcher]/10 if function_values[load_fetcher] <= 10 else 10 for w in range(int(update_rate/0.01)): i = i + load_function for y in range(height): for x in range(function_pos[load_rainbow] + 1): r = 0#x * 32 g = 0#y * 32 xy = x + y / 4 r = (math.cos((x+i)/2.0) + math.cos((y+i)/2.0)) * 64.0 + 128.0 g = (math.sin((x+i)/1.5) + math.sin((y+i)/2.0)) * 64.0 + 128.0 b = (math.sin((x+i)/2.0) + math.cos((y+i)/1.5)) * 64.0 + 128.0 r = max(0, min(255, r + offset)) g = max(0, min(255, g + offset)) b = max(0, min(255, b + offset)) unicorn.set_pixel(x,y,int(r),int(g),int(b)) unicorn.show() time.sleep(0.01)
def option_1():###User enters a sentance to create the light show### phrase = raw_input("Please enter your phrase ").lower() ###Checks the letters in the phrase, then works out the co- ordinates### for letter in phrase: index = ord(letter)-65 #print index ### remove when complete### if index > 0: x = int(index/8.0) #print x ### remove when complete### x = x - 4 y = int(index%8) #print (x, y) UH.clear UH.brightness(0.20) UH.set_pixel(y, x, 255, 255, 255) #UH.set_pixel(x, y, 0, 255, 0) UH.show() time.sleep(0.5) UH.clear() elif index <= 0: random_sparkle()
def draw_heart(hue, brightness): for x, y in pixels_to_light: color = colorsys.hsv_to_rgb(hue, 1, brightness) color = [int(c * 255) for c in color] r, g, b = color unicorn.set_pixel(x, y, r, g, b) unicorn.show()
def display_binary(value, row, color): binary_str = "{0:8b}".format(value) for x in range(0, 8): if binary_str[x] == '1': hat.set_pixel(x, row, color[0], color[1], color[2]) else: hat.set_pixel(x, row, 0, 0, 0)
def display_matrix(max_x, max_y, text=False, r=255, g=255, b=255): """ Display the matrix, either on the unicorn or on the stdout :param max_x: :param max_y: :param text: If True, display on stdout instead of unicornhat. For debugging """ if text: for x in range(max_x): for y in range(max_y): coordinate_tuple = (x, y) if LifeCell.matrix[coordinate_tuple].current_state == 'alive': print '*', else: print '.', print print else: for x in range(max_x): for y in range(max_y): coordinate_tuple = (x, y) if LifeCell.matrix[coordinate_tuple].current_state == 'alive': unicorn.set_pixel(x, y, r, g, b) else: unicorn.set_pixel(x, y, 0, 0, 0) unicorn.show()
def setColor(full): for y in range (8): for x in range (8): if full[y][x]==0: UH.set_pixel(7-x,y,255,0,0) UH.show() time.sleep(5)
def led_field(colour): led.clear() for y in range(8): for x in range(8): led.set_pixel(x, y, colour[0], colour[1], colour[2]) led.show() time.sleep(w) return;
def fillme(): for x in range(8): for y in range(8): unicorn.set_pixel(8-x-1, 8-y-1, randint(0,255), randint(0,255), randint(0,255)) unicorn.show() time.sleep(0.05) time.sleep(2)
def piLoad(): # Loads image onto matrix uh.off() for led in leds: if led.lit: uh.set_pixel(led.pos[0], led.pos[1], led.color[0], led.color[1], led.color[2]) #print str(led.pos[0])+ ' ' +str(led.pos[1]) + ' ' + str(led.color[1]) uh.show()
def clear(self): r = 0 g = 0 b = 0 for y in range(8): for x in range(8): unicornhat.set_pixel(x, y, r, g, b) unicornhat.show()
def drawChar(offset_y, offset_x): for x in range(7,-1,-1): for y in range(8): pixel = img.getpixel(((offset_x*8)+x,(offset_y*8)+y)) r, g, b = int(pixel[0]),int(pixel[1]),int(pixel[2]) unicorn.set_pixel(x, y, r, g, b) unicorn.show() time.sleep(0.5)
def set_build_failure(self): self.logger.debug("Last build failed !") for y in range(8): for x in range(8): UH.set_pixel(x, y, 255, 0, 0) UH.show() time.sleep(0.05)
def fade(self): for y in range(8): for x in range(8): r, g, b = self._buffer[x][y] r, g, b = image_helper.fade_rgb(r, g, b) self._buffer[x][y] = (r, g, b) unicornhat.set_pixel(x, y, r, g, b) unicornhat.show()
def go(): UH.brightness(1) for y in range(8): for x in range(8): UH.set_pixel(x,y,255,0,0) UH.show() time.sleep(0.05) time.sleep(1)
def update_led(self, a, b, num): mapping = { 1: 32, 2: 16, 3: 8, 4: 4, 5: 2, 6: 1 } for x in range(1, 7): for y in range(a, b): if num[mapping[x]]: UH.set_pixel(x, y, self.prefs['on']['red'], self.prefs['on']['green'], self.prefs['on']['blue']) else: UH.set_pixel(x, y, self.prefs['off']['red'], self.prefs['off']['green'], self.prefs['off']['blue'])
def expanding_square_1(): """ Creates a square that increases in size. It does this with each of the colors. """ sleep_speed = 0.1 colors = [C1, C2, C3, C4, C5, C6, C7, C8] for color in colors: for _ in range(5): unicornhat.set_pixel(3, 3, color) unicornhat.set_pixel(3, 4, color) unicornhat.set_pixel(4, 3, color) unicornhat.set_pixel(4, 4, color) unicornhat.show() sleep(sleep_speed) unicornhat.clear() unicornhat.set_pixel(2, 2, color) unicornhat.set_pixel(3, 2, color) unicornhat.set_pixel(4, 2, color) unicornhat.set_pixel(5, 2, color) unicornhat.set_pixel(2, 3, color) unicornhat.set_pixel(2, 4, color) unicornhat.set_pixel(2, 5, color) unicornhat.set_pixel(3, 5, color) unicornhat.set_pixel(4, 5, color) unicornhat.set_pixel(5, 5, color) unicornhat.set_pixel(5, 3, color) unicornhat.set_pixel(5, 4, color) unicornhat.set_pixel(5, 5, color) unicornhat.show() sleep(sleep_speed) unicornhat.clear() unicornhat.set_pixel(1, 1, color) unicornhat.set_pixel(2, 1, color) unicornhat.set_pixel(3, 1, color) unicornhat.set_pixel(4, 1, color) unicornhat.set_pixel(5, 1, color) unicornhat.set_pixel(6, 1, color) unicornhat.set_pixel(1, 2, color) unicornhat.set_pixel(1, 3, color) unicornhat.set_pixel(1, 4, color) unicornhat.set_pixel(1, 5, color) unicornhat.set_pixel(1, 6, color) unicornhat.set_pixel(2, 6, color) unicornhat.set_pixel(3, 6, color) unicornhat.set_pixel(4, 6, color) unicornhat.set_pixel(5, 6, color) unicornhat.set_pixel(6, 6, color) unicornhat.set_pixel(6, 2, color) unicornhat.set_pixel(6, 3, color) unicornhat.set_pixel(6, 4, color) unicornhat.set_pixel(6, 5, color) unicornhat.show() sleep(sleep_speed) unicornhat.clear() unicornhat.set_pixel(0, 0, color) unicornhat.set_pixel(1, 0, color) unicornhat.set_pixel(2, 0, color) unicornhat.set_pixel(3, 0, color) unicornhat.set_pixel(4, 0, color) unicornhat.set_pixel(5, 0, color) unicornhat.set_pixel(6, 0, color) unicornhat.set_pixel(7, 0, color) unicornhat.set_pixel(0, 1, color) unicornhat.set_pixel(0, 2, color) unicornhat.set_pixel(0, 3, color) unicornhat.set_pixel(0, 4, color) unicornhat.set_pixel(0, 5, color) unicornhat.set_pixel(0, 6, color) unicornhat.set_pixel(0, 7, color) unicornhat.set_pixel(1, 7, color) unicornhat.set_pixel(2, 7, color) unicornhat.set_pixel(3, 7, color) unicornhat.set_pixel(4, 7, color) unicornhat.set_pixel(5, 7, color) unicornhat.set_pixel(6, 7, color) unicornhat.set_pixel(7, 7, color) unicornhat.set_pixel(7, 1, color) unicornhat.set_pixel(7, 2, color) unicornhat.set_pixel(7, 3, color) unicornhat.set_pixel(7, 4, color) unicornhat.set_pixel(7, 5, color) unicornhat.set_pixel(7, 6, color) unicornhat.show() sleep(sleep_speed) unicornhat.clear()
def square_off(): """ Creates a vortex pattern with each of the colors. """ sleep_speed = 0.1 unicornhat.set_pixel(3, 3, OFF) unicornhat.set_pixel(3, 4, OFF) unicornhat.set_pixel(4, 3, OFF) unicornhat.set_pixel(4, 4, OFF) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(2, 2, OFF) unicornhat.set_pixel(3, 2, OFF) unicornhat.set_pixel(4, 2, OFF) unicornhat.set_pixel(5, 2, OFF) unicornhat.set_pixel(2, 3, OFF) unicornhat.set_pixel(2, 4, OFF) unicornhat.set_pixel(2, 5, OFF) unicornhat.set_pixel(3, 5, OFF) unicornhat.set_pixel(4, 5, OFF) unicornhat.set_pixel(5, 5, OFF) unicornhat.set_pixel(5, 3, OFF) unicornhat.set_pixel(5, 4, OFF) unicornhat.set_pixel(5, 5, OFF) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(1, 1, OFF) unicornhat.set_pixel(2, 1, OFF) unicornhat.set_pixel(3, 1, OFF) unicornhat.set_pixel(4, 1, OFF) unicornhat.set_pixel(5, 1, OFF) unicornhat.set_pixel(6, 1, OFF) unicornhat.set_pixel(1, 2, OFF) unicornhat.set_pixel(1, 3, OFF) unicornhat.set_pixel(1, 4, OFF) unicornhat.set_pixel(1, 5, OFF) unicornhat.set_pixel(1, 6, OFF) unicornhat.set_pixel(2, 6, OFF) unicornhat.set_pixel(3, 6, OFF) unicornhat.set_pixel(4, 6, OFF) unicornhat.set_pixel(5, 6, OFF) unicornhat.set_pixel(6, 6, OFF) unicornhat.set_pixel(6, 2, OFF) unicornhat.set_pixel(6, 3, OFF) unicornhat.set_pixel(6, 4, OFF) unicornhat.set_pixel(6, 5, OFF) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(0, 0, OFF) unicornhat.set_pixel(1, 0, OFF) unicornhat.set_pixel(2, 0, OFF) unicornhat.set_pixel(3, 0, OFF) unicornhat.set_pixel(4, 0, OFF) unicornhat.set_pixel(5, 0, OFF) unicornhat.set_pixel(6, 0, OFF) unicornhat.set_pixel(7, 0, OFF) unicornhat.set_pixel(0, 1, OFF) unicornhat.set_pixel(0, 2, OFF) unicornhat.set_pixel(0, 3, OFF) unicornhat.set_pixel(0, 4, OFF) unicornhat.set_pixel(0, 5, OFF) unicornhat.set_pixel(0, 6, OFF) unicornhat.set_pixel(0, 7, OFF) unicornhat.set_pixel(1, 7, OFF) unicornhat.set_pixel(2, 7, OFF) unicornhat.set_pixel(3, 7, OFF) unicornhat.set_pixel(4, 7, OFF) unicornhat.set_pixel(5, 7, OFF) unicornhat.set_pixel(6, 7, OFF) unicornhat.set_pixel(7, 7, OFF) unicornhat.set_pixel(7, 1, OFF) unicornhat.set_pixel(7, 2, OFF) unicornhat.set_pixel(7, 3, OFF) unicornhat.set_pixel(7, 4, OFF) unicornhat.set_pixel(7, 5, OFF) unicornhat.set_pixel(7, 6, OFF) unicornhat.show() sleep(sleep_speed)
import unicornhat as UH import time r=94 g=41 b=41 sleepspeed=0.05 for y in range(8): if y % 2 == 0: for x in range(8): UH.set_pixel(x,y,r,g,b) UH.show() time.sleep(sleepspeed) else: for x in reversed(8): UH.set_pixel(x,y,r,g,b) UH.show() time.sleep(sleepseed) time.sleep(2)
def corner_to_corner_3_v2(color): """ Moves a square from the lower right corner to the upper left corner. Arguments: This function takes an RGB tuple as an argument argument. """ sleep_speed = 0.1 off = (0, 0, 0) unicornhat.set_pixel(7, 7, color) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(6, 7, color) unicornhat.set_pixel(6, 6, color) unicornhat.set_pixel(7, 6, color) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(5, 7, color) unicornhat.set_pixel(5, 6, color) unicornhat.set_pixel(5, 5, color) unicornhat.set_pixel(6, 5, color) unicornhat.set_pixel(7, 5, color) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(4, 7, color) unicornhat.set_pixel(4, 6, color) unicornhat.set_pixel(4, 5, color) unicornhat.set_pixel(4, 4, color) unicornhat.set_pixel(5, 4, color) unicornhat.set_pixel(6, 4, color) unicornhat.set_pixel(7, 4, color) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(3, 7, color) unicornhat.set_pixel(3, 6, color) unicornhat.set_pixel(3, 5, color) unicornhat.set_pixel(3, 4, color) unicornhat.set_pixel(3, 3, color) unicornhat.set_pixel(4, 3, color) unicornhat.set_pixel(5, 3, color) unicornhat.set_pixel(6, 3, color) unicornhat.set_pixel(7, 3, color) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(2, 7, color) unicornhat.set_pixel(2, 6, color) unicornhat.set_pixel(2, 5, color) unicornhat.set_pixel(2, 4, color) unicornhat.set_pixel(2, 3, color) unicornhat.set_pixel(2, 2, color) unicornhat.set_pixel(3, 2, color) unicornhat.set_pixel(4, 2, color) unicornhat.set_pixel(5, 2, color) unicornhat.set_pixel(6, 2, color) unicornhat.set_pixel(7, 2, color) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(1, 7, color) unicornhat.set_pixel(1, 6, color) unicornhat.set_pixel(1, 5, color) unicornhat.set_pixel(1, 4, color) unicornhat.set_pixel(1, 3, color) unicornhat.set_pixel(1, 2, color) unicornhat.set_pixel(1, 1, color) unicornhat.set_pixel(2, 1, color) unicornhat.set_pixel(3, 1, color) unicornhat.set_pixel(4, 1, color) unicornhat.set_pixel(5, 1, color) unicornhat.set_pixel(6, 1, color) unicornhat.set_pixel(7, 1, color) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(0, 7, color) unicornhat.set_pixel(0, 6, color) unicornhat.set_pixel(0, 5, color) unicornhat.set_pixel(0, 4, color) unicornhat.set_pixel(0, 3, color) unicornhat.set_pixel(0, 2, color) unicornhat.set_pixel(0, 1, color) unicornhat.set_pixel(0, 0, color) unicornhat.set_pixel(1, 0, color) unicornhat.set_pixel(2, 0, color) unicornhat.set_pixel(3, 0, color) unicornhat.set_pixel(4, 0, color) unicornhat.set_pixel(5, 0, color) unicornhat.set_pixel(6, 0, color) unicornhat.set_pixel(7, 0, color) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(7, 0, off) unicornhat.set_pixel(7, 1, off) unicornhat.set_pixel(7, 2, off) unicornhat.set_pixel(7, 3, off) unicornhat.set_pixel(7, 4, off) unicornhat.set_pixel(7, 5, off) unicornhat.set_pixel(7, 6, off) unicornhat.set_pixel(7, 7, off) unicornhat.set_pixel(6, 7, off) unicornhat.set_pixel(5, 7, off) unicornhat.set_pixel(4, 7, off) unicornhat.set_pixel(3, 7, off) unicornhat.set_pixel(2, 7, off) unicornhat.set_pixel(1, 7, off) unicornhat.set_pixel(0, 7, off) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(6, 0, off) unicornhat.set_pixel(6, 1, off) unicornhat.set_pixel(6, 2, off) unicornhat.set_pixel(6, 3, off) unicornhat.set_pixel(6, 4, off) unicornhat.set_pixel(6, 5, off) unicornhat.set_pixel(6, 6, off) unicornhat.set_pixel(5, 6, off) unicornhat.set_pixel(4, 6, off) unicornhat.set_pixel(3, 6, off) unicornhat.set_pixel(2, 6, off) unicornhat.set_pixel(1, 6, off) unicornhat.set_pixel(0, 6, off) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(5, 0, off) unicornhat.set_pixel(5, 1, off) unicornhat.set_pixel(5, 2, off) unicornhat.set_pixel(5, 3, off) unicornhat.set_pixel(5, 4, off) unicornhat.set_pixel(5, 5, off) unicornhat.set_pixel(4, 5, off) unicornhat.set_pixel(3, 5, off) unicornhat.set_pixel(2, 5, off) unicornhat.set_pixel(1, 5, off) unicornhat.set_pixel(0, 5, off) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(4, 0, off) unicornhat.set_pixel(4, 1, off) unicornhat.set_pixel(4, 2, off) unicornhat.set_pixel(4, 3, off) unicornhat.set_pixel(4, 4, off) unicornhat.set_pixel(3, 4, off) unicornhat.set_pixel(2, 4, off) unicornhat.set_pixel(1, 4, off) unicornhat.set_pixel(0, 4, off) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(3, 0, off) unicornhat.set_pixel(3, 1, off) unicornhat.set_pixel(3, 2, off) unicornhat.set_pixel(3, 3, off) unicornhat.set_pixel(2, 3, off) unicornhat.set_pixel(1, 3, off) unicornhat.set_pixel(0, 3, off) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(2, 0, off) unicornhat.set_pixel(2, 1, off) unicornhat.set_pixel(2, 2, off) unicornhat.set_pixel(1, 2, off) unicornhat.set_pixel(0, 2, off) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(1, 0, off) unicornhat.set_pixel(1, 1, off) unicornhat.set_pixel(0, 1, off) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(0, 0, off) unicornhat.show() sleep(sleep_speed)
def set_my_pixels(payload): for x in range(width): #8 for y in range(height): #4 or 8 r, g, b = payload[y][x] unicorn.set_pixel(x, y, r, g, b)
def pion(): for x in range(8): for y in range(4): uh.set_pixel(x, y, 255, 0, 255) uh.show()
def yeon(): for x in range(8): for y in range(4): uh.set_pixel(x, y, 255, 255, 0) uh.show()
#!/usr/bin/env python import unicornhat as UH import time UH.set_pixel(0, 0, 255, 0, 0) UH.set_pixel(7, 0, 255, 0, 0) UH.set_pixel(1, 1, 255, 0, 0) UH.set_pixel(6, 1, 255, 0, 0) UH.set_pixel(2, 2, 255, 0, 0) UH.set_pixel(5, 2, 255, 0, 0) UH.set_pixel(3, 3, 255, 0, 0) UH.set_pixel(4, 3, 255, 0, 0) UH.set_pixel(4, 4, 255, 0, 0) UH.set_pixel(3, 2, 255, 0, 0) UH.set_pixel(5, 5, 255, 0, 0) UH.set_pixel(6, 6, 255, 0, 0) UH.set_pixel(7, 7, 255, 0, 0) UH.show() time.sleep(15)
def plot_points(): unicorn.clear() for point in points: unicorn.set_pixel(point.x, point.y, point.colour[0], point.colour[1], point.colour[2]) unicorn.show()
def clear(): for y in range(8): for x in range(8): unicorn.set_pixel(x, y, 0, 0, 0) unicorn.show()
from random import randint import unicornhat as unicorn import math import random import time intensity = 0.9 unicorn.set_layout(unicorn.AUTO) unicorn.rotation(0) width, height = unicorn.get_shape() def rand_flicker_sleep(): time.sleep(random.randint(1, 6) / 100.0) while True: x = randint(0, (width - 1)) y = randint(0, (height - 1)) r = randint(75, 140) g = randint(33, 68) b = 0 r_intensity = math.pow(intensity + 0.1, 0.95) unicorn.brightness(r_intensity) unicorn.set_pixel(x, y, r, g, b) unicorn.show() rand_flicker_sleep()
def dataReceived(self, data): rawbytes = map(ord, data) #print "len(rawbytes) %d" % len(rawbytes) #print rawbytes i = 0 while (i < len(rawbytes)): #print "parseState %d i %d" % (OPC.parseState, i) if (OPC.parseState == 0): # get OPC.pktChannel OPC.pktChannel = rawbytes[i] i += 1 OPC.parseState += 1 elif (OPC.parseState == 1): # get OPC.pktCommand OPC.pktCommand = rawbytes[i] i += 1 OPC.parseState += 1 elif (OPC.parseState == 2): # get OPC.pktLength.highbyte OPC.pktLength = rawbytes[i] << 8 i += 1 OPC.parseState += 1 elif (OPC.parseState == 3): # get OPC.pktLength.lowbyte OPC.pktLength |= rawbytes[i] i += 1 OPC.parseState += 1 OPC.pixelCount = 0 OPC.pixelLimit = min(3 * OPC.MAX_LEDS, OPC.pktLength) #print "OPC.pktChannel %d OPC.pktCommand %d OPC.pktLength %d OPC.pixelLimit %d" % \ # (OPC.pktChannel, OPC.pktCommand, OPC.pktLength, OPC.pixelLimit) if (OPC.pktLength > 3 * OPC.MAX_LEDS): print "Received pixel packet exeeds size of buffer! Data discarded." if (OPC.pixelLimit == 0): OPC.parseState = 0 elif (OPC.parseState == 4): copyBytes = min(OPC.pixelLimit - OPC.pixelCount, len(rawbytes) - i) if (copyBytes > 0): OPC.pixelCount += copyBytes #print "OPC.pixelLimit %d OPC.pixelCount %d copyBytes %d" % \ # (OPC.pixelLimit, OPC.pixelCount, copyBytes) if ((OPC.pktCommand == 0) and (OPC.pktChannel <= 1)): x = 0 y = 0 iLimit = i + copyBytes while ((i < iLimit) and (y < 8)): #print "i %d" % (i) r = rawbytes[i] i += 1 g = rawbytes[i] i += 1 b = rawbytes[i] i += 1 unicorn.set_pixel(x, y, r, g, b) #print "x %d y %d r %d g %d b %d" % (x,y,r,g,b) x += 1 if (x > 7): x = 0 y += 1 if (OPC.pixelCount >= OPC.pixelLimit): unicorn.show() else: i += copyBytes if (OPC.pixelCount == OPC.pktLength): OPC.parseState = 0 else: OPC.parseState += 1 elif (OPC.parseState == 5): discardBytes = min(OPC.pktLength - OPC.pixelLimit, len(rawbytes) - i) #print "discardBytes %d" % (discardBytes) OPC.pixelCount += discardBytes i += discardBytes if (OPC.pixelCount >= OPC.pktLength): OPC.parseState = 0 else: print "Invalid OPC.parseState %d" % (OPC.parseState)
def corner_to_corner_1(): """ Moves a square from the lower left corner to the upper right corner. """ sleep_speed = 0.1 off = (0, 0, 0) colors = [off, C1, C2, C3, C4, C5, C6, C7, C8] for color in colors: unicornhat.set_pixel(0, 7, color) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(0, 6, color) unicornhat.set_pixel(1, 6, color) unicornhat.set_pixel(1, 7, color) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(0, 5, color) unicornhat.set_pixel(1, 5, color) unicornhat.set_pixel(2, 5, color) unicornhat.set_pixel(2, 6, color) unicornhat.set_pixel(2, 7, color) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(0, 4, color) unicornhat.set_pixel(1, 4, color) unicornhat.set_pixel(2, 4, color) unicornhat.set_pixel(3, 4, color) unicornhat.set_pixel(3, 5, color) unicornhat.set_pixel(3, 6, color) unicornhat.set_pixel(3, 7, color) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(0, 3, color) unicornhat.set_pixel(1, 3, color) unicornhat.set_pixel(2, 3, color) unicornhat.set_pixel(3, 3, color) unicornhat.set_pixel(4, 3, color) unicornhat.set_pixel(4, 4, color) unicornhat.set_pixel(4, 5, color) unicornhat.set_pixel(4, 6, color) unicornhat.set_pixel(4, 7, color) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(0, 2, color) unicornhat.set_pixel(1, 2, color) unicornhat.set_pixel(2, 2, color) unicornhat.set_pixel(3, 2, color) unicornhat.set_pixel(4, 2, color) unicornhat.set_pixel(5, 2, color) unicornhat.set_pixel(5, 3, color) unicornhat.set_pixel(5, 4, color) unicornhat.set_pixel(5, 5, color) unicornhat.set_pixel(5, 6, color) unicornhat.set_pixel(5, 7, color) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(0, 1, color) unicornhat.set_pixel(1, 1, color) unicornhat.set_pixel(2, 1, color) unicornhat.set_pixel(3, 1, color) unicornhat.set_pixel(4, 1, color) unicornhat.set_pixel(5, 1, color) unicornhat.set_pixel(6, 1, color) unicornhat.set_pixel(6, 2, color) unicornhat.set_pixel(6, 3, color) unicornhat.set_pixel(6, 4, color) unicornhat.set_pixel(6, 5, color) unicornhat.set_pixel(6, 6, color) unicornhat.set_pixel(6, 7, color) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(0, 0, color) unicornhat.set_pixel(1, 0, color) unicornhat.set_pixel(2, 0, color) unicornhat.set_pixel(3, 0, color) unicornhat.set_pixel(4, 0, color) unicornhat.set_pixel(5, 0, color) unicornhat.set_pixel(6, 0, color) unicornhat.set_pixel(7, 0, color) unicornhat.set_pixel(7, 1, color) unicornhat.set_pixel(7, 2, color) unicornhat.set_pixel(7, 3, color) unicornhat.set_pixel(7, 4, color) unicornhat.set_pixel(7, 5, color) unicornhat.set_pixel(7, 6, color) unicornhat.set_pixel(7, 7, color) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(0, 0, off) unicornhat.set_pixel(0, 1, off) unicornhat.set_pixel(0, 2, off) unicornhat.set_pixel(0, 3, off) unicornhat.set_pixel(0, 4, off) unicornhat.set_pixel(0, 5, off) unicornhat.set_pixel(0, 6, off) unicornhat.set_pixel(0, 7, off) unicornhat.set_pixel(1, 7, off) unicornhat.set_pixel(2, 7, off) unicornhat.set_pixel(3, 7, off) unicornhat.set_pixel(4, 7, off) unicornhat.set_pixel(5, 7, off) unicornhat.set_pixel(6, 7, off) unicornhat.set_pixel(7, 7, off) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(1, 0, off) unicornhat.set_pixel(1, 1, off) unicornhat.set_pixel(1, 2, off) unicornhat.set_pixel(1, 3, off) unicornhat.set_pixel(1, 4, off) unicornhat.set_pixel(1, 5, off) unicornhat.set_pixel(1, 6, off) unicornhat.set_pixel(2, 6, off) unicornhat.set_pixel(3, 6, off) unicornhat.set_pixel(4, 6, off) unicornhat.set_pixel(5, 6, off) unicornhat.set_pixel(6, 6, off) unicornhat.set_pixel(7, 6, off) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(2, 0, off) unicornhat.set_pixel(2, 1, off) unicornhat.set_pixel(2, 2, off) unicornhat.set_pixel(2, 3, off) unicornhat.set_pixel(2, 4, off) unicornhat.set_pixel(2, 5, off) unicornhat.set_pixel(3, 5, off) unicornhat.set_pixel(4, 5, off) unicornhat.set_pixel(5, 5, off) unicornhat.set_pixel(6, 5, off) unicornhat.set_pixel(7, 5, off) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(3, 0, off) unicornhat.set_pixel(3, 1, off) unicornhat.set_pixel(3, 2, off) unicornhat.set_pixel(3, 3, off) unicornhat.set_pixel(3, 4, off) unicornhat.set_pixel(4, 4, off) unicornhat.set_pixel(5, 4, off) unicornhat.set_pixel(6, 4, off) unicornhat.set_pixel(7, 4, off) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(4, 0, off) unicornhat.set_pixel(4, 1, off) unicornhat.set_pixel(4, 2, off) unicornhat.set_pixel(4, 3, off) unicornhat.set_pixel(5, 3, off) unicornhat.set_pixel(6, 3, off) unicornhat.set_pixel(7, 3, off) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(5, 0, off) unicornhat.set_pixel(5, 1, off) unicornhat.set_pixel(5, 2, off) unicornhat.set_pixel(6, 2, off) unicornhat.set_pixel(7, 2, off) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(6, 0, off) unicornhat.set_pixel(6, 1, off) unicornhat.set_pixel(7, 1, off) unicornhat.show() sleep(sleep_speed) unicornhat.set_pixel(7, 0, off) unicornhat.show() sleep(sleep_speed)
import unicornhat as uh import random import time uh.set_layout(uh.PHAT) brightness_min = 0.25 brightness_max = 0.9 brightness_delta = 0.1 brightness = brightness_min while True: for i in range(8): for j in range(4): uh.set_pixel(i, j, 255, 0, 0) brightness += brightness_delta if brightness > brightness_max: brightness_delta = -0.1 if brightness < brightness_min: brightness_delta = 0.1 uh.brightness(brightness) uh.show() time.sleep(0.1)
for option, arg in options: if option == '-h': print( 'set-unicorn-color.py -r <red value> -g <green value> -b <blue value>' ) print('set-unicorn-color.py -c <defined color name>') print('set-unicorn-color.py -x <color hex code>') sys.exit() elif option in ("-r", "--red"): red_value = arg elif option in ("-g", "--green"): green_value = arg elif option in ("-b", "--blue"): blue_value = arg elif option in ("-c", "--color"): red_value, green_value, blue_value = colorconstants.colors[arg] unicorn.set_layout(unicorn.AUTO) unicorn.rotation(0) unicorn.brightness(1) width, height = unicorn.get_shape() for y in range(height): for x in range(width): unicorn.set_pixel(x, y, red_value, green_value, blue_value) unicorn.show() while True: time.sleep(1)
def set_pixel(data): key = data.get('key', None) x, y = get_position_for_key(key) r, g, b = data.get('rgb', (None, None, None)) unicorn.set_pixel(x, y, r, g, b)
def on_green(): for x in range(8): for y in range(4): unicornhat.set_pixel(x, y, 0, 255, 0) unicornhat.show()
else: unicorn.set_pixel(x, y, 0, 0, 0) def draw_char(c, pos): if c in chars: val = chars[c] for y in range(0, 4): for x in range(0 + pos - offset, 3 + pos - offset): set_pixel(x, y, val) val = val >> 1 text = 'My IP address is xxxxxxxxx' offset = -8 while True: i = i + 0.3 for y in range(height): for x in range(width): unicorn.set_pixel(x,y,0,0,0) pos = 0 for c in text: draw_char(c, pos) pos = pos + 4 unicorn.show() time.sleep(speed) offset = offset + 1 if offset > len(text) * 4: offset = -8 # time.sleep(1)
def gron(): for x in range(8): for y in range(4): uh.set_pixel(x, y, 0, 128, 0) uh.show()
def drawBarGreen(bar_width, row): for x in range(0, bar_width): unicorn.set_pixel(x, row, math.floor((x / width) * 255), 160, 0)
def lightup(output): for i in range(0, 8): for j in range(0, 8): if output[i][j] == 1: unicornhat.set_pixel(i, j, 255, 124, 124) unicornhat.show()
def pixel(self, x, y, col): if x < 0 or x > 7 or y < 0 or y > 7: return False self.buffer[(x, y)] = col unicorn.set_pixel(x, y, col.r, col.g, col.b)
def test_flash(): unicornhat.set_pixel(0, 0, 255, 255, 255) unicornhat.show() unicornhat.clear() unicornhat.show()
Follow the white rabbit... """) unicorn.set_layout(unicorn.HAT) unicorn.rotation(90) unicorn.brightness(0.5) wrd_rgb = [[154, 173, 154], [0, 255, 0], [0, 200, 0], [0, 162, 0], [0, 145, 0], [0, 96, 0], [0, 74, 0], [0, 0, 0,]] clock = 0 blue_pilled_population = [[randint(0,7), 7]] while True: for person in blue_pilled_population: y = person[1] for rgb in wrd_rgb: if (y <= 7) and (y >= 0): unicorn.set_pixel(person[0], y, rgb[0], rgb[1], rgb[2]) y += 1 person[1] -= 1 unicorn.show() time.sleep(0.1) clock += 1 if clock % 5 == 0: blue_pilled_population.append([randint(0,7), 7]) if clock % 7 == 0: blue_pilled_population.append([randint(0,7), 7]) while len(blue_pilled_population) > 100: blue_pilled_population.pop(0)
def lbon(): for x in range(8): for y in range(4): uh.set_pixel(x, y, 0, 128, 128) uh.show()
unicorn.set_layout(unicorn.PHAT) unicorn.brightness(0.5) print("Reticulating splines") time.sleep(.5) print("Enabled unicorn poop module!") time.sleep(.5) print("Pooping rainbows...") i = 0.0 offset = 30 while True: i = i + 0.3 for y in range(4): for x in range(8): r = 0 #x * 32 g = 0 #y * 32 xy = x + y / 4 r = (math.cos((x + i) / 2.0) + math.cos( (y + i) / 2.0)) * 64.0 + 128.0 g = (math.sin((x + i) / 1.5) + math.sin( (y + i) / 2.0)) * 64.0 + 128.0 b = (math.sin((x + i) / 2.0) + math.cos( (y + i) / 1.5)) * 64.0 + 128.0 r = max(0, min(255, r + offset)) g = max(0, min(255, g + offset)) b = max(0, min(255, b + offset)) unicorn.set_pixel(x, y, int(r), int(g), int(b)) unicorn.show() time.sleep(0.01)
def showNum(num, cols, colOffset, r, g, b): for col in range(cols): for row in range(4): if (col * 4) + (row + 1) <= num: unicorn.set_pixel(col + colOffset, row, r, g, b)
def drawBarRed(bar_width, row): for x in range(0, bar_width): unicorn.set_pixel(x, row, 255, math.floor((x / width) * 255), 0)
import unicornhat as u from random import randint import time import sys u.brightness(float(sys.argv[4])) a = 0 r = int(sys.argv[1]) g = int(sys.argv[2]) b = int(sys.argv[3]) while True: for x in xrange(8): for y in xrange(8): print "u.set_pixel({0}, {1}, {2}, {3}, {4})".format(x, y, r, g, b) u.set_pixel(x, y, r, g, b) u.show() print "done" time.sleep(100)
#!/usr/bin/env python3 import unicornhat as unicorn import time from random import randint unicorn.set_layout(unicorn.AUTO) unicorn.rotation(0) unicorn.brightness(0.4) uh_width, uh_height = unicorn.get_shape() for rot in [0, 90, 180, 270]: print(rot) unicorn.rotation(rot) unicorn.set_pixel(0, 0, 255, 255, 255) print(unicorn.get_rotation()) unicorn.show() time.sleep(1)