def sprite_add_inconsistent_heights():
    one = Sprite('''
        12
        45
        67
        ''')
    two = Sprite('''
        b
        c
        ''')
    try:
        new = one + two
    except ValueError:
        return True
    return False
def sprite_reinit_change():
    original = copy.deepcopy(default_sprite)
    modified = Sprite(original)
    modified.bitmap[0][0]=0
    expected_modified = '''
        123
        456
        789
        0bc
        '''
    expected_original = '''
        123
        456
        789
        abc
        '''
    return arrays_equal(expected_original, original) \
            and arrays_equal(expected_modified, modified)
def sprite_reinit_change():
    original = copy.deepcopy(default_sprite)
    modified = Sprite(original)
    modified.bitmap[0][0] = 0
    expected_modified = '''
        123
        456
        789
        0bc
        '''
    expected_original = '''
        123
        456
        789
        abc
        '''
    return arrays_equal(expected_original, original) \
            and arrays_equal(expected_modified, modified)
def sprite_add():
    one = Sprite('''
        12
        45
        67
        ''')
    two = Sprite('''
        a
        b
        c
        ''')
    new = one + two
    expected_bitmap = '''
        12a
        45b
        67c
        '''
    return arrays_equal(expected_bitmap, new)
def sprite_time_large_bitmap_draw_and_show():
    # This is currently quite slow, as it is all done in Python via a 2D array.
    # Speed not needed right now, but may in future move to numpy or CPython
    fb = FrameBuffer(matrix_layout=[(0, 0, 0)])
    s = Sprite((('5' * 16) + '\n') * 16)

    def draw():
        fb.draw(s)
        fb.show()

    return timeit(partial(draw), loops=100) > 50
def sprite_init_variable_whitespace():
    s = Sprite('''
        1  	2 3    4
        4 				5       6 a b c
        7  8  		  9
        a   b  c d e
        ''')
    expected_bitmap = '''
        123
        456
        789
        abc
        '''
    return arrays_equal(expected_bitmap, s)
def sprite_init_lines_long():
    s = Sprite('''
        1 2 3 4
        4 5 6 a b c
        7 8 9
        a b c d e
        ''')
    expected_bitmap = '''
        123
        456
        789
        abc
        '''
    return arrays_equal(expected_bitmap, s)
fb = FrameBuffer([(0, 0, 90)])

outs = [
    Output(17),
    Output(27),
    Output(22),
    Output(23),
    Output(4),
    Output(14),
    Output(15),
    Output(18),
]

with open('scroller1.spr') as f:
    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))
Example #9
0
keymap = {
    Button(23): control.left,
    Button(14): control.right,
    Button(18): control.forward,
    Button(15): control.backward,
    Button(7): control.smash,
}

accel = Accel()

arrow0deg = Sprite("""
    --------
    --------
    -----F--
    ------F-
    FFFFFFFF
    ------F-
    -----F--
    --------
    """)
arrow15deg = Sprite("""
    --------
    -----F--
    ------F-
    ----FFFF
    FFFF--F-
    -----F--
    --------
    --------
    """)
arrow30deg = Sprite("""
def sprite_reinit():
    s = copy.deepcopy(default_sprite)
    expected_bitmap = Sprite(s)
    return arrays_equal(expected_bitmap, s)
    return False


@testing.automatic
def time_show():
    fb = FrameBuffer(matrix_layout=[(0, 0, 0)])
    return timeit(partial(fb.show), loops=200) > 300


#########################################################################
# Sprite tests
#

default_sprite = Sprite('''
    1 2 3
    4 5 6
    7 8 9
    a b c
    ''')


@testing.automatic
def sprite_init():
    s = copy.deepcopy(default_sprite)
    expected_bitmap = '''
        123
        456
        789
        abc
        '''
    return arrays_equal(expected_bitmap, s)
from rstem.mcpi.vec3 import Vec3
from rstem.led_matrix import FrameBuffer, Sprite
from itertools import cycle
import time

fb = FrameBuffer()

control.show(hide_at_exit=True)
mc = minecraft.Minecraft.create()

animation = [
    Sprite("""
        00000000
        0000FF00
        000FF000
        000FFF00
        00FFFF00
        000FFF00
        0FF00F00
        0F0000FF
        """),
    Sprite("""
        00000000
        0000FF00
        0000F000
        00FFFF00
        0F0FF0F0
        000FFF00
        0FF00F00
        00000FF0
        """),
    Sprite("""
from rstem.accel import Accel
from rstem.button import Button
from rstem.led_matrix import FrameBuffer, Sprite
import time

fire_button = Button(25)

fb = FrameBuffer()
accel = Accel()

spaceship = Sprite('''
    -F-
    FAF
    ''')
spaceship_middle = 1
spaceship_position = fb.width / 2

alien_columns = [0, 1, 2, 3]
alien_row = fb.height - 1
alien_start_time = time.time()
alien_direction = 1
alien_speed = 1

ALIENS_STEP_TIME = 0.8

missile_x, missile_y = -1, -1

MISSILE_COLOR = 10
MISSILE_STEP_TIME = 0.1

TILT_FORCE = 0.1
# Initialize accelerometer
accel = Accel()

# Initialize sounds
fire_sound = Sound("fire.wav")
hit_sound = Sound("hit.wav")
notes = cycle([Note('B3'), Note('G3'), Note('E3'), Note('C3')])

fire_button = Button(7)

while True:
    # Initialize spaceship
    spaceship = Sprite('''
        --F--
        FFAFF
        FAAAF
        ''')
    spaceship_middle = 2
    spaceship_position = fb.width / 2
    TILT_FORCE = 0.1
    SPACESHIP_STEP = 1

    # Initialize aliens
    alien_columns = [i for i in range(27) if i % 3]
    alien_columns2 = [i for i in range(27) if i % 3]
    alien_row = fb.height - 6
    alien_start_time = time.time()
    alien_direction = 1
    alien_speed = 2
    ALIENS_STEP_TIME = .8