def __init__(self, width, height, title): """ Set up the application. """ super().__init__(width, height, title) self.shape_list = arcade.ShapeElementList() self.shape_list.center_x = SCREEN_WIDTH // 2 self.shape_list.center_y = SCREEN_HEIGHT // 2 self.shape_list.angle = 0 point_list = ((0, 50), (10, 10), (50, 0), (10, -10), (0, -50), (-10, -10), (-50, 0), (-10, 10), (0, 50)) colors = [ getattr(arcade.color, color) for color in dir(arcade.color) if not color.startswith("__") ] for i in range(5): x = SCREEN_WIDTH // 2 - random.randrange(SCREEN_WIDTH - 50) y = SCREEN_HEIGHT // 2 - random.randrange(SCREEN_HEIGHT - 50) color = random.choice(colors) points = [(px + x, py + y) for px, py in point_list] my_line_strip = arcade.create_line_strip(points, color, 5) self.shape_list.append(my_line_strip) point_list = ((-50, -50), (0, 40), (50, -50)) for i in range(5): x = SCREEN_WIDTH // 2 - random.randrange(SCREEN_WIDTH - 50) y = SCREEN_HEIGHT // 2 - random.randrange(SCREEN_HEIGHT - 50) points = [(px + x, py + y) for px, py in point_list] triangle_filled = arcade.create_triangles_filled_with_colors( points, random.sample(colors, 3)) self.shape_list.append(triangle_filled) point_list = ((-50, -70), (-50, 70), (50, 70), (50, -70)) for i in range(5): x = SCREEN_WIDTH // 2 - random.randrange(SCREEN_WIDTH - 50) y = SCREEN_HEIGHT // 2 - random.randrange(SCREEN_HEIGHT - 50) points = [(px + x, py + y) for px, py in point_list] rect_filled = arcade.create_rectangle_filled_with_colors( points, random.sample(colors, 4)) self.shape_list.append(rect_filled) point_list = ((100, 100), (50, 150), (100, 200), (200, 200), (250, 150), (200, 100)) poly = arcade.create_polygon(point_list, (255, 10, 10)) self.shape_list.append(poly) ellipse = arcade.create_ellipse(20, 30, 50, 20, (230, 230, 0)) self.shape_list.append(ellipse) arcade.set_background_color(arcade.color.BLACK) self.offscreen = self.ctx.framebuffer( color_attachments=self.ctx.texture((SCREEN_WIDTH, SCREEN_HEIGHT), wrap_x=gl.GL_CLAMP_TO_EDGE, wrap_y=gl.GL_CLAMP_TO_EDGE)) self.glow = postprocessing.BloomEffect((SCREEN_WIDTH, SCREEN_HEIGHT))
def __init__(self, width, height, title): """ Set up the application. """ super().__init__(width, height, title) arcade.set_background_color(arcade.color.BLACK) self.shapes = arcade.ShapeElementList() # This is a large rectangle that fills the whole # background. The gradient goes between the two colors # top to bottom. color1 = (215, 214, 165) color2 = (219, 166, 123) points = (0, 0), (SCREEN_WIDTH, 0), (SCREEN_WIDTH, SCREEN_HEIGHT), (0, SCREEN_HEIGHT) colors = (color1, color1, color2, color2) # rect = arcade.create_rectangle_filled_with_colors(points, colors) # self.shapes.append(rect) # Another rectangle, but in this case the color doesn't change. Just the # transparency. This time it goes from left to right. color1 = (165, 92, 85, 255) color2 = (165, 92, 85, 0) points = (100, 100), (SCREEN_WIDTH - 100, 100), (SCREEN_WIDTH - 100, 300), (100, 300) colors = (color2, color1, color1, color2) # rect = arcade.create_rectangle_filled_with_colors(points, colors) # self.shapes.append(rect) # Two lines color1 = (7, 67, 88) color2 = (69, 137, 133) points = (100, 400), (SCREEN_WIDTH - 100, 400), (SCREEN_WIDTH - 100, 500), (100, 500) colors = [color2, color1, color2, color1] # shape = arcade.create_lines_with_colors(points, colors, line_width=5) # self.shapes.append(shape) # Triangle color1 = (215, 214, 165) color2 = (219, 166, 123) color3 = (165, 92, 85) points = (SCREEN_WIDTH // 2, 500), (SCREEN_WIDTH // 2 - 100, 400), (SCREEN_WIDTH // 2 + 100, 400) colors = (color1, color2, color3) shape = arcade.create_triangles_filled_with_colors(points, colors) self.shapes.append(shape) # Ellipse, gradient between center and outside color1 = (69, 137, 133, 127) color2 = (7, 67, 88, 127)
def create_turtle(self, center_x, center_y, base=30, height=25): point_list = [ (center_x - base//2, center_y + height//2), (center_x + base//2, center_y + height//2), (center_x, center_y - (height//2 + 5)), ] color_list = [ arcade.color.BLACK, arcade.color.BLACK, arcade.color.BLACK ] return arcade.create_triangles_filled_with_colors(point_list, color_list)
def __init__(self, width, height): """ Set up the application. """ super().__init__(width, height) self.shape_list = arcade.ShapeElementList() self.shape_list.center_x = SCREEN_WIDTH // 2 self.shape_list.center_y = SCREEN_HEIGHT // 2 self.shape_list.angle = 0 point_list = ((0, 50), (10, 10), (50, 0), (10, -10), (0, -50), (-10, -10), (-50, 0), (-10, 10), (0, 50)) colors = [ getattr(arcade.color, color) for color in dir(arcade.color) if not color.startswith("__") ] for i in range(5): x = SCREEN_WIDTH // 2 - random.randrange(SCREEN_WIDTH - 50) y = SCREEN_HEIGHT // 2 - random.randrange(SCREEN_HEIGHT - 50) color = random.choice(colors) points = [(px + x, py + y) for px, py in point_list] my_line_strip = arcade.create_line_strip(points, color, 5) self.shape_list.append(my_line_strip) point_list = ((-50, -50), (0, 40), (50, -50)) for i in range(5): x = SCREEN_WIDTH // 2 - random.randrange(SCREEN_WIDTH - 50) y = SCREEN_HEIGHT // 2 - random.randrange(SCREEN_HEIGHT - 50) points = [(px + x, py + y) for px, py in point_list] triangle_filled = arcade.create_triangles_filled_with_colors( points, random.sample(colors, 3)) self.shape_list.append(triangle_filled) point_list = ((-50, -70), (-50, 70), (50, 70), (50, -70)) for i in range(5): x = SCREEN_WIDTH // 2 - random.randrange(SCREEN_WIDTH - 50) y = SCREEN_HEIGHT // 2 - random.randrange(SCREEN_HEIGHT - 50) points = [(px + x, py + y) for px, py in point_list] rect_filled = arcade.create_rectangle_filled_with_colors( points, random.sample(colors, 4)) self.shape_list.append(rect_filled) point_list = ((100, 100), (50, 150), (100, 200), (200, 200), (250, 150), (200, 100)) poly = arcade.create_polygon(point_list, (255, 10, 10), 5) self.shape_list.append(poly) ellipse = arcade.create_ellipse(20, 30, 50, 20, (230, 230, 0)) self.shape_list.append(ellipse) arcade.set_background_color(arcade.color.BLACK)
def setup_draw(self): ''' Creating the inital shapes to be rendered later by the BoxCar class. ''' self.visuals.center_x = self.body.position.x self.visuals.center_y = self.body.position.y for i in range(len(self.vertices) - 1): v = self.vertices[i] v_1 = self.vertices[i + 1] colour_list = self.__generate_colour_list(v, v_1) shape = arcade.create_triangles_filled_with_colors( [v, v_1, (0, 0)], colour_list) self.visuals.append(shape) v = self.vertices[0] v_1 = self.vertices[-1] colour_list = self.__generate_colour_list(v, v_1) shape = arcade.create_triangles_filled_with_colors([v, v_1, (0, 0)], colour_list) self.visuals.append(shape)
def _update_cells_colors(self): """ Map visual part update. """ color_list = [] # Colors recalculation. for cell in self.world_map.cells: color = self._get_cell_color(cell) color_list.extend(3 * [color]) self._cells_grid_container = arcade.ShapeElementList() cells_grid = arcade.create_triangles_filled_with_colors( self._cells_vertices, color_list) self._cells_grid_container.append(cells_grid)
def draw(self): rad=np.arctan(self.velocity[1]/(self.velocity[0]+sys.float_info.epsilon)) - \ (1 - np.sign(self.velocity[0])) * np.sign(self.velocity[0]) * np.pi / 2 # rad=np.arctan(self.y()/(self.x()+sys.float_info.epsilon)) theta = np.arccos(1 - BOID_CONFIG["base"]**2 / (2 * BOID_CONFIG["radius"]**2)) x1, y1 = (self.x() + BOID_CONFIG["radius"] * np.cos(rad), self.y() + BOID_CONFIG["radius"] * np.sin(rad)) u1 = rad - np.pi + theta / 2 u2 = rad + np.pi - theta / 2 x2, y2 = (self.x() + BOID_CONFIG["radius"] * np.cos(u1), self.y() + BOID_CONFIG["radius"] * np.sin(u1)) x3, y3 = (self.x() + BOID_CONFIG["radius"] * np.cos(u2), self.y() + BOID_CONFIG["radius"] * np.sin(u2)) self.shape = arcade.create_triangles_filled_with_colors( [(x1, y1), (x2, y2), (x3, y3)], [BOID_CONFIG["color"], BOID_CONFIG["color"], BOID_CONFIG["color"]])
def on_draw(self): """ Called whenever we need to draw the window. """ shapes = arcade.ShapeElementList() pipePoints = [] pipeColors = [] for pipe in self.pipes: pipe.append_points(pipePoints, pipeColors) shapes.append( arcade.create_rectangles_filled_with_colors( pipePoints, pipeColors)) birdPoints = [] birdColors = [] for bird in self.pop.alive: bird.append_points(birdPoints, birdColors) shapes.append( arcade.create_triangles_filled_with_colors(birdPoints, birdColors)) arcade.start_render() shapes.draw() arcade.draw_text('High Score: ' + str(self.highScore), WINDOW_WIDTH // 2 - 40, WINDOW_HEIGHT - FONT_SIZE - 10, arcade.color.TIGERS_EYE, FONT_SIZE)