def on_draw(self): try: arcade.start_render() assert arcade.get_pixel(50, 50) == (59, 122, 87) self.sprite.draw() assert arcade.get_pixel(50, 50) == (255, 204, 0) except Exception as e: assert e is None
def on_draw(self): try: arcade.start_render() x = 50 y = 50 scale = 1.0 assert arcade.get_pixel(50, 50) == (59, 122, 87) arcade.draw_scaled_texture_rectangle(x, y, self.texture, scale) assert arcade.get_pixel(50, 50) == (255, 204, 0) except Exception as e: assert e is None
def on_draw(self): """ Render the screen. """ # This command has to happen before we start drawing arcade.start_render() print() tests = [ ['identity', Matrix3x3(), (14, 14, 0)], ['rotate(30)', Matrix3x3().rotate(30), (227, 86, 0)], ['scale(0.8, 0.5)', Matrix3x3().scale(0.8, 0.5), (241, 155, 0)], ['translate(0.3, 0.1)', Matrix3x3().translate(0.3, 0.1), (192, 243, 0)], ['rotate(10).\nscale(0.33, 0.33)', Matrix3x3().rotate(10).scale(0.7, 0.7), (222, 252, 116)], ['scale(-1, 1)', Matrix3x3().scale(-1, 1), (241, 14, 0)], ['shear(0.3, 0.1)', Matrix3x3().shear(0.3, 0.1), (48, 25, 0)], [f'rotate({int(self.t) % 360})', Matrix3x3().rotate(self.t), (14, 14, 0)], ] for i, test_data in enumerate(tests): x = 80 + 180 * (i % 4) y = 420 - (i // 4) * 320 text, texture, desired_color = test_data arcade.draw_text(text, x, y - 20 - text.count('\n') * 10, arcade.color.WHITE, 10) self.xy_square.draw_transformed(x, y, 100, 100, 0, 255, texture) test_x = x + 5 test_y = y + 5 actual_color = arcade.get_pixel(test_x, test_y) assert actual_color[0] == desired_color[0] assert actual_color[1] == desired_color[1] assert actual_color[2] == desired_color[2]
def on_draw(self): try: arcade.start_render() self.character_list.draw() for i in range(7): my_width = SIZE my_height = SIZE + i * 3 my_color = (i * 40, 0, 255) center_x = SPACING + (i * SPACING) center_y = ROW_SPACING # Sample bottom pixel_color = arcade.get_pixel(center_x, center_y - (my_height / 2 - 4)) assert pixel_color == my_color # Sample top pixel_color = arcade.get_pixel(center_x, center_y + (my_height / 2 - 4)) assert pixel_color == my_color # Sample right pixel_color = arcade.get_pixel(center_x + (my_width / 2 - 1), center_y) assert pixel_color == my_color for i in range(7): my_width = SIZE + i * 3 my_height = SIZE my_color = (0, i * 40, 255) center_x = SPACING + (i * SPACING) center_y = ROW_SPACING * 2 # Sample bottom pixel_color = arcade.get_pixel(center_x, center_y - (my_height / 2 - 1)) assert pixel_color == my_color # Sample top pixel_color = arcade.get_pixel(center_x, center_y + (my_height / 2 - 4)) assert pixel_color == my_color except Exception as e: assert e is None
def on_draw(self): try: arcade.start_render() self.coin_list.draw() self.character_list.draw() assert arcade.get_pixel(150, 50) == (191, 121, 88) assert arcade.get_pixel(230, 230) == (59, 122, 87) self.individual_coin.draw() assert arcade.get_pixel(230, 230) == (255, 204, 0) # Test for coin scaling if self.frame_counter < 5: assert arcade.get_pixel(130, 150) == (59, 122, 87) else: assert arcade.get_pixel(130, 150) == (227, 182, 2) except Exception as e: assert e is None
def on_update(self, time): self._time += time self._player.update() self._player_pos = self._player.position # print(arcade.get_pixel(player_pos[0] - 1, player_pos[1] - 1)) if arcade.get_pixel(self._player_pos[0], self._player_pos[1]) == (255, 255, 255): self._is_transparent = True else: self._is_transparent = False
def on_draw(self): """ Render the screen. """ # This command has to happen before we start drawing arcade.start_render() print() tests = [ ['identity', Matrix3x3(), (14, 14, 0)], ['rotate(30)', Matrix3x3().rotate(30), (230, 87, 0)], ['scale(0.8, 0.5)', Matrix3x3().scale(0.8, 0.5), (242, 158, 0)], [ 'translate(0.3, 0.1)', Matrix3x3().translate(0.3, 0.1), (194, 245, 0) ], [ 'rotate(10).\nscale(0.33, 0.33)', Matrix3x3().rotate(10).scale(0.7, 0.7), (252, 255, 244) ], ['scale(-1, 1)', Matrix3x3().scale(-1, 1), (243, 14, 0)], ['shear(0.3, 0.1)', Matrix3x3().shear(0.3, 0.1), (48, 26, 0)], [ f'rotate({int(self.t) % 360})', Matrix3x3().rotate(self.t), (14, 14, 0) ], ] for i, test_data in enumerate(tests): x = 80 + 180 * (i % 4) y = 420 - (i // 4) * 320 text, texture, desired_color = test_data arcade.draw_text(text, x, y - 20 - text.count('\n') * 10, arcade.color.WHITE, 10) self.xy_square.draw_transformed(x, y, 100, 100, 0, 255, texture) test_x = x + 5 test_y = y + 5 actual_color = arcade.get_pixel(test_x, test_y) # Mac, with its retina scaling, doesn't match other platforms. import sys if sys.platform != "darwin": # print(actual_color, desired_color) assert actual_color[0] == desired_color[0] assert actual_color[1] == desired_color[1] assert actual_color[2] == desired_color[2]
def on_draw(self): arcade.start_render() self.line_strip.draw() p = arcade.get_pixel(0, 100) assert p == (0, 0, 0) p = arcade.get_pixel(0, 96) assert p == (0, 0, 0) p = arcade.get_pixel(0, 94) assert p == (255, 255, 255) p = arcade.get_pixel(50, 100) assert p == (0, 0, 0) p = arcade.get_pixel(100, 200) assert p == (0, 0, 0) p = arcade.get_pixel(150, 300) assert p == (0, 0, 0) p = arcade.get_pixel(301, 300) assert p == (255, 255, 255)
def on_draw(self): """ Render the screen. """ # Start the render process. This must be done before any drawing commands. arcade.start_render() # Draw a grid # Draw vertical lines every 120 pixels for x in range(0, 601, 120): arcade.draw_line(x, 0, x, 600, arcade.color.BLACK, 2) # Draw horizontal lines every 200 pixels for y in range(0, 601, 200): arcade.draw_line(0, y, 800, y, arcade.color.BLACK, 2) # Draw a point arcade.draw_text("draw_point", 3, 405, arcade.color.BLACK, 12) arcade.draw_point(60, 495, arcade.color.RED, 10) # Draw a set of points arcade.draw_text("draw_points", 123, 405, arcade.color.BLACK, 12) point_list = ((165, 495), (165, 480), (165, 465), (195, 495), (195, 480), (195, 465)) arcade.draw_points(point_list, arcade.color.ZAFFRE, 10) # Draw a line arcade.draw_text("draw_line", 243, 405, arcade.color.BLACK, 12) arcade.draw_line(270, 495, 300, 450, arcade.color.WOOD_BROWN, 3) # Draw a set of lines arcade.draw_text("draw_lines", 363, 405, arcade.color.BLACK, 12) point_list = ((390, 450), (450, 450), (390, 480), (450, 480), (390, 510), (450, 510)) arcade.draw_lines(point_list, arcade.color.BLUE, 3) # Draw a line strip arcade.draw_text("draw_line_strip", 483, 405, arcade.color.BLACK, 12) point_list = ((510, 450), (570, 450), (510, 480), (570, 480), (510, 510), (570, 510)) arcade.draw_line_strip(point_list, arcade.color.TROPICAL_RAIN_FOREST, 3) arcade.draw_line_strip(point_list, arcade.color.BEIGE) # Draw a polygon arcade.draw_text("draw_polygon_outline", 3, 207, arcade.color.BLACK, 9) point_list = ((30, 240), (45, 240), (60, 255), (60, 285), (45, 300), (30, 300)) arcade.draw_polygon_outline(point_list, arcade.color.SPANISH_VIOLET, 3) # Draw a filled in polygon arcade.draw_text("draw_polygon_filled", 123, 207, arcade.color.BLACK, 9) point_list = ((150, 240), (165, 240), (180, 255), (180, 285), (165, 300), (150, 300)) arcade.draw_polygon_filled(point_list, arcade.color.SPANISH_VIOLET) # Draw an outline of a circle arcade.draw_text("draw_circle_outline", 243, 207, arcade.color.BLACK, 10) arcade.draw_circle_outline(300, 285, 18, arcade.color.WISTERIA, 3) arcade.draw_circle_outline(350, 285, 18, arcade.color.WISTERIA) # Draw a filled in circle arcade.draw_text("draw_circle_filled", 363, 207, arcade.color.BLACK, 10) arcade.draw_circle_filled(420, 285, 18, arcade.color.GREEN) # Draw an ellipse outline, and another one rotated arcade.draw_text("draw_ellipse_outline", 483, 207, arcade.color.BLACK, 10) arcade.draw_ellipse_outline(540, 273, 15, 36, arcade.color.AMBER, 3) arcade.draw_ellipse_outline(540, 336, 15, 36, arcade.color.BLACK_BEAN, 3, 45) # Draw a filled ellipse, and another one rotated arcade.draw_text("draw_ellipse_filled", 3, 3, arcade.color.BLACK, 10) arcade.draw_ellipse_filled(60, 81, 15, 36, arcade.color.AMBER) arcade.draw_ellipse_filled(60, 144, 15, 36, arcade.color.BLACK_BEAN, 45) # Draw an arc, and another one rotated arcade.draw_text("draw_arc/filled_arc", 123, 3, arcade.color.BLACK, 10) arcade.draw_arc_outline(150, 81, 15, 36, arcade.color.BRIGHT_MAROON, 90, 360) arcade.draw_arc_filled(150, 144, 15, 36, arcade.color.BOTTLE_GREEN, 90, 360, 45) # Draw an rectangle outline arcade.draw_text("draw_rect", 243, 3, arcade.color.BLACK, 10) arcade.draw_rectangle_outline(295, 100, 45, 65, arcade.color.BRITISH_RACING_GREEN) arcade.draw_rectangle_outline(295, 160, 20, 45, arcade.color.BRITISH_RACING_GREEN, 3, 45) # Draw a filled in rectangle arcade.draw_text("draw_filled_rect", 363, 3, arcade.color.BLACK, 10) arcade.draw_rectangle_filled(420, 100, 45, 65, arcade.color.BLUSH) arcade.draw_rectangle_filled(420, 160, 20, 40, arcade.color.BLUSH, 45) # Load and draw an image to the screen # Image from kenney.nl asset pack #1 arcade.draw_text("draw_bitmap", 483, 3, arcade.color.BLACK, 12) texture = arcade.load_texture("images/playerShip1_orange.png") scale = .6 arcade.draw_texture_rectangle(540, 120, scale * texture.width, scale * texture.height, texture, 0) arcade.draw_texture_rectangle(540, 60, scale * texture.width, scale * texture.height, texture, 45) color = arcade.get_pixel(100, 100) assert color == (255, 255, 255) image = arcade.get_image()
def on_draw(self): """ Render the screen. """ # Start the render process. This must be done before any drawing commands. arcade.start_render() # Draw a grid # Draw vertical lines every 120 pixels for x in range(0, 601, 120): arcade.draw_line(x, 0, x, 600, arcade.color.BLACK, 2) # Draw horizontal lines every 200 pixels for y in range(0, 601, 200): arcade.draw_line(0, y, 800, y, arcade.color.BLACK, 2) # Draw a point arcade.draw_text("draw_point", 3, 405, arcade.color.BLACK, 12) arcade.draw_point(60, 495, arcade.color.RED, 10) # Draw a set of points arcade.draw_text("draw_points", 123, 405, arcade.color.BLACK, 12) point_list = ((165, 495), (165, 480), (165, 465), (195, 495), (195, 480), (195, 465)) arcade.draw_points(point_list, arcade.color.ZAFFRE, 10) # Draw a line arcade.draw_text("draw_line", 243, 405, arcade.color.BLACK, 12) arcade.draw_line(270, 495, 300, 450, arcade.color.WOOD_BROWN, 3) # Draw a set of lines arcade.draw_text("draw_lines", 363, 405, arcade.color.BLACK, 12) point_list = ((390, 450), (450, 450), (390, 480), (450, 480), (390, 510), (450, 510)) arcade.draw_lines(point_list, arcade.color.BLUE, 3) # Draw a line strip arcade.draw_text("draw_line_strip", 483, 405, arcade.color.BLACK, 12) point_list = ((510, 450), (570, 450), (510, 480), (570, 480), (510, 510), (570, 510)) arcade.draw_line_strip(point_list, arcade.color.TROPICAL_RAIN_FOREST, 3) arcade.draw_line_strip(point_list, arcade.color.BEIGE) # Draw a polygon arcade.draw_text("draw_polygon_outline", 3, 207, arcade.color.BLACK, 9) point_list = ((30, 240), (45, 240), (60, 255), (60, 285), (45, 300), (30, 300)) arcade.draw_polygon_outline(point_list, arcade.color.SPANISH_VIOLET, 3) # Draw a filled in polygon arcade.draw_text("draw_polygon_filled", 123, 207, arcade.color.BLACK, 9) point_list = ((150, 240), (165, 240), (180, 255), (180, 285), (165, 300), (150, 300)) arcade.draw_polygon_filled(point_list, arcade.color.SPANISH_VIOLET) # Draw an outline of a circle arcade.draw_text("draw_circle_outline", 243, 207, arcade.color.BLACK, 10) arcade.draw_circle_outline(300, 285, 18, arcade.color.WISTERIA, 3) arcade.draw_circle_outline(350, 285, 18, arcade.color.WISTERIA) # Draw a filled in circle arcade.draw_text("draw_circle_filled", 363, 207, arcade.color.BLACK, 10) arcade.draw_circle_filled(420, 285, 18, arcade.color.GREEN) # Draw an ellipse outline, and another one rotated arcade.draw_text("draw_ellipse_outline", 483, 207, arcade.color.BLACK, 10) arcade.draw_ellipse_outline(540, 273, 15, 36, arcade.color.AMBER, 3) arcade.draw_ellipse_outline(540, 336, 15, 36, arcade.color.BLACK_BEAN, 3, 45) # Draw a filled ellipse, and another one rotated arcade.draw_text("draw_ellipse_filled", 3, 3, arcade.color.BLACK, 10) arcade.draw_ellipse_filled(60, 81, 15, 36, arcade.color.AMBER) arcade.draw_ellipse_filled(60, 144, 15, 36, arcade.color.BLACK_BEAN, 45) # Draw an arc, and another one rotated arcade.draw_text("draw_arc/filled_arc", 123, 3, arcade.color.BLACK, 10) arcade.draw_arc_outline(150, 81, 15, 36, arcade.color.BRIGHT_MAROON, 90, 360) arcade.draw_arc_filled(150, 144, 15, 36, arcade.color.BOTTLE_GREEN, 90, 360, 45) # Draw an rectangle outline arcade.draw_text("draw_rect", 243, 3, arcade.color.BLACK, 10) arcade.draw_rectangle_outline(295, 100, 45, 65, arcade.color.BRITISH_RACING_GREEN) arcade.draw_rectangle_outline(295, 160, 20, 45, arcade.color.BRITISH_RACING_GREEN, 3, 45) # Draw a filled in rectangle arcade.draw_text("draw_filled_rect", 363, 3, arcade.color.BLACK, 10) arcade.draw_rectangle_filled(420, 100, 45, 65, arcade.color.BLUSH) arcade.draw_rectangle_filled(420, 160, 20, 40, arcade.color.BLUSH, 45) # Load and draw an image to the screen # Image from kenney.nl asset pack #1 arcade.draw_text("draw_bitmap", 483, 3, arcade.color.BLACK, 12) texture = arcade.load_texture( ":resources:images/space_shooter/playerShip1_orange.png") scale = .6 # arcade.draw_texture_rectangle(540, 120, scale * texture.width, # scale * texture.height, texture, 0) # arcade.draw_texture_rectangle(540, 60, scale * texture.width, # scale * texture.height, texture, 45) # # Overlapping, with transparency test # Draw arcade.draw_rectangle_filled(650, 100, 50, 50, (255, 0, 0)) arcade.draw_rectangle_filled(670, 100, 50, 50, (0, 255, 0, 127)) import sys # TODO: Fix. See https://github.com/pvcraven/arcade/issues/539 if sys.platform != "darwin": # Test colors color = arcade.get_pixel(635, 100) assert color == (255, 0, 0) color = arcade.get_pixel(670, 100) assert color == (128, 127, 0) color = arcade.get_pixel(690, 100) assert color == (128, 255, 128) # Test this other thing color = arcade.get_pixel(100, 100) assert color == (255, 255, 255) # Run the get image. Ideally we'd test the output arcade.get_image()