def show_digit(val, xd, yd, r, g, b): offset = val * 15 for p in range(offset, offset + 15): xt = p % 3 yt = (p - offset) // 3 ledmatrix.set_pixel(xt + xd, 7 - yt - yd, r * NUMS[p], g * NUMS[p], b * NUMS[p]) ledmatrix.show()
def draw_ball(): ledmatrix.set_pixel( game_state.ball_x, game_state.ball_y, ball_color[0], ball_color[1], ball_color[2], )
def show_map(r, g, b): for x in range(0, 7): for y in range(0, 7): z = (float(y) + 7.0 * float(x)) / 49.0 rr = int(z * r) gg = int(z * g) bb = int(z * b) ledmatrix.set_pixel(x, y, rr, gg, bb) ledmatrix.show()
def draw_bats(): for y in range(7): ledmatrix.set_pixel(0, y, background_color[0], background_color[1], background_color[2]) ledmatrix.set_pixel(6, y, background_color[0], background_color[1], background_color[2]) for y in range(game_state.bat_left_size): ledmatrix.set_pixel( 0, y + game_state.bat_left_y, left_bat_color[0], left_bat_color[1], left_bat_color[2], ) for y in range(game_state.bat_right_size): ledmatrix.set_pixel( 6, y + game_state.bat_right_y, right_bat_color[0], right_bat_color[1], right_bat_color[2], )
def draw_battery_outline(): # Draw the naked battery for y in range(0, 6): ledmatrix.set_pixel(1, y, 64, 64, 255) ledmatrix.set_pixel(5, y, 64, 64, 255) for x in range(2, 5): ledmatrix.set_pixel(x, 0, 64, 64, 255) ledmatrix.set_pixel(x, 6, 192, 192, 192) ledmatrix.show()
def update_battery_state(charging_state, capacity): r = 0 g = 0 b = 0 if charging_state == 0: if capacity < 11: r = 255 else: g = 255 elif charging_state == 1: r = 255 g = 225 cap = int(capacity / 20) + 1 if cap < 0: cap = 0 if cap > 5: cap = 5 if cap > 0: for y in range(1, cap + 1): ledmatrix.set_pixel(2, y, r, g, b) ledmatrix.set_pixel(3, y, r, g, b) ledmatrix.set_pixel(4, y, r, g, b) if cap == 0: cap = 1 if cap < 6: if (capacity < 50) and (charging_state == 0): # blinking warning for i in range(1, 3): for y in range(cap + 1, 6): ledmatrix.set_pixel(2, y, 0, 0, 0) ledmatrix.set_pixel(3, y, 0, 0, 0) ledmatrix.set_pixel(4, y, 0, 0, 0) ledmatrix.show() sleep(0.4) for y in range(cap + 1, 6): ledmatrix.set_pixel(2, y, 255, 0, 0) ledmatrix.set_pixel(3, y, 255, 0, 0) ledmatrix.set_pixel(4, y, 255, 0, 0) ledmatrix.show() sleep(0.4) else: for y in range(cap + 1, 6): ledmatrix.set_pixel(2, y, 0, 0, 0) ledmatrix.set_pixel(3, y, 0, 0, 0) ledmatrix.set_pixel(4, y, 0, 0, 0) ledmatrix.show() sleep(5) return 0
col = (col[0] * shade, col[1] * shade, col[2] * shade) return (col[0] * 255, col[1] * 255, col[2] * 255) effects = [tunnel, rainbow_search, checker, swirl] step = 0 while True: for i in range(500): for y in range(s_height): for x in range(s_width): r, g, b = effects[0](x, y, step) if i > 400: r2, g2, b2 = effects[-1](x, y, step) ratio = (500.00 - i) / 100.0 r = r * ratio + r2 * (1.0 - ratio) g = g * ratio + g2 * (1.0 - ratio) b = b * ratio + b2 * (1.0 - ratio) r = int(max(0, min(255, r))) g = int(max(0, min(255, g))) b = int(max(0, min(255, b))) ledmatrix.set_pixel(x, y, r, g, b) step += 1 ledmatrix.show() effect = effects.pop() effects.insert(0, effect)
ledmatrix.rotation(0) try: while True: rate = get_cpu_rates() ledmatrix.clear() for i in range(0, 4): level = int(6.99 * rate[i]) if level < 4: r = 0 g = 255 b = 0 elif level < 6: r = 255 g = 255 b = 6 else: r = 255 g = 0 b = 0 for y in range(0, level + 1): ledmatrix.set_pixel(2 * i, y, r, g, b) ledmatrix.show() time.sleep(1) except KeyboardInterrupt: ledmatrix.clear() ledmatrix.show()