def clear_screen(background="black"): if background == "white": display.set_pen(255, 255, 255) else: display.set_pen(0, 0, 0) display.clear() display.update()
def flash_b(): picodisplay.set_pen(100, 100, 100) picodisplay.clear() picodisplay.set_pen(255, 255, 255) picodisplay.text("F#$%!", 5, 10, 240, 5) picodisplay.set_pen(0, 0, 0) picodisplay.text("Its monday!", 5, 50, 240, 5) picodisplay.update()
def flash_a(): picodisplay.set_pen(175, 175, 175) picodisplay.clear() picodisplay.set_pen(255, 255, 255) picodisplay.text("Morning...", 5, 10, 240, 4) picodisplay.set_pen(0, 0, 0) picodisplay.text("Its monday!", 5, 50, 240, 5) picodisplay.update()
def initDisplay(): width = display.get_width() height = display.get_height() display_buffer = bytearray(width * height * 2) # 2-bytes per pixel (RGB565) display.init(display_buffer) display.set_backlight(1) display.set_pen(0, 0, 0) # black display.clear() display.set_pen(100, 100, 100) # white
def menu(): display.set_led(0, 0, 0) display.set_pen(BLACK) display.clear() display.set_pen(WHITE) display.text("Press any button!", 10, 10, 240, (3, 6)[best == 0]) if best > 0: display.text("Hiscore: " + str(best), 10, 68, 240, 3) display.update() # Update the display while True: if display.is_pressed(display.BUTTON_A) or display.is_pressed( display.BUTTON_B) or display.is_pressed( display.BUTTON_X) or display.is_pressed(display.BUTTON_Y): return utime.sleep(0.5)
def failed(): global best display.set_pen(RED) display.clear() display.set_pen(YELLOW) display.text("Game Over!", 10, 10, 240, 6) # Add some text display.update() # Update the display utime.sleep(1) display.set_pen(RED) display.clear() display.set_pen(YELLOW) display.text("Score: " + str(score), 10, 10, 240, 3) if score > best: display.text("New Hiscore!", 10, 68, 240, 3) best = score else: display.text("Hiscore: " + str(best), 10, 68, 240, 3) display.update() # Update the display utime.sleep(3)
def run(self): # Starting angle (unrotated in any dimension) angleX, angleY, angleZ = 0, 0, 0 distance_delta = 0.1 while 1: # It will hold transformed vertices. t = [] for v in self.vertices: # Rotate the point around X axis, then around Y axis, and finally around Z axis. r = v.rotateX(angleX).rotateY(angleY).rotateZ(angleZ) # Transform the point from 3D to 2D p = r.project(*self.projection) # Put the point in the list of transformed vertices t.append(p) display.set_pen(40, 40, 40) display.clear() display.set_pen(255, 255, 255) for e in self.edges: drawDDA(*to_int(t[e[0]].x, t[e[0]].y, t[e[1]].x, t[e[1]].y)) display.update() # Continue the rotation angleX += self.rotateX angleY += self.rotateY angleZ += self.rotateZ self.projection[3] += distance_delta if self.projection[3] > 12.0: distance_delta = -0.1 if self.projection[3] < 2.0: distance_delta = 0.1
conversion_factor = 3 * 3.3 / 65535 full_battery = 4.2 # these are our reference voltages for a full/empty battery, in volts empty_battery = 2.8 # the values could vary by battery size/manufacturer so you might need to adjust them while True: # convert the raw ADC read into a voltage, and then a percentage voltage = vsys.read_u16() * conversion_factor percentage = 100 * ((voltage - empty_battery) / (full_battery - empty_battery)) if percentage > 100: percentage = 100.00 # draw the battery outline display.set_pen(0, 0, 0) display.clear() display.set_pen(190, 190, 190) display.rectangle(0, 0, 220, 135) display.rectangle(220, 40, 20, 55) display.set_pen(0, 0, 0) display.rectangle(3, 3, 214, 129) # draw a green box for the battery level display.set_pen(0, 255, 0) display.rectangle(5, 5, round(210 / 100 * percentage), 125) # add text display.set_pen(255, 0, 0) if charging.value() == 1: # if it's plugged into USB power... display.text("Charging!", 15, 55, 240, 4) else: # if not, display the battery stats
def clearDisplay(): display.set_pen(BLACK) display.clear() display.update()
def clear(): display.set_pen(0, 0, 0) display.clear() display.update()
def clear_display(): display.set_pen(BACKGROUND_COLOUR["r"], BACKGROUND_COLOUR["g"], BACKGROUND_COLOUR["b"]) display.clear() display.update()
def clearDisplay(): display.set_pen(0, 0, 0) # black display.clear() display.set_pen(100, 100, 100) # white
q = v * (1.0 - s * f) t = v * (1.0 - s * (1.0 - f)) i = i % 6 if i == 0: return v, t, p if i == 1: return q, v, p if i == 2: return p, v, t if i == 3: return p, q, v if i == 4: return t, p, v if i == 5: return v, p, q h = 0 while True: h += 1 r, g, b = [int(255 * c) for c in hsv_to_rgb(h / 360.0, 1.0, 1.0)] # rainbow magic display.set_led(r, g, b) # Set LED to a converted HSV value display.set_pen(r, g, b) # Set pen to a converted HSV value display.clear() # Fill the screen with the colour display.set_pen(0, 0, 0) # Set pen to black display.text("pico disco!", 10, 10, 240, 6) # Add some text display.update() # Update the display utime.sleep(1.0 / 60)
def run_game(): global key_mode, game_state while True: ## Draw methods display.set_pen(*SKY_COLOR) display.clear() ground.draw() tank1.draw() tank2.draw() if (game_state == "player1fire" or game_state == "player2fire"): shell.draw() display.set_pen(*TEXT_COLOR) if (game_state == "player1" or game_state == "player1fire"): display.text("Player 1", 10, 10, 240, 1) if (key_mode == "power"): display.set_pen(*TEXT_COLOR_ACTIVE) display.text("Power " + str(tank1.get_gun_power()) + "%", 10, 20, 240, 1) # if (key_mode == "angle"): display.set_pen(*TEXT_COLOR_ACTIVE) else: display.set_pen(*TEXT_COLOR) display.text("Angle " + str(tank1.get_gun_angle()), 10, 30, 240, 1) if (game_state == "player2" or game_state == "player2fire"): display.text("Player 2", 180, 10, 240, 1) if (key_mode == "power"): display.set_pen(*TEXT_COLOR_ACTIVE) display.text("Power " + str(tank2.get_gun_power()) + "%", 180, 20, 240, 1) if (key_mode == "angle"): display.set_pen(*TEXT_COLOR_ACTIVE) else: display.set_pen(*TEXT_COLOR) display.text("Angle " + str(tank2.get_gun_angle()), 180, 30, 240, 1) if (game_state == "game_over_1"): display.text("Game Over", 50, 20, 240, 3) display.text("Player 1 wins!", 30, 40, 240, 3) if (game_state == "game_over_2"): display.text("Game Over", 50, 20, 240, 3) display.text("Player 2 wins!", 30, 40, 240, 3) display.update() ## Update methods # Only read keyboard in certain states if (game_state == 'player1'): player1_fired = player_keyboard("left") if (player1_fired == True): # Set shell position to end of gun # Use gun_positions so we can get start position gun_positions = tank1.calc_gun_positions() start_shell_pos = (gun_positions[3][0], gun_positions[3][1] + 2) shell.set_start_position(start_shell_pos) shell.set_current_position(start_shell_pos) game_state = 'player1fire' shell.set_angle(math.radians(tank1.get_gun_angle())) shell.set_power(tank1.get_gun_power() / 40) shell.set_time(0) if (game_state == 'player1fire'): shell.update_shell_position("left") # shell value is whether the shell is inflight, hit or missed shell_value = detect_hit("left") # shell_value 20 is if other tank hit if (shell_value >= 20): game_state = 'game_over_1' # 10 is offscreen and 11 is hit ground, both indicate missed elif (shell_value >= 10): # reset key mode to angle key_mode = "angle" game_state = 'player2' if (game_state == 'player2'): player2_fired = player_keyboard("right") if (player2_fired == True): # Set shell position to end of gun # Use gun_positions so we can get start position gun_positions = tank2.calc_gun_positions() start_shell_pos = (gun_positions[3][0], gun_positions[3][1] + 2) shell.set_start_position(start_shell_pos) shell.set_current_position(start_shell_pos) game_state = 'player2fire' shell.set_angle(math.radians(tank2.get_gun_angle())) shell.set_power(tank2.get_gun_power() / 40) shell.set_time(0) if (game_state == 'player2fire'): shell.update_shell_position("right") # shell value is whether the shell is inflight, hit or missed shell_value = detect_hit("right") # shell_value 20 is if other tank hit if (shell_value >= 20): game_state = 'game_over_2' # 10 is offscreen and 11 is hit ground, both indicate missed elif (shell_value >= 10): game_state = 'player1' # reset key mode to angle key_mode = "angle" if (game_state == 'game_over_1' or game_state == 'game_over_2'): # Allow space key or left-shift (picade) to continue if (display.is_pressed(display.BUTTON_B)): # Reset position of tanks and terrain setup()
def draw_background(self): display.set_pen(0, 0, 0) display.clear()