def create_border_rect(self, x, y): rect = arcade.create_rectangle_filled( center_x=x, center_y=y, width=24, height=24, color=DARK_GRAY) self.rect_list.append(rect)
def create_game_piece_rect(self, x, y, color): rect = arcade.create_rectangle_filled( center_x=x, center_y=y, width=24, height=24, color=COLORS[color]) self.rect_list.append(rect)
def _create_shape(self, scale) -> Shape: """ Create a shape representing this lake. :return: a Arcade shape object. """ return create_rectangle_filled(self.center_x, self.center_y, self.width * scale, self.height * scale, self.color)
def __init__(self, xpos, ypos): self._width = 35 super().__init__(xpos, ypos, self._width, self._width, 0, arcade.color.MAGENTA) shape = arcade.create_rectangle_filled(0, 0, self.width, self.height, self.color, self.angle) self.shape_list = arcade.ShapeElementList() self.shape_list.append(shape)
def __init__(self, x, y, width, height, color): self.x = x + int(width / 2) self.y = y + int(height / 2) self.width = width self.height = height self.color = color self.shape = arcade.create_rectangle_filled(self.x, self.y, self.width, self.height, self.color)
def setup(self): # --- Create the vertex buffers objects for each square before we do # any drawing. self.shape_list = arcade.ShapeElementList() for x in range(0, SCREEN_WIDTH, SQUARE_SPACING): for y in range(0, SCREEN_HEIGHT, SQUARE_SPACING): shape = arcade.create_rectangle_filled(x, y, SQUARE_WIDTH, SQUARE_HEIGHT, arcade.color.DARK_BLUE) self.shape_list.append(shape)
def main(): file_name = input("Enter a file name: ") data = list() lines = open(file_name, 'r') for line in lines.readlines(): split_line = line.split(":") split_line[0] = split_line[0].strip() split_line[1] = int(split_line[1].strip()) data.append(split_line) lines.close() arcade.open_window(800, 800, "project3") arcade.set_background_color(arcade.color.FAWN) yaxis = arcade.create_line(30, 100, 30, 800, arcade.color.KOBE) xaxis = arcade.create_line(30, 100, 800, 100, arcade.color.AVOCADO) bar_width = 50 y_scale = 30 y_offset = 100 x_offset = 100 colors = [ arcade.color.AVOCADO, arcade.color.BALL_BLUE, arcade.color.BANANA_MANIA, arcade.color.ARSENIC, arcade.color.ANTIQUE_WHITE, arcade.color.BITTERSWEET ] bars = [] for i in range(len(data)): height = data[i][1] bars.append( arcade.create_rectangle_filled( x_offset + i * bar_width * 2, y_offset + int(height) / 4 * y_scale, bar_width, height / 2 * y_scale, colors[random.randint(0, len(colors) - 1)])) text_width = 15 # paul = arcade.create_rectangle_filled(100, 100, 70, 100, arcade.color.AMARANTH_PURPLE) # haleh = arcade.create_rectangle_filled(200, 110, 70, 120, arcade.color.ANTIQUE_WHITE) # enping = arcade.create_rectangle_filled(300, 120, 70, 140, arcade.color.AVOCADO) # michael = arcade.create_rectangle_filled(400, 130, 70, 160, arcade.color.BALL_BLUE) # seikyung = arcade.create_rectangle_filled(500, 140, 70, 180, arcade.color.ARSENIC) # john = arcade.create_rectangle_filled(600, 150, 70, 200, arcade.color.BANANA_MANIA) # abdul = arcade.create_rectangle_filled(700, 160, 70, 220, arcade.color.BITTERSWEET) # text1 = arcade.draw_text("paul", 75, 30, arcade.color.AMARANTH_PURPLE) # text2 = arcade.draw_text("haleh", 175, 30, arcade.color.ANTIQUE_WHITE) # text3 = arcade.draw_text("enping", 270, 30, arcade.color.AVOCADO) # text4 = arcade.draw_text("michael", 370, 30, arcade.color.BALL_BLUE) # text5 = arcade.draw_text("seikyung", 470, 30, arcade.color.ARSENIC) # text6 = arcade.draw_text("john", 570, 30, arcade.color.BANANA_MANIA) # text7 = arcade.draw_text("abdul", 670, 30, arcade.color.BITTERSWEET) arcade.start_render() for bar in bars: bar.draw() for i in range(len(data)): arcade.draw_text(data[i][0], i * bar_width + x_offset, 80, arcade.color.BARN_RED) yaxis.draw() xaxis.draw() arcade.finish_render() arcade.run()
def set_cursor(self, center_x: float, center_y: float, alpha: int) -> None: color = self.cursor_color if len(self.cursor_color) == 3 else self.cursor_color[:-1] self.cursor = arcade.create_rectangle_filled( center_x=center_x, center_y=center_y, width=1, height=self.text_sprites[self.cursor_idx].height, color=(*color, alpha) )
def make_person(head_radius, chest_height, chest_width, leg_width, leg_height, arm_width, arm_length, arm_gap, shoulder_height): shape_list = arcade.ShapeElementList() # Head shape = arcade.create_ellipse_filled(0, chest_height / 2 + head_radius, head_radius, head_radius, arcade.color.WHITE) shape_list.append(shape) # Chest shape = arcade.create_rectangle_filled(0, 0, chest_width, chest_height, arcade.color.BLACK) shape_list.append(shape) # Left leg shape = arcade.create_rectangle_filled( -(chest_width / 2) + leg_width / 2, -(chest_height / 2) - leg_height / 2, leg_width, leg_height, arcade.color.RED) shape_list.append(shape) # Right leg shape = arcade.create_rectangle_filled( (chest_width / 2) - leg_width / 2, -(chest_height / 2) - leg_height / 2, leg_width, leg_height, arcade.color.RED) shape_list.append(shape) # Left arm shape = arcade.create_rectangle_filled( -(chest_width / 2) - arm_width / 2 - arm_gap, (chest_height / 2) - arm_length / 2 - shoulder_height, arm_width, arm_length, arcade.color.BLUE) shape_list.append(shape) # Left shoulder shape = arcade.create_rectangle_filled( -(chest_width / 2) - (arm_gap + arm_width) / 2, (chest_height / 2) - shoulder_height / 2, arm_gap + arm_width, shoulder_height, arcade.color.BLUE_BELL) shape_list.append(shape) # Right arm shape = arcade.create_rectangle_filled( (chest_width / 2) + arm_width / 2 + arm_gap, (chest_height / 2) - arm_length / 2 - shoulder_height, arm_width, arm_length, arcade.color.BLUE) shape_list.append(shape) # Right shoulder shape = arcade.create_rectangle_filled( (chest_width / 2) + (arm_gap + arm_width) / 2, (chest_height / 2) - shoulder_height / 2, arm_gap + arm_width, shoulder_height, arcade.color.BLUE_BELL) shape_list.append(shape) return shape_list
def set_goal(self, row, col): spot = self.spots[row][col] if spot.is_not_wall(): self.GOAL = spot self.spots_list[row * DIV + col] = arcade.create_rectangle_filled( spot.x * G_W + G_W / 2, spot.y * G_H + G_H / 2, G_W, G_H, arcade.color.AO) self.__recalculate_grid() return self.GOAL return None
def stars_render(self): for j in range(0, len(self.stars)): star = self.stars[j] if abs(self.player.x - star["x"]) < 800 and abs(self.player.y - star["y"]) < 800: self.draw_list.append( arcade.create_rectangle_filled( 400 - (self.player.x - star["x"]), 400 - (self.player.y - star["y"]), 1, 1, colors["white"], 0))
def __init__(self, x, y, width, height, angle, delta_x, delta_y, delta_angle, color): super().__init__(x, y, width, height, angle, delta_x, delta_y, delta_angle, color) shape = arcade.create_rectangle_filled(0, 0, self.width, self.height, self.color, self.angle) self.shape_list = arcade.ShapeElementList() self.shape_list.append(shape)
def create_starfield(shape_list, color=arcade.color.WHITE, random_color=False): for i in range(200): x = random.randint(0, 1280) y = random.randint(0, 720) w = random.randint(1, 3) h = random.randint(1, 3) if random_color: color = random.choice(fg_star_colors) star = arcade.create_rectangle_filled(x, y, w, h, color) shape_list.append(star)
def generate_buttons(self): self.buttons = arcade.ShapeElementList() x = self.button_dict()["button_x"] for i in range(NUM_BUTTONS): y = self.button_dict()["button_y"] - (BUTTON_SPACING * i) button = arcade.create_rectangle_filled( x, y, BUTTON_WIDTH, BUTTON_HEIGHT, self.button_dict()["button_color"]) self.buttons.append(button)
def setup(self): # reset player position, current player and board self.player_position = 4 self.current_player = 1 self.board_position = self.new_board() self.current_state = GAME_RUNNING self.winner = None # create shapes for drawing background board arcade.set_background_color(arcade.color.WHITE) self.shape_list = arcade.ShapeElementList() self.shape_list.append( arcade.create_rectangle_filled( self.width / 2, self.height / 2, self.width * (1 - MARGIN_PERCENTAGE + 0.02), self.height * (1 - MARGIN_PERCENTAGE + 0.02), arcade.color.DARK_PASTEL_BLUE)) self.shape_list.append( arcade.create_rectangle_filled( self.width / 2, self.height / 2, self.width * (1 - MARGIN_PERCENTAGE), self.height * (1 - MARGIN_PERCENTAGE), arcade.color.BRIGHT_NAVY_BLUE)) # create sprites (all potential circles and colors) self.board_sprite_list = arcade.SpriteList() for row in range(ROW_COUNT): for column in range(COLUMN_COUNT): sprite = arcade.Sprite() # assign all three color options to each field for texture in self.texture_list: sprite.append_texture(texture) # set default / start color sprite.set_texture(0) sprite.center_x = self.left_margin + (self.circle_max_radius * (2 * column + 1)) sprite.center_y = self.height - self.bottom_margin - ( self.circle_max_radius * (2 * row + 1)) self.board_sprite_list.append(sprite)
def recreate_grid(self): self.shape_list = arcade.ShapeElementList() for row in range(ROW_COUNT): for column in range(COLUMN_COUNT): if grid[row][column]: color = arcade.color.SMOKY_BLACK else: color = arcade.color.WHITE x, y = get_grid_points(row, column) current_rect = arcade.create_rectangle_filled(x, y, WIDTH, HEIGHT, color) self.shape_list.append(current_rect)
def rectangle(self, x, y, width, height, rotation=None): if rotation == "horizontal": self.edge = (x, y - height) edge_dict = {"y_min": self.edge[1], "y_max": self.edge[1] + width} elif rotation == "vertical": self.edge = (x - width / 2, y) edge_dict = {"x_min": self.edge[0], "x_max": self.edge[0] + width} else: edge_dict = None return edge_dict, arcade.create_rectangle_filled( x, y, width, height, arcade.color.BLUE)
def make_kinematic_shape(self): # dynamic circle s = arcade.create_rectangle_filled(0, 0, self.box_width, self.box_height, arcade.color.GRAY) self.kinematic_shape_element.append(s) s = arcade.create_rectangle(0, 0, self.box_width, self.box_height, arcade.color.LAVENDER_GRAY, 3, filled=False) self.kinematic_shape_element.append(s) s = arcade.create_rectangle_filled(int(self.box_width * 0.35), 0, 3, int(self.box_height * 0.8), arcade.color.LAVENDER_GRAY) self.kinematic_shape_element.append(s)
def create_menu_board(self, colour): """ Create a coloured rectangle for the menu board. Return an object that can be rendered to the screen efficiently. """ menu_board = arcade.create_rectangle_filled( settings.WINDOW_WIDTH / 2, settings.WINDOW_HEIGHT / 2, settings.WINDOW_WIDTH - (settings.CELL * 2), settings.WINDOW_HEIGHT - (settings.CELL * 2), colour) return menu_board
def update_hp_bar_location(self): self.remaining_hp = self.total_hp - self.damage_taken ## position hp bar carefully inside the outline, when hp bar shrinks, the center changes # if self.remaining_hp <= self.total_hp: self.center_pos = (self.center_x - HP_BAR_WIDTH / 2) + ( HP_BAR_WIDTH * self.remaining_hp / self.total_hp) / 2 self.rect = arcade.create_rectangle_filled( self.center_pos, self.top + self.height * 0.1, (self.remaining_hp / self.total_hp) * self.hp_bar_width, self.hp_bar_height, self.hp_bar_color, 0)
def reset_goal(self): self.open_set = [] self.closed_set = [] self.open_set.append(self.START) spot = self.GOAL if spot: self.spots_list[spot.x * DIV + spot.y] = arcade.create_rectangle_filled( spot.x * G_W + G_W / 2, spot.y * G_H + G_H / 2, G_W, G_H, arcade.color.RED) self.GOAL = None self.__recalculate_grid()
def set_start(self, row, col): spot = self.spots[row][col] if spot.is_not_wall(): self.START = spot self.open_set.append(self.START) self.spots_list[row * DIV + col] = arcade.create_rectangle_filled( spot.x * G_W + G_W / 2, spot.y * G_H + G_H / 2, G_W, G_H, arcade.color.BITTER_LEMON) self.__recalculate_grid() return self.START else: return None
def create_scoreboard_overlay(self, colour): """ Create a coloured rectangle with transparency. Return an object that can be rendered to the screen efficiently. """ scoreboard_overlay = arcade.create_rectangle_filled( settings.WINDOW_WIDTH / 2, (settings.WINDOW_HEIGHT - settings.CELL * 4) + settings.CELL / 2, settings.WINDOW_WIDTH - (settings.CELL * 1.75), settings.CELL * 5.125, self.get_overlay_values(colour, 50)) return scoreboard_overlay
def draw_cursor(self, center_x: float, center_y: float, color: Tuple[int, int, int, int]) -> None: self.cursor_sprites.remove(self.cursor) self.cursor = arcade.create_rectangle_filled( center_x=center_x, center_y=center_y, width=1, height=self.text_sprites[self.cursor_idx].height, color=color) self.cursor_sprites.append(self.cursor)
def create_game_board(self, colour): """ Create a coloured rectangle to represent the game board. Return an object that can be rendered to the screen efficiently. """ game_board = arcade.create_rectangle_filled( settings.WINDOW_WIDTH / 2, ((settings.WINDOW_HEIGHT / 2) - (settings.CELL * 3)) + settings.CELL / 2, settings.WINDOW_WIDTH - (settings.CELL * 2), settings.WINDOW_HEIGHT - (settings.CELL * 7), colour) return game_board
def active(self, value: bool) -> None: if not value: self.cursor_sprites.remove(self.cursor) self.cursor = arcade.create_rectangle_filled( *self.cursor_pos, width=1, height=self.text_sprites[0].height, color=self.box_color) self.cursor_sprites.append(self.cursor) self._active = value
def random(self): x = random.randint(0, SW) y = random.randint(0, SH) rotation = random.choice(["horizontal", "vertical"]) height, width = random.randint(10, 50), random.randint(10, 50) if rotation == "horizontal": self.edge = np.array([x, y - height]) elif rotation == "vertical": self.edge = (x - width / 2, y) self.edge = [x, y - height] return self.edge, arcade.create_rectangle_filled( x, y, width, height, arcade.color.BLUE)
def create_scoreboard_backing(self, colour): """ Create a coloured rectangle for the scoreboard backing. Return an object that can be rendered to the screen efficiently. """ scoreboard_backing = arcade.create_rectangle_filled( settings.WINDOW_WIDTH / 2, (settings.WINDOW_HEIGHT - settings.CELL * 4) + settings.CELL / 2, settings.WINDOW_WIDTH - (settings.CELL * 1.875), settings.CELL * 5.125, colour) return scoreboard_backing
def scene4_render(self): self.draw_list = arcade.ShapeElementList() self.draw_list.append( arcade.create_rectangle_filled(400, 400, 600, 600, colors["db"], 0)) self.draw_list.append( arcade.create_line(200, 100, 200, 700, arcade.color.DARK_BLUE, 4)) self.draw_list.append( arcade.create_rectangle_outline( menu_slots[self.station_cursor]["x"], menu_slots[self.station_cursor]["y"], 140, 140, arcade.color.DARK_BLUE, 3))
def create_shapes(win_width, win_height): shape_list = [] win_width = win_width / 4 rectangle = arcade.create_rectangle_filled(win_width, 350, 100, 200, arcade.color.BABY_PINK) circle = arcade.create_ellipse(win_width * 3, 350, 50, 50, arcade.color.PUCE_RED) line = arcade.create_line(win_width, 650, win_width * 3, 75, arcade.color.CANARY_YELLOW) shape_list.append(rectangle) shape_list.append(circle) shape_list.append(line) return shape_list