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
예제 #2
0
    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])
예제 #3
0
    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()
예제 #4
0
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
예제 #5
0
def setPoints():
	global board_position_bottom, cpu_position_bottom
	if (points[0] < 10 and points[1] < 10):
		board_position_bottom = round( 8*LEDMatrix.MATRIX_HEIGHT/2 - board_height / 2 )
		cpu_position_bottom = board_position_bottom
		LEDMatrix.gfx_set_all(GFX_OFF)
		display = LEDNumbers[points[0]] + LED_colon + LEDNumbers[points[1]]
		LEDMatrix.gfx_sprite_array(display, int((LEDMatrix.MATRIX_WIDTH*8 - len(display))/2), int( LEDMatrix.MATRIX_HEIGHT*4 - 4 ) )
		LEDMatrix.gfx_render()
		time.sleep(1)
	else:
		print "Game over: %d - %d" % (points[0], points[1])
		LEDMatrix.gfx_set_all(GFX_OFF)
		if points[0] >= 10:
			sign = [[1,1,1,1,1,1,1],[1,0,0,0,0,0,0],[1,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,1,1,1,1,1,0],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[0,1,1,1,1,1,0],[0,0,0,0,0,0,0],[1,0,0,1,1,1,1],[1,0,0,1,0,0,1],[1,1,1,1,0,0,1],[0,0,0,0,0,0,0],[0,0,0,0,0,0,1],[1,1,1,1,1,1,1],[0,0,0,0,0,0,1]]
			LEDMatrix.gfx_sprite_array(sign, int((LEDMatrix.MATRIX_WIDTH*8 - len(sign))/2), int( LEDMatrix.MATRIX_HEIGHT*4 - 4 ) )
		else:
			sign = [[0,1,1,1,1,1],[1,0,0,0,0,0],[0,1,1,1,0,0],[1,0,0,0,0,0],[0,1,1,1,1,1],[0,0,0,0,0,0],[1,1,1,1,1,1],[0,0,0,0,0,0],[1,1,1,1,1,1],[0,0,0,1,1,0],[0,0,1,0,0,0],[1,1,0,0,0,0],[1,1,1,1,1,1],[0,0,0,0,0,0],[1,0,1,1,1,1]]
			LEDMatrix.gfx_sprite_array(sign, int((LEDMatrix.MATRIX_WIDTH*8 - len(sign))/2), int( LEDMatrix.MATRIX_HEIGHT*4 - 3 ) )
		LEDMatrix.gfx_render()
		sys.exit(0)
예제 #6
0
def setPoints():
    global board_position_bottom, cpu_position_bottom
    if (points[0] < 10 and points[1] < 10):
        board_position_bottom = round(8 * LEDMatrix.MATRIX_HEIGHT / 2 -
                                      board_height / 2)
        cpu_position_bottom = board_position_bottom
        LEDMatrix.gfx_set_all(GFX_OFF)
        display = LEDNumbers[points[0]] + LED_colon + LEDNumbers[points[1]]
        LEDMatrix.gfx_sprite_array(
            display, int((LEDMatrix.MATRIX_WIDTH * 8 - len(display)) / 2),
            int(LEDMatrix.MATRIX_HEIGHT * 4 - 4))
        LEDMatrix.gfx_render()
        time.sleep(1)
    else:
        print "Game over: %d - %d" % (points[0], points[1])
        LEDMatrix.gfx_set_all(GFX_OFF)
        if points[0] >= 10:
            sign = [[1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0],
                    [1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0],
                    [0, 1, 1, 1, 1, 1, 0], [1, 0, 0, 0, 0, 0, 1],
                    [1, 0, 0, 0, 0, 0, 1], [0, 1, 1, 1, 1, 1, 0],
                    [0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 1, 1, 1, 1],
                    [1, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 0, 0, 1],
                    [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1],
                    [1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 1]]
            LEDMatrix.gfx_sprite_array(
                sign, int((LEDMatrix.MATRIX_WIDTH * 8 - len(sign)) / 2),
                int(LEDMatrix.MATRIX_HEIGHT * 4 - 4))
        else:
            sign = [[0, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0], [0, 1, 1, 1, 0, 0],
                    [1, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0],
                    [1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1],
                    [0, 0, 0, 1, 1, 0], [0, 0, 1, 0, 0, 0], [1, 1, 0, 0, 0, 0],
                    [1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0], [1, 0, 1, 1, 1, 1]]
            LEDMatrix.gfx_sprite_array(
                sign, int((LEDMatrix.MATRIX_WIDTH * 8 - len(sign)) / 2),
                int(LEDMatrix.MATRIX_HEIGHT * 4 - 3))
        LEDMatrix.gfx_render()
        sys.exit(0)
