Beispiel #1
0
def star(matrix):
    frame = FrameSequence('star').first_frame()
    x_path = range(-16, 16)
    y_path = list(range(-12, 4)) + list(sorted(range(-12, 3), reverse=True))
    path = zip(x_path, y_path)
    for x, y in path:
        frame.render(matrix, x, y)
Beispiel #2
0
def piranha_plant(matrix):
    plant = FrameSequence('piranha-plant')
    frame = plant.first_frame()
    y_path = sorted(range(17), reverse=True)
    for y in y_path:
        frame.render(matrix, y_offset=y)

    for frame in plant.get_frames(repeat=5):
        frame.render(matrix)
    frame.render(matrix)
Beispiel #3
0
def mushroom(matrix):
    shroom = 'mushroom-{0}'.format(
        random.choice((
            '1-up',
            'poison',
            'super-og',
            'super-red',
        )))
    frames = FrameSequence(shroom).cycle()
    x_path = range(-16, 16)
    for x in x_path:
        next(frames).render(matrix, x_offset=x)
def loop():
    ping = sonar.ping()
    if ping > 0:
        distance = sonar.convert_cm(ping)
        if distance < 5:
            time.sleep(2)

            # Slide the block down
            path = [(0, y) for y in range(1, 17)]
            for (x, y) in path:
                block.render(matrix, x, y)

            # Spin the coin a couple times
            sequence = FrameSequence('coin')
            for frame in sequence.get_frames(repeat=4):
                frame.render(matrix)
            sequence.first_frame().render(matrix)
            time.sleep(1)

            # Make something walk across the screen, then return to the block.
            random.choice(animation_list)(matrix)
            block.render(matrix)
        time.sleep(0.1)
Beispiel #5
0
def bullet_biff(matrix):
    frames = FrameSequence('bullet-biff').cycle()
    x_path = sorted(range(-16, 16), reverse=True)
    for x in x_path:
        next(frames).render(matrix, x_offset=x)
Beispiel #6
0
def koopa_troopa(matrix):
    frames = FrameSequence('koopa-troopa').cycle()
    x_path = sorted(range(-16, 16), reverse=True)
    for x in x_path:
        next(frames).render(matrix, x_offset=x)
Beispiel #7
0
def mario(matrix):
    walking = FrameSequence('mario-walking').cycle()
    standing = FrameSequence('mario-stand').first_frame()

    # Mario walks on screen
    x_path = range(-16, 0)
    for x in x_path:
        next(walking).render(matrix, x_offset=x)

    standing.render(matrix)
    time.sleep(1)

    if random.choice((True, False)):
        # Might as well jump (jump!)
        jump = FrameSequence('mario-jump').first_frame()
        y_path = [-1, -2, -3, -4, -3, -2, -1]
        for y in y_path:
            jump.render(matrix, y_offset=y)

        # Exit stage left
        x_path = range(16)
        for x in x_path:
            next(walking).render(matrix, x_offset=x)
    else:
        # He's dead, Jim
        dead = FrameSequence('mario-dead').first_frame()
        y_path = [
            0, 0, -1, -2, -3, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
            11, 12, 13, 14, 15, 16
        ]
        for y in y_path:
            dead.render(matrix, y_offset=y)
    'mushroom-warhol',
    'pipe',
    'piranha-plant',
    'star',
)

# Define our pins
matrix = PixelMatrix(PinMap.D2, 16, 16)
sonar = HCSR04(PinMap.D1)

# Reset the matrix
matrix.fill()
matrix.write()

# Default block image
block = FrameSequence('block').first_frame()
block.render(matrix)


def loop():
    ping = sonar.ping()
    if ping > 0:
        distance = sonar.convert_cm(ping)
        if distance < 5:
            time.sleep(2)

            # Slide the block down
            path = [(0, y) for y in range(1, 17)]
            for (x, y) in path:
                block.render(matrix, x, y)