def char_on_each_matrix():
    '''Verify that the numbers 0-9, A-Z are in the vertical chain of LEDs,
    lowest number at the bottom.
    '''
    chars = [Text(chr(ord('0')+i)) for i in range(10)]
    chars += [Text(chr(ord('A')+i)) for i in range(26)]

    num = FrameBuffer.detect()
    matrix_layout = [(0,y*8,90) for y in reversed(range(num))]
    fb = FrameBuffer(matrix_layout=matrix_layout)

    fb.erase()
    for i in range(num):
        fb.draw(chars[i], (2,8*i))
    fb.show()
def sprite_draw():
    fb = FrameBuffer(matrix_layout=[(0,0,0)])
    fb.erase(0xE)
    s = copy.deepcopy(default_sprite)
    fb.draw(s, origin=(2,3))
    expected_fb = '''
        EEEEEEEE
        EE123EEE
        EE456EEE
        EE789EEE
        EEABCEEE
        EEEEEEEE
        EEEEEEEE
        EEEEEEEE
        '''
    return arrays_equal(expected_fb, fb)
def sprite_draw():
    fb = FrameBuffer(matrix_layout=[(0, 0, 0)])
    fb.erase(0xE)
    s = copy.deepcopy(default_sprite)
    fb.draw(s, origin=(2, 3))
    expected_fb = '''
        EEEEEEEE
        EE123EEE
        EE456EEE
        EE789EEE
        EEABCEEE
        EEEEEEEE
        EEEEEEEE
        EEEEEEEE
        '''
    return arrays_equal(expected_fb, fb)
    Sprite(arrow45deg).rotate(0),
    Sprite(arrow60deg).rotate(0),
    Sprite(arrow75deg).rotate(0),
    Sprite(arrow0deg).rotate(90),
    Sprite(arrow15deg).rotate(90),
    Sprite(arrow30deg).rotate(90),
    Sprite(arrow45deg).rotate(90),
    Sprite(arrow60deg).rotate(90),
    Sprite(arrow75deg).rotate(90),
    Sprite(arrow0deg).rotate(180),
    Sprite(arrow15deg).rotate(180),
    Sprite(arrow30deg).rotate(180),
    Sprite(arrow45deg).rotate(180),
    Sprite(arrow60deg).rotate(180),
    Sprite(arrow75deg).rotate(180),
    Sprite(arrow0deg).rotate(270),
    Sprite(arrow15deg).rotate(270),
    Sprite(arrow30deg).rotate(270),
    Sprite(arrow45deg).rotate(270),
    Sprite(arrow60deg).rotate(270),
    Sprite(arrow75deg).rotate(270),
    ]

fb = FrameBuffer()
while True:
    for arrow in arrows:
        fb.erase()
        fb.draw(arrow)
        fb.show()
        time.sleep(0.1)