예제 #7
0
def move():
	global running, speed
	if running:
		newPosition = tail[0] + direction
		if newPosition.x > WIDTH:
			newPosition.x -= WIDTH+1
		elif newPosition.x < 0:
			newPosition.x += WIDTH+1
		if newPosition.y > HEIGHT:
			newPosition.y -= HEIGHT+1
		elif newPosition.y < 0:
			newPosition.y += HEIGHT+1
		
		if newPosition == target:
			tail.insert(0,newPosition)
			setTarget()
			speed = max(0.07, min(0.3, 2/float(len(tail))))
		elif newPosition not in tail:
			tail.insert(0, newPosition)
			tail.pop()
		else:
			# Game Over
			running = False
			for i in range(6):
				LEDMatrix.gfx_set_all(GFX_INVERT)
				LEDMatrix.gfx_render()
				time.sleep(0.3)
			if USE_JOYPAD:
				print "Game Over. Score: " + str(len(tail)-1)
			else:
				print "Game Over. Press any Key to exit. Score: " + str(len(tail)-1)
			LEDMatrix.clear_all()
			raise SystemExit("\n")
		
		# threading for calling it every period
		threading.Timer(speed, move).start ()
	else:
		LEDMatrix.clear_all()
	display()
예제 #8
0
    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()
    async def neutral(self):
        while Button.sad_flag==False and Button.happy_flag==False:
            if Button.sad_flag==False and Button.happy_flag==False:
            # Set off all LEDs of the LED Matrices
                LEDMatrix.gfx_set_all(GFX_OFF)
            # Set borders on
                self.set_borders()
            # Set Iris 1 on
                self.set_iris(1)
            # Make the eye with the iris at neutral position appear on the matrices for 2 secs
                LEDMatrix.gfx_render()
                await asyncio.sleep(2)
            elif Button.happy_flag==True:
                await self.happy()
            else:
                await self.sad()

            if Button.sad_flag==False and Button.happy_flag==False:
  # Set off all LEDs of the LED Matrices
                LEDMatrix.gfx_set_all(GFX_OFF)
            # Set borders on
                self.set_borders()

            # Set Iris Position 1 off
#                self.set_iris(1)
            # Set Iris Position 2 on
                self.set_iris(2)
            # Make the eye with the iris at left position appear on the matrices for 1 secs
                LEDMatrix.gfx_render()
                await asyncio.sleep(1)
            elif Button.happy_flag==True:
                await self.happy()
            else:
                await self.sad()

            if Button.sad_flag==False and Button.happy_flag==False:
  # Set off all LEDs of the LED Matrices
                LEDMatrix.gfx_set_all(GFX_OFF)
            # Set borders on
                self.set_borders()
            # Set Iris Position 2 off
#                self.set_iris(2)
            # Set Iris Position 1 on
                self.set_iris(1)
            # Make the eye with the iris at neutral position appear on the matrices for 1 secs
                LEDMatrix.gfx_render()
                await asyncio.sleep(1)
            elif Button.happy_flag==True:
                await self.happy()
            else:
                await self.sad()

            # Set off all the LEDs
            if Button.sad_flag==False and Button.happy_flag==False:

                LEDMatrix.gfx_set_all(GFX_OFF)
                await self.set_blink()
                self.set_borders()
                self.set_iris(1)
            # Make the eye appear at neutral position on the matrices
                LEDMatrix.gfx_render()
                await asyncio.sleep(2)
            elif Button.happy_flag==True:
                await self.happy()
            else:
                await self.sad()

            if Button.sad_flag==False and Button.happy_flag==False:
  # Set off all LEDs of the LED Matrices
                LEDMatrix.gfx_set_all(GFX_OFF)
            # Set borders on
                self.set_borders()
            # Set Iris Position 1 off
#                self.set_iris(1)
            # Set Iris Position 2 on
                self.set_iris(3)
            # Make the eye with the iris at left position appear on the matrices for 1 secs
                LEDMatrix.gfx_render()
                await asyncio.sleep(1)
            elif Button.happy_flag==True:
                await self.happy()
            else:
                await self.sad()

            # Set Iris Position 2 off
            if Button.sad_flag==False and Button.happy_flag==False:
  # Set off all LEDs of the LED Matrices
                LEDMatrix.gfx_set_all(GFX_OFF)
            # Set borders on
                self.set_borders()
