async def set_blink(self): # Create a list with the x and y coordinates of the eye when it blinks x_blink_on = [ 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30, 31, 31, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7 ] y_blink_on = [ 0, 0, 15, 0, 15, 0, 15, 0, 15, 0, 15, 0, 15, 0, 15, 0, 15, 0, 15, 0, 15, 0, 15, 0, 15, 0, 15, 0, 0, 0, 15, 0, 15, 0, 15, 0, 15, 0, 15, 0, 15, 0, 15, 0, 15, 0, 15, 0, 15, 0, 15, 0, 15, 0, 15, 0 ] LEDMatrix.gfx_set_all(GFX_OFF) # Set the LEDs on for blinking position of the eye for b in range(0, len(x_blink_on)): LEDMatrix.gfx_set_px(x_blink_on[b], y_blink_on[b]) # Make the eye blinking appear on the matrices for 0.12 secs LEDMatrix.gfx_render() await asyncio.sleep(0.12) # Set the blinking off for b in range(0, len(x_blink_on)): LEDMatrix.gfx_set_px(x_blink_on[b], y_blink_on[b])
async def happy(self): happy_x = [28,28,28,29,29,29,29,29,30,30,30,30,30,30,31,31,31,31,31,31,16,16,16,16,16,16,17,17,17,17,17,18,18,18,13,13,13,14,14,14,14,14,15,15,15,15,15,15,0,0,0,0,0,0,1,1,1,1,1,1,2,2,2,2,2,3,3,3] happy_y = [1,0,15,2,1,0,15,14,2,1,0,15,14,13,1,0,15,14,13,12,2,1,0,15,14,13,2,1,0,15,14,1,0,15,1,0,15,2,1,0,15,14,2,1,0,15,14,13,1,0,15,14,13,12,2,1,0,15,14,13,2,1,0,15,14,1,0,15] LEDMatrix.gfx_set_all(GFX_OFF) self.set_borders() for b in range(0,len(happy_x)): LEDMatrix.gfx_set_px(happy_x[b],happy_y[b]) LEDMatrix.gfx_render() await asyncio.sleep(3) await self.set_blink() self.set_borders() for b in range(0,len(happy_x)): LEDMatrix.gfx_set_px(happy_x[b],happy_y[b]) LEDMatrix.gfx_render() await asyncio.sleep(3) await self.set_blink() Button.happy_flag = False
def movePong(): global delay_time, dot_dir # top / bottom if dot[1] + dot_dir[1] > 8*LEDMatrix.MATRIX_WIDTH-1 or dot[1] + dot_dir[1] < 0: dot_dir[1] = - dot_dir[1] # cpu side if dot[0] + dot_dir[0] < 1: if round(dot[1] + dot_dir[1]) >= round(cpu_position_bottom) and round(dot[1] + dot_dir[1]) <= round(cpu_position_bottom) + board_height: dot_dir[0] = - dot_dir[0] dot_dir[1] = choice([uniform(0.3, 0.55), uniform(-0.55, -0.3)]) delay_time = max(0.03, delay_time - 0.01) else: dot[0] = 1 dot[1] = int(round(8*LEDMatrix.MATRIX_HEIGHT/2)) dot_dir = [choice([2/3.0, 3/4.0, 4/5.0, 1.0]), uniform(0.85, 1) * choice([0.5, -0.5])] points[1] += 1 setPoints() return # user side elif dot[0] + dot_dir[0] > 8*LEDMatrix.MATRIX_WIDTH - 2: if round(dot[1] + dot_dir[1]) >= round(board_position_bottom) and round(dot[1] + dot_dir[1]) <= round(board_position_bottom) + board_height: dot_dir[0] = - dot_dir[0] dot_dir[1] = choice([uniform(0.3, 0.55), uniform(-0.55, -0.3)]) delay_time = max(0.03, delay_time - 0.01) else: dot[0] = 8*LEDMatrix.MATRIX_WIDTH-2 dot[1] = int(round(8*LEDMatrix.MATRIX_HEIGHT/2)) dot_dir = [choice([-2/3.0, -3/4.0, -4/5.0, -1.0]), uniform(0.85, 1) * choice([0.5, -0.5])] points[0] += 1 setPoints() return dot[0] = dot[0] + dot_dir[0] dot[1] = dot[1] + dot_dir[1] LEDMatrix.gfx_set_px(int(round(dot[0])), int(round(dot[1])), GFX_ON)
async def sad(self): sad_x = [ 29, 29, 30, 30, 31, 16, 16, 17, 17, 14, 14, 15, 15, 0, 1, 1, 2, 2 ] sad_y = [ 1, 13, 0, 14, 15, 0, 14, 1, 13, 1, 13, 0, 14, 15, 0, 14, 1, 13 ] LEDMatrix.gfx_set_all(GFX_OFF) self.set_borders() for b in range(0, len(sad_x)): LEDMatrix.gfx_set_px(sad_x[b], sad_y[b]) LEDMatrix.gfx_render() await asyncio.sleep(3) await self.set_blink() self.set_borders() for b in range(0, len(sad_x)): LEDMatrix.gfx_set_px(sad_x[b], sad_y[b]) LEDMatrix.gfx_render() await asyncio.sleep(3) #await self.set_blink() await self.state.end_interaction()
def display(): # displays all on the LED Matrices LEDMatrix.gfx_set_all(GFX_OFF) for p in tail: LEDMatrix.gfx_set_px(int(p.x), int(p.y), GFX_ON) LEDMatrix.gfx_set_px(int(target.x), int(target.y), GFX_ON) LEDMatrix.gfx_render() global wasDisplayed wasDisplayed = True
def movePong(): global delay_time, dot_dir # top / bottom if dot[1] + dot_dir[1] > 8 * LEDMatrix.MATRIX_WIDTH - 1 or dot[ 1] + dot_dir[1] < 0: dot_dir[1] = -dot_dir[1] # cpu side if dot[0] + dot_dir[0] < 1: if round(dot[1] + dot_dir[1]) >= round(cpu_position_bottom) and round( dot[1] + dot_dir[1]) <= round(cpu_position_bottom) + board_height: dot_dir[0] = -dot_dir[0] dot_dir[1] = choice([uniform(0.3, 0.55), uniform(-0.55, -0.3)]) delay_time = max(0.03, delay_time - 0.01) else: dot[0] = 1 dot[1] = int(round(8 * LEDMatrix.MATRIX_HEIGHT / 2)) dot_dir = [ choice([2 / 3.0, 3 / 4.0, 4 / 5.0, 1.0]), uniform(0.85, 1) * choice([0.5, -0.5]) ] points[1] += 1 setPoints() return # user side elif dot[0] + dot_dir[0] > 8 * LEDMatrix.MATRIX_WIDTH - 2: if round(dot[1] + dot_dir[1]) >= round( board_position_bottom) and round(dot[1] + dot_dir[1]) <= round( board_position_bottom) + board_height: dot_dir[0] = -dot_dir[0] dot_dir[1] = choice([uniform(0.3, 0.55), uniform(-0.55, -0.3)]) delay_time = max(0.03, delay_time - 0.01) else: dot[0] = 8 * LEDMatrix.MATRIX_WIDTH - 2 dot[1] = int(round(8 * LEDMatrix.MATRIX_HEIGHT / 2)) dot_dir = [ choice([-2 / 3.0, -3 / 4.0, -4 / 5.0, -1.0]), uniform(0.85, 1) * choice([0.5, -0.5]) ] points[0] += 1 setPoints() return dot[0] = dot[0] + dot_dir[0] dot[1] = dot[1] + dot_dir[1] LEDMatrix.gfx_set_px(int(round(dot[0])), int(round(dot[1])), GFX_ON)
async def sad(self): sad_x = [29,29,30,30,31,16,16,17,17,14,14,15,15,0,1,1,2,2] sad_y = [1,13,0,14,15,0,14,1,13,1,13,0,14,15,0,14,1,13] for b in range(0,len(sad_x)): LEDMatrix.gfx_set_px(sad_x[b],sad_y[b]) LEDMatrix.gfx_render() await asyncio.sleep(3) await self.set_blink() for b in range(0,len(sad_x)): LEDMatrix.gfx_set_px(sad_x[b],sad_y[b]) LEDMatrix.gfx_render() await asyncio.sleep(3) await self.set_blink() self.neutral()
def set_borders(self): # Create a list with the column numbers that create the borders of the eyes borders_col = [24, 25, 21, 22, 9, 10, 6, 7] # Create a list with the x and y coordinates of the LEDs needed to be set off # (previously set on by the columns) to create the corners of the borders of the eyes x_corners_off = [24,24,24,24,24,25,25,25,21,21,21,22,22,22,22,22,9,9,9,9,9,10,10,10,6,6,6,7,7,7,7,7] y_corners_off = [7,6,5,9,8,7,6,8,7,6,8,7,6,5,9,8,7,6,5,9,8,7,6,8,7,6,8,7,6,5,9,8] # Create a list with the x and y coordinates of the LEDs needed to complete the borders of the eyes x_borders_on = [26,26,26,26,27,27,27,27,28,28,28,28,29,29,29,29,30,30,30,30,31,31,31,31,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,14,15,15,15,15,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5] y_borders_on =[6,5,10,9,6,5,10,9,6,5,10,9,6,5,10,9,6,5,10,9,6,5,10,9,6,5,10,9,6,5,10,9,6,5,10,9,6,5,10,9,6,5,10,9,6,5,10,9,6,5,10,9,6,5,10,9,6,5,10,9,6,5,10,9,6,5,10,9,6,5,10,9,6,5,10,9,6,5,10,9,6,5,10,9,6,5,10,9,] # Set on the columns of the list borders_col for column in borders_col: LEDMatrix.gfx_set_col(column) # Set off the corners of the eye (previously set on by the columns) for b in range(0,len(x_corners_off)): LEDMatrix.gfx_set_px(x_corners_off[b],y_corners_off[b]) # Set the rest of the LEDs that create the borders on for b in range(0,len(x_borders_on)): LEDMatrix.gfx_set_px(x_borders_on[b],y_borders_on[b])
async def full(self): full_x = [ 24, 24, 24, 24, 9, 9, 9, 9, 25, 25, 10, 10, 26, 26, 26, 26, 26, 26, 26, 26, 26, 11, 11, 11, 11, 11, 11, 11, 11, 11, 27, 27, 12, 12, 28, 28, 28, 28, 13, 13, 13, 13, 29, 29, 29, 29, 29, 29, 29, 14, 14, 14, 14, 14, 14, 14, 30, 30, 30, 30, 30, 15, 15, 15, 15, 15, 31, 31, 31, 31, 31, 0, 0, 0, 0, 0, 16, 16, 16, 16, 1, 1, 1, 1, 17, 17, 17, 17, 17, 17, 17, 2, 2, 2, 2, 2, 2, 2, 18, 18, 18, 18, 18, 3, 3, 3, 3, 3, 20, 20, 20, 20, 20, 20, 20, 20, 20, 5, 5, 5, 5, 5, 5, 5, 5, 5, 21, 21, 21, 6, 6, 6, 22, 22, 22, 22, 7, 7, 7, 7 ] full_y = [ 6, 4, 10, 8, 6, 4, 10, 8, 5, 9, 5, 9, 6, 4, 1, 0, 15, 14, 13, 10, 8, 6, 4, 1, 0, 15, 14, 13, 10, 8, 1, 15, 1, 15, 6, 4, 10, 8, 6, 4, 10, 8, 5, 1, 0, 15, 14, 13, 9, 5, 1, 0, 15, 14, 13, 9, 6, 4, 13, 10, 8, 6, 4, 13, 10, 8, 1, 0, 15, 14, 13, 1, 0, 15, 14, 13, 6, 4, 10, 8, 6, 4, 10, 8, 5, 1, 0, 15, 14, 13, 9, 5, 1, 0, 15, 14, 13, 9, 6, 4, 13, 10, 8, 6, 4, 13, 10, 8, 6, 4, 1, 0, 15, 14, 13, 10, 8, 6, 4, 1, 0, 15, 14, 13, 10, 8, 5, 13, 9, 5, 13, 9, 6, 4, 10, 8, 6, 4, 10, 8 ] LEDMatrix.gfx_set_all(GFX_OFF) for b in range(0, len(full_x)): LEDMatrix.gfx_set_px(full_x[b], full_y[b]) LEDMatrix.gfx_render() await asyncio.sleep(3) await self.set_blink() for b in range(0, len(full_x)): LEDMatrix.gfx_set_px(full_x[b], full_y[b]) LEDMatrix.gfx_render() await asyncio.sleep(3) await self.set_blink()
def set_iris(self, position): # Iris Position 1 - Neutral Position iris_1_x = [29,29,29,29,30,30,30,30,31,31,31,31,16,16,16,16,17,17,17,17,14,14,14,14,15,15,15,15,0,0,0,0,1,1,1,1,2,2,2,2] iris_1_y = [1,0,15,14,1,0,15,14,1,0,15,14,1,0,15,14,1,0,15,14,1,0,15,14,1,0,15,14,1,0,15,14,1,0,15,14,1,0,15,14,] # Iris Position 2 - Iris positioned left iris_2_x = [27,27,27,27,28,28,28,28,29,29,29,29,30,30,30,30,31,31,31,31,12,12,12,12,13,13,13,13,14,14,14,14,15,15,15,15,0,0,0,0] iris_2_y = iris_1_y # Iris Position 3 - Iris positioned right iris_3_x = [31,31,31,31,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4] iris_3_y = iris_1_y # Set Iris Position 1 on if position == 1: for b in range(0,len(iris_1_x)): LEDMatrix.gfx_set_px(iris_1_x[b],iris_1_y[b]) elif position == 2: for b in range(0,len(iris_2_x)): LEDMatrix.gfx_set_px(iris_2_x[b],iris_2_y[b]) else: for b in range(0,len(iris_3_x)): LEDMatrix.gfx_set_px(iris_3_x[b],iris_3_y[b])
5, 10, 9, 6, 5, 10, 9, 6, 5, 10, 9, ] # Set off the corners of the eye (previously set on by the columns) for i in range(0, len(x_coord_off)): LEDMatrix.gfx_set_px(x_coord_off[i], y_coord_off[i]) for a in range(0, len(x_coord_on)): LEDMatrix.gfx_set_px(x_coord_on[a], y_coord_on[a]) # Iris Position 1 iris_1_x = [ 29, 29, 29, 29, 30, 30, 30, 30, 31, 31, 31, 31, 16, 16, 16, 16, 17, 17, 17, 17, 14, 14, 14, 14, 15, 15, 15, 15, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2 ] iris_1_y = [ 1, 0, 15, 14,