예제 #5
0
        0000FF00
        000FF000
        000FF000
        000FF000
        000FF000
        00FFF000
        000FF000
        """),
    Sprite("""
        0000FF00
        000FF000
        000FFF00
        00FFFF00
        000FFF00
        00F00F00
        00F0F000
        00F00000
        """),
    ]

animation = cycle(animation)
while True:
    sprite = next(animation)

    fb.erase()
    fb.draw(sprite)
    fb.show()

    time.sleep(0.1)

예제 #6
0
    s1 = Sprite(f.read())
s1_width = s1.width
s1 += s1

with open('scroller2.spr') as f:
    s2 = Sprite(f.read())
s2_width = s2.width
s2 += s2

i = 0
i1 = 0
i2 = 0
x = 4
while True:
    fb.erase()
    fb.draw(s1, (-i1, 0))
    fb.draw(s2, (-i2, 0))
    fb.show()
    time.sleep(0.01)
    if i1 == s1_width:
        i1 = 0
    elif i % 15 == 0:
        i1 += 1
    if i2 == s2_width:
        i2 = 0
    elif i % 4 == 0:
        i2 += 1
    i += 1

    if i % 12 == 0:
        r = random()
         if not alien_columns:
             break
 
     # ########################################
     # Show world
     # ########################################
 
     fb.erase()
 
     # Draw missile
     if missile_x >= 0:
         fb.point(missile_x, missile_y, MISSILE_COLOR)
 
     # Draw spaceship
     spaceship_x = round(spaceship_position) - spaceship_middle
     fb.draw(spaceship, origin=(spaceship_x, 0))
 
     # Draw aliens
     for column in alien_columns:
         fb.point(column, alien_row)
 
     # Show FrameBuffer on LED Matrix
     fb.show()
     time.sleep(0.001)
 
 if alien_columns:
     print("Ouch!")
     scroll(lose_text, speed=0.12)
 else:
     print("You win!")
     scroll(win_text, speed=0.12)
예제 #8
0

def vector_angle(start, end):
    return degrees(atan2(end.x - start.x, end.z - start.z))


compass = Button(24)
fb = FrameBuffer()
while block.Block(mc.getBlock(gold_pos)) == block.GOLD_BLOCK:
    if compass.presses():
        heading = control.get_heading(mc)
        angle_to_gold = vector_angle(mc.player.getPos(), gold_pos)
        compass_angle = 90 + (angle_to_gold - heading)
        fb.erase()
        arrow_index = round(compass_angle / 15) % 24
        fb.draw(arrows[arrow_index])
        fb.show()

    for button, action in keymap.items():
        if button.is_pressed():
            action()
        else:
            action(release=True)

    x, y, z = accel.forces()
    control.look(up=20 * y, left=20 * x)

    time.sleep(0.01)

mc.postToChat("You found the gold!")
time.sleep(3)
    - UUT shows 1 quarter lit (upper left/right, then lower left/right) (1
      second)
    - UUT shows checkerboard with bottom left lit, then inverted checkerboard
      (1.5 seconds)
Any missing LEDs lit is a failure.

Sequence repeats forever - hit CTRL-C to stop.
""")

input("Press Enter to start the test...")

print("TEST SEQUENCE RUNNING - CTRL-C TO END")

while True:
    fb.erase()
    fb.draw(Text("A"), (0,0))
    fb.draw(Text("B"), (8,0))
    fb.draw(Text("C"), (8,8))
    fb.show()
    time.sleep(1)

    fb.erase(0xF)
    fb.show()
    time.sleep(1)

    for color in range(16):
        fb.erase(color)
        fb.show()
        time.sleep(2/16)

    fb.erase()
    Sprite(arrow30deg).rotate(90),
    Sprite(arrow45deg).rotate(90),
    Sprite(arrow60deg).rotate(90),
    Sprite(arrow75deg).rotate(90),
    Sprite(arrow0deg).rotate(180),
    Sprite(arrow15deg).rotate(180),
    Sprite(arrow30deg).rotate(180),
    Sprite(arrow45deg).rotate(180),
    Sprite(arrow60deg).rotate(180),
    Sprite(arrow75deg).rotate(180),
    Sprite(arrow0deg).rotate(270),
    Sprite(arrow15deg).rotate(270),
    Sprite(arrow30deg).rotate(270),
    Sprite(arrow45deg).rotate(270),
    Sprite(arrow60deg).rotate(270),
    Sprite(arrow75deg).rotate(270),
    ]

compass = Button(24)
fb = FrameBuffer()
while True:
    if compass.presses():
        heading = control.get_heading(mc)
        fb.erase()
        arrow_index = round(heading/15) % 24
        fb.draw(arrows[arrow_index])
        fb.show()

    time.sleep(0.01)

