def point4(): fb = FrameBuffer(matrix_layout=[(0,0,0)]) fb.point(7,7,color=10) expected_fb = ''' 0000000A 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ''' return arrays_equal(expected_fb, fb)
def point2(): fb = FrameBuffer(matrix_layout=[(0,0,0)]) fb.point((0,0), color=1) expected_fb = ''' 00000000 00000000 00000000 00000000 00000000 00000000 00000000 10000000 ''' return arrays_equal(expected_fb, fb)
def point3(): fb = FrameBuffer(matrix_layout=[(0,0,0)]) fb.point(1,2,color=3) expected_fb = ''' 00000000 00000000 00000000 00000000 00000000 03000000 00000000 00000000 ''' return arrays_equal(expected_fb, fb)
def point4(): fb = FrameBuffer(matrix_layout=[(0, 0, 0)]) fb.point(7, 7, color=10) expected_fb = ''' 0000000A 00000000 00000000 00000000 00000000 00000000 00000000 00000000 ''' return arrays_equal(expected_fb, fb)
def point3(): fb = FrameBuffer(matrix_layout=[(0, 0, 0)]) fb.point(1, 2, color=3) expected_fb = ''' 00000000 00000000 00000000 00000000 00000000 03000000 00000000 00000000 ''' return arrays_equal(expected_fb, fb)
def point2(): fb = FrameBuffer(matrix_layout=[(0, 0, 0)]) fb.point((0, 0), color=1) expected_fb = ''' 00000000 00000000 00000000 00000000 00000000 00000000 00000000 10000000 ''' return arrays_equal(expected_fb, fb)
def point1(): fb = FrameBuffer(matrix_layout=[(0, 0, 0)]) fb.point(0, 0) expected_fb = ''' 00000000 00000000 00000000 00000000 00000000 00000000 00000000 F0000000 ''' return arrays_equal(expected_fb, fb)
def point1(): fb = FrameBuffer(matrix_layout=[(0,0,0)]) fb.point(0,0) expected_fb = ''' 00000000 00000000 00000000 00000000 00000000 00000000 00000000 F0000000 ''' return arrays_equal(expected_fb, fb)
# Check for collision if missile_y == alien_row and missile_x in alien_columns: alien_columns.remove(missile_x) 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!")
from rstem.accel import Accel from rstem.led_matrix import FrameBuffer import time fb = FrameBuffer() accel = Accel() TILT_FORCE = 0.1 STEP = 0.1 x, y = (3, 3) while True: x_force, y_force, z_force = accel.forces() if x_force > TILT_FORCE: x -= STEP elif x_force < -TILT_FORCE: x += STEP fb.erase() fb.point(round(x), round(y)) fb.show() time.sleep(.1)
if missile_y == alien_row and missile_x in alien_columns: alien_columns.remove(missile_x) missile_x, missile_y = -1, -1 hit_sound.play() 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!")
from rstem.led_matrix import FrameBuffer fb = FrameBuffer() fb.erase() fb.point(3, 0) fb.show()
while True: # ######################################## # Get inputs # ######################################## x_force, y_force, z_force = accel.forces() # ######################################## # Change the World # ######################################## # Move spaceship if x_force > TILT_FORCE: spaceship_position -= SPACESHIP_STEP elif x_force < -TILT_FORCE: spaceship_position += SPACESHIP_STEP spaceship_position = max(0, min(fb.width - 1, spaceship_position)) # ######################################## # Show world # ######################################## fb.erase() # Draw spaceship fb.point(round(spaceship_position), 0) # Show FrameBuffer on LED Matrix fb.show() time.sleep(0.001)
def out_of_bounds_point4(): fb = FrameBuffer(matrix_layout=[(0, 0, 0)]) fb.point(0, fb.height) return fb._framebuffer() == erased_fb()
def out_of_bounds_point3(): fb = FrameBuffer(matrix_layout=[(0, 0, 0)]) fb.point(fb.width, 0) return fb._framebuffer() == erased_fb()
def out_of_bounds_point3(): fb = FrameBuffer(matrix_layout=[(0,0,0)]) fb.point(fb.width, 0) return fb._framebuffer() == erased_fb()
def out_of_bounds_point4(): fb = FrameBuffer(matrix_layout=[(0,0,0)]) fb.point(0, fb.height) return fb._framebuffer() == erased_fb()
from rstem.led_matrix import FrameBuffer import time fb = FrameBuffer() x, y = (3, 3) while True: fb.erase() fb.point(x, y) fb.show() time.sleep(.1)
mc = minecraft.Minecraft.create() SCALE = 25 fb = FrameBuffer() count = 0 FLASH_COUNT = 3 flash_lit = True while True: pos = mc.player.getTilePos() x = round(pos.x/SCALE + (fb.width-1)/2) x_out_of_bounds = not 0 <= x < fb.width x = min(fb.width-1, max(0, x)) z = round(pos.z/SCALE + (fb.height-1)/2) z_out_of_bounds = not 0 <= z < fb.height z = min(fb.height-1, max(0, z)) fb.erase() count += 1 if count > FLASH_COUNT: flash_lit = not flash_lit count = 0 if not x_out_of_bounds and not z_out_of_bounds or flash_lit: fb.point(z, x) fb.show() time.sleep(0.01)
# ######################################## x_force, y_force, z_force = accel.forces() # ######################################## # Change the World # ######################################## # Move spaceship if x_force > TILT_FORCE: spaceship_position -= SPACESHIP_STEP elif x_force < -TILT_FORCE: spaceship_position += SPACESHIP_STEP spaceship_position = max(0, min(fb.width - 1, spaceship_position)) # ######################################## # Show world # ######################################## fb.erase() # Draw spaceship fb.point(round(spaceship_position), 0) # Draw aliens for column in alien_columns: fb.point(column, alien_row) # Show FrameBuffer on LED Matrix fb.show() time.sleep(0.001)
# Check for collision if missile_y == alien_row and missile_x in alien_columns: alien_columns.remove(missile_x) 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 fb.point(round(spaceship_position), 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:
from rstem.accel import Accel from rstem.led_matrix import FrameBuffer import time fb = FrameBuffer() accel = Accel() TILT_FORCE = 0.1 STEP = 0.1 x, y = (3, 3) while True: x_force, y_force, z_force = accel.forces() if x_force > TILT_FORCE: x -= STEP elif x_force < -TILT_FORCE: x += STEP x = max(min(fb.width, x), 0) fb.erase() fb.point(round(x), round(y)) fb.show() time.sleep(.1)
mc = minecraft.Minecraft.create() SCALE = 25 fb = FrameBuffer() count = 0 FLASH_COUNT = 3 flash_lit = True while True: pos = mc.player.getTilePos() x = round(pos.x / SCALE + (fb.width - 1) / 2) x_out_of_bounds = not 0 <= x < fb.width x = min(fb.width - 1, max(0, x)) z = round(pos.z / SCALE + (fb.height - 1) / 2) z_out_of_bounds = not 0 <= z < fb.height z = min(fb.height - 1, max(0, z)) fb.erase() count += 1 if count > FLASH_COUNT: flash_lit = not flash_lit count = 0 if not x_out_of_bounds and not z_out_of_bounds or flash_lit: fb.point(z, x) fb.show() time.sleep(0.01)