#                self.set_iris(3)
            # Set Iris Position 1 on
                self.set_iris(1)
            # Make the eye with the iris at neutral position appear on the matrices for 1 secs
                LEDMatrix.gfx_render()
                await asyncio.sleep(1)
            elif Button.happy_flag==True:
                await self.happy()
            else:
                await self.sad()

            # Set off all the LEDs
            if Button.sad_flag==False and Button.happy_flag==False:
                LEDMatrix.gfx_set_all(GFX_OFF)
                await self.set_blink()
            elif Button.happy_flag==True:
                await self.happy()
            else:
                await self.sad()
예제 #10
0
                    [1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 1]]
            LEDMatrix.gfx_sprite_array(
                sign, int((LEDMatrix.MATRIX_WIDTH * 8 - len(sign)) / 2),
                int(LEDMatrix.MATRIX_HEIGHT * 4 - 4))
        else:
            sign = [[0, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0], [0, 1, 1, 1, 0, 0],
                    [1, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0],
                    [1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1],
                    [0, 0, 0, 1, 1, 0], [0, 0, 1, 0, 0, 0], [1, 1, 0, 0, 0, 0],
                    [1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0], [1, 0, 1, 1, 1, 1]]
            LEDMatrix.gfx_sprite_array(
                sign, int((LEDMatrix.MATRIX_WIDTH * 8 - len(sign)) / 2),
                int(LEDMatrix.MATRIX_HEIGHT * 4 - 3))
        LEDMatrix.gfx_render()
        sys.exit(0)


if __name__ == "__main__":
    board_height = min(max(2, board_height), 8 * LEDMatrix.MATRIX_HEIGHT - 2)
    dot[0] = 8 * LEDMatrix.MATRIX_WIDTH - 2
    dot[1] = int(round(8 * LEDMatrix.MATRIX_HEIGHT / 2))
    #time.sleep(delay_time)
    while True:
        LEDMatrix.gfx_set_all(GFX_OFF)
        move()
        moveCPU()
        movePong()

        LEDMatrix.gfx_render()
        time.sleep(delay_time)
예제 #11
0
		display = LEDNumbers[points[0]] + LED_colon + LEDNumbers[points[1]]
		LEDMatrix.gfx_sprite_array(display, int((LEDMatrix.MATRIX_WIDTH*8 - len(display))/2), int( LEDMatrix.MATRIX_HEIGHT*4 - 4 ) )
		LEDMatrix.gfx_render()
		time.sleep(1)
	else:
		print "Game over: %d - %d" % (points[0], points[1])
		LEDMatrix.gfx_set_all(GFX_OFF)
		if points[0] >= 10:
			sign = [[1,1,1,1,1,1,1],[1,0,0,0,0,0,0],[1,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,1,1,1,1,1,0],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[0,1,1,1,1,1,0],[0,0,0,0,0,0,0],[1,0,0,1,1,1,1],[1,0,0,1,0,0,1],[1,1,1,1,0,0,1],[0,0,0,0,0,0,0],[0,0,0,0,0,0,1],[1,1,1,1,1,1,1],[0,0,0,0,0,0,1]]
			LEDMatrix.gfx_sprite_array(sign, int((LEDMatrix.MATRIX_WIDTH*8 - len(sign))/2), int( LEDMatrix.MATRIX_HEIGHT*4 - 4 ) )
		else:
			sign = [[0,1,1,1,1,1],[1,0,0,0,0,0],[0,1,1,1,0,0],[1,0,0,0,0,0],[0,1,1,1,1,1],[0,0,0,0,0,0],[1,1,1,1,1,1],[0,0,0,0,0,0],[1,1,1,1,1,1],[0,0,0,1,1,0],[0,0,1,0,0,0],[1,1,0,0,0,0],[1,1,1,1,1,1],[0,0,0,0,0,0],[1,0,1,1,1,1]]
			LEDMatrix.gfx_sprite_array(sign, int((LEDMatrix.MATRIX_WIDTH*8 - len(sign))/2), int( LEDMatrix.MATRIX_HEIGHT*4 - 3 ) )
		LEDMatrix.gfx_render()
		sys.exit(0)
		
if __name__ == "__main__":
	board_height = min(max(2, board_height), 8*LEDMatrix.MATRIX_HEIGHT -2)
	dot[0] = 8*LEDMatrix.MATRIX_WIDTH-2
	dot[1] = int(round(8*LEDMatrix.MATRIX_HEIGHT/2))
	#time.sleep(delay_time)
	while True:
		LEDMatrix.gfx_set_all(GFX_OFF)
		move()
		moveCPU()
		movePong()
		
		LEDMatrix.gfx_render()
		time.sleep(delay_time)