예제 #11
0
        00F00F00
        00F0F000
        00F00000
        """),
]


def sprite_in_minecraft(mc, sprite, pos):
    char_sprite = reversed(str(sprite).splitlines())
    for height, row in enumerate(char_sprite):
        for width, char in enumerate(row):
            if char == '0':
                blk = block.AIR
            else:
                blk = block.WOOD
            mc.setBlock(player_pos + Vec3(width, height, 0), blk)


player_pos = mc.player.getTilePos()
animation = cycle(animation)
while True:
    sprite = next(animation)

    fb.erase()
    fb.draw(sprite)
    fb.show()

    sprite_in_minecraft(mc, sprite, player_pos)

    time.sleep(0.1)
        missile_x, missile_y = -1, -1
        if not alien_columns:
            break

    # ########################################
    # Show world
    # ########################################

    fb.erase()

    # Draw missile
    if missile_x >= 0:
        fb.point(missile_x, missile_y, MISSILE_COLOR)

    # Draw spaceship
    spaceship_x = round(spaceship_position) - spaceship_middle
    fb.draw(spaceship, origin=(spaceship_x, 0))

    # Draw aliens
    for column in alien_columns:
        fb.point(column, alien_row)

    # Show FrameBuffer on LED Matrix
    fb.show()
    time.sleep(0.001)

if alien_columns:
    print("Ouch!")
else:
    print("You win!")
    fb_spec = [(8*x,0,0) for x in range(num_uuts)]
    fb = FrameBuffer(fb_spec)

    digits = [Text(str(i)) for i in range(10)]

    def endcaps():
        fb.erase()
        fb.line((0,0), (7,7))
        fb.line((0,7), (7,0))
        fb.line((fb.width-8,0), (fb.width-1,7))
        fb.line((fb.width-8,7), (fb.width-1,0))

    # Number UUTs
    endcaps()
    for uut in range(1,num_uuts-1):
        fb.draw(digits[uut], (8*uut+1, 0))
    fb.show()
    time.sleep(3)

    # Brightness sequence
    for color in range(16):
        endcaps()
        fb.rect((8,0), (fb.width-16,8), fill=True, color=color)
        fb.show()
        time.sleep(4/16)

    # Horizontal line moving down
    for y in reversed(range(8)):
        endcaps()
        fb.line((8,y),(fb.width-9,y))
        fb.show()
예제 #14
0
    mc.setBlocks(pos - r_vector, pos + r_vector, block.AIR)
    bomb_sound.play()


place_mode = True
radius = 1
while True:
    if place_mode:
        if bomb.presses():
            control.hit()
        hits = mc.events.pollBlockHits()
        if hits:
            tnt_pos = hits[0].pos
            mc.setBlock(tnt_pos, block.TNT)
            place_mode = False

    else:
        if bomb.presses():
            detonate(mc, tnt_pos, radius)
            place_mode = True

    radius += up.presses()
    radius -= down.presses()
    radius = max(min(9, radius), 0)

    fb.erase()
    fb.draw(Text(str(radius)))
    fb.show()

    time.sleep(0.01)
예제 #15
0
    s1 = Sprite(f.read())
s1_width = s1.width
s1 += s1

with open('scroller2.spr') as f:
    s2 = Sprite(f.read())
s2_width = s2.width
s2 += s2

i = 0
i1 = 0
i2 = 0
x = 4
while True:
    fb.erase()
    fb.draw(s1, (-i1,0))
    fb.draw(s2, (-i2,0))
    fb.show()
    time.sleep(0.01)
    if i1 == s1_width:
        i1 = 0
    elif i % 15 == 0:
        i1 += 1
    if i2 == s2_width:
        i2 = 0
    elif i % 4 == 0:
        i2 += 1
    i += 1


    if i % 12 == 0:
    Sprite(arrow45deg).rotate(0),
    Sprite(arrow60deg).rotate(0),
    Sprite(arrow75deg).rotate(0),
    Sprite(arrow0deg).rotate(90),
    Sprite(arrow15deg).rotate(90),
    Sprite(arrow30deg).rotate(90),
    Sprite(arrow45deg).rotate(90),
    Sprite(arrow60deg).rotate(90),
    Sprite(arrow75deg).rotate(90),
    Sprite(arrow0deg).rotate(180),
    Sprite(arrow15deg).rotate(180),
    Sprite(arrow30deg).rotate(180),
    Sprite(arrow45deg).rotate(180),
    Sprite(arrow60deg).rotate(180),
    Sprite(arrow75deg).rotate(180),
    Sprite(arrow0deg).rotate(270),
    Sprite(arrow15deg).rotate(270),
    Sprite(arrow30deg).rotate(270),
    Sprite(arrow45deg).rotate(270),
    Sprite(arrow60deg).rotate(270),
    Sprite(arrow75deg).rotate(270),
]

fb = FrameBuffer()
while True:
    for arrow in arrows:
        fb.erase()
        fb.draw(arrow)
        fb.show()
        time.sleep(0.1)