def draw_plane_holes(self, plane): self.hole_list = None self.hole_list = arcade.ShapeElementList() if self.box.dimensions < 3: for hole in plane.holes: (point, radius) = hole pnormal = numpy.array( [plane.unitnormal[1], -plane.unitnormal[0]]) start = point - (radius * pnormal) end = point + (radius * pnormal) line = arcade.create_line(*start, *end, arcade.color.GO_GREEN, 4) self.hole_list.append(line) else: for hole in plane.holes: (point, radius) = hole shape = FlatD3Shape() shape.regular_polygon_vertices(360) shape.rotate(plane.unitnormal) shape.scale(radius) shape.move(point) points = [v[:2] for v in shape.vertices] polygon = arcade.create_polygon(points, arcade.color.GO_GREEN) if plane.reflect: pass self.hole_list.append(polygon)
def main (): arcade.open_window(800, 800, "Hey We Have a Window") arcade.set_background_color(arcade.color.ALMOND) # now create objects main_house = arcade.create_rectangle(400, 200, 400, 400, arcade.color.ANTIQUE_BRASS) door = arcade.create_rectangle(400, 75, 100, 150, arcade.color.ARMY_GREEN) window1 = arcade.create_ellipse(300, 300, 50, 50, arcade.color.BABY_BLUE) window2 = arcade.create_ellipse(500, 300, 50, 50, arcade.color.BABY_BLUE) roof_points = [(200, 400), (400, 600), (600, 400)] roof = arcade.create_polygon(roof_points, arcade.color.DARK_GRAY) line = arcade.create_line(175, 725, 550, 725, arcade.color.FALU_RED) # now we will begin to draw arcade.start_render() # draw everything here arcade.draw_text("Boy that was an ugly house", 200, 750, arcade.color.ALABAMA_CRIMSON, 22) main_house.draw() door.draw() window1.draw() window2.draw() roof.draw() line.draw() arcade.finish_render() arcade.run()
def main(): arcade.open_window(800, 800, "first window example") arcade.set_background_color(arcade.color.ALMOND) #now create objects main_house = arcade.create_rectangle(400, 200, 400, 400, arcade.color.ANTIQUE_BRASS) door = arcade.create_rectangle(400, 75, 100, 150, arcade.color.ARMY_GREEN) window_1 = arcade.create_ellipse(300, 300, 50, 50, arcade.color.AERO_BLUE) window_2 = arcade.create_ellipse(500, 300, 50, 50, arcade.color.AERO_BLUE) roof_points = [(200, 400), (400, 600), (600, 400)] roof = arcade.create_polygon(roof_points, arcade.color.DARK_GRAY) line = arcade.create_line(200, 730, 510, 730, arcade.color.ROSE) #now we will begin to draw arcade.start_render() #draw everything here arcade.draw_text("boy is that an ugly house", 200, 750, arcade.color.ALABAMA_CRIMSON, 22) main_house.draw() door.draw() window_1.draw() window_2.draw() roof.draw() line.draw() arcade.finish_render() arcade.run()
def __init__(self, width, height, title): super().__init__(width, height, title) self.center_window() # A batch ami egy ShapeElementList objektum self.batch = arcade.ShapeElementList() # Ellipses - Ellipszisek ellipse1 = arcade.create_ellipse_filled(440, 360, 50, 50, arcade.color.ROSE) ellipse2 = arcade.create_ellipse_outline(640, 360, 50, 80, arcade.color.RED) ellipse3 = arcade.create_ellipse_filled_with_colors( 840, 360, 50, 80, arcade.color.RED, arcade.color.BLUE, 45) # Triangle - Háromszög triangle = arcade.create_polygon([[0, 0], [100, 0], [50, 100]], arcade.color.BLUE) # Rectangle - Téglalap rect = arcade.create_rectangle_filled(100, 360, 100, 150, arcade.color.GREEN) # Invisible Rectangle 1 pixel - Láthatalan 1 pixel átmérőjű négyzet invisible_rect = arcade.create_rectangle_filled( 0, 0, 1, 1, arcade.color.BLACK) # Itt adjuk hozzá a batch-oz a geometriai alakzatokat self.batch.append(ellipse1) self.batch.append(ellipse2) self.batch.append(ellipse3) self.batch.append(triangle) self.batch.append(rect) # Ezt mindig utoljára adjuk a batch-hoz, amíg a hibát ki nem javítják az Arcade fejlesztői. self.batch.append(invisible_rect)
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 create_cell_poly(self): coord = self.bound_coords if self.highlight is None: cell_color = EVEN_GRID_COLOR if self.pos[2] else ODD_GRID_COLOR elif self.highlight == 'movable': cell_color = MOVABLE_GRID_COLOR elif self.highlight == 'attackable': cell_color = ATTACKABLE_GRID_COLOR else: raise ValueError('cell is missing highlight') cell_poly = arcade.create_polygon(coord, cell_color) return cell_poly
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 __init__(self, x, y, angle, vertices): self.graphic_shape = arcade.create_polygon(vertices, arcade.color.WHITE, 1) self.graphic_shape.center_x = x self.graphic_shape.center_y = y self.body = pymunk.Body(body_type=pymunk.Body.STATIC) self.body.position = pymunk.Vec2d(x, y) self.body.angle = math.radians(angle) self.pymunk_shape = pymunk.Poly(self.body, vertices) self.pymunk_shape.friction = 1 self.pymunk_shape.elasticity = 0.9
def __init__(self): super().__init__() for p1, p2 in pairs(mountain_points): bottom_left = (p1[0], GROUND_Y) bottom_right = (p2[0], GROUND_Y) points_list = [ bottom_left, p1, p2, bottom_right, ] # each "segment" of the mountain is a convex polygon. self.append( arcade.create_polygon(points_list, arcade.color.BROWN_NOSE))
def main(): arcade.open_window(700, 700, "Smile Demo") arcade.set_background_color(arcade.color.AFRICAN_VIOLET) face = arcade.create_ellipse(350, 350, 300, 300, arcade.color.ANTIQUE_BRASS) points = [(250, 350), (450, 350), (350, 425)] nose = arcade.create_polygon(points, arcade.color.GRANNY_SMITH_APPLE) eye1 = arcade.create_ellipse(300, 450, 100, 100, arcade.color.BANANA_YELLOW) eye2 = arcade.create_ellipse(500, 450, 100, 100, arcade.color.BANANA_YELLOW) arcade.start_render() face.draw() nose.draw() eye1.draw() eye2.draw() arcade.draw_arc_outline(350, 200, 200, 200, arcade.color.RED_DEVIL, 180, 360, 3) arcade.finish_render() arcade.run()
def main(): arcade.open_window(700, 700, "Smile Demo") arcade.set_background_color(arcade.color.PIGGY_PINK) # create objects here face = arcade.create_ellipse_outline(350, 350, 200, 200, arcade.color.BLACK) eye1 = arcade.create_ellipse(270, 400, 30, 30, arcade.color.BLACK) eye2 = arcade.create_ellipse(420, 400, 30, 30, arcade.color.BLACK) nose_points = [(320, 350), (370, 350), (345, 370)] nose = arcade.create_polygon(nose_points, arcade.color.DARK_PINK) arcade.start_render() # draw stuff here face.draw() eye1.draw() eye2.draw() nose.draw() arcade.draw_arc_outline(350, 350, 200, 125, arcade.color.RADICAL_RED, 180, 360, 3) arcade.finish_render() arcade.run()
def make_skyline(width, skyline_height, skyline_color, gap_chance=0.70, window_chance=0.30, light_on_chance=0.5, window_color=(255, 255, 200), window_margin=3, window_gap=2, cap_chance=0.20): """ Make a skyline """ shape_list = arcade.ShapeElementList() # Add the "base" that we build the buildings on shape = arcade.create_rectangle_filled(width / 2, skyline_height / 2, width, skyline_height, skyline_color) shape_list.append(shape) building_center_x = 0 skyline_point_list = [] color_list = [] while building_center_x < width: # Is there a gap between the buildings? if random.random() < gap_chance: gap_width = random.randrange(10, 50) else: gap_width = 0 # Figure out location and size of building building_width = random.randrange(20, 70) building_height = random.randrange(40, 150) building_center_x += gap_width + (building_width / 2) building_center_y = skyline_height + (building_height / 2) x1 = building_center_x - building_width / 2 x2 = building_center_x + building_width / 2 y1 = skyline_height y2 = skyline_height + building_height skyline_point_list.append([x1, y1]) skyline_point_list.append([x1, y2]) skyline_point_list.append([x2, y2]) skyline_point_list.append([x2, y1]) for i in range(4): color_list.append( [skyline_color[0], skyline_color[1], skyline_color[2]]) if random.random() < cap_chance: x1 = building_center_x - building_width / 2 x2 = building_center_x + building_width / 2 x3 = building_center_x y1 = y2 = building_center_y + building_height / 2 y3 = y1 + building_width / 2 shape = arcade.create_polygon([[x1, y1], [x2, y2], [x3, y3]], skyline_color) shape_list.append(shape) # See if we should have some windows if random.random() < window_chance: # Yes windows! How many windows? window_rows = random.randrange(10, 15) window_columns = random.randrange(1, 7) # Based on that, how big should they be? window_height = (building_height - window_margin * 2) / window_rows window_width = (building_width - window_margin * 2 - window_gap * (window_columns - 1)) / window_columns # Find the bottom left of the building so we can start adding widows building_base_y = building_center_y - building_height / 2 building_left_x = building_center_x - building_width / 2 # Loop through each window for row in range(window_rows): for column in range(window_columns): if random.random() < light_on_chance: x1 = building_left_x + column * ( window_width + window_gap) + window_margin x2 = building_left_x + column * ( window_width + window_gap) + window_width + window_margin y1 = building_base_y + row * window_height y2 = building_base_y + row * window_height + window_height * .8 skyline_point_list.append([x1, y1]) skyline_point_list.append([x1, y2]) skyline_point_list.append([x2, y2]) skyline_point_list.append([x2, y1]) for i in range(4): color_list.append( (window_color[0], window_color[1], window_color[2])) building_center_x += (building_width / 2) shape = arcade.create_rectangles_filled_with_colors( skyline_point_list, color_list) shape_list.append(shape) return shape_list
def __init__(self, width, height, title): """ Set up the application. """ super().__init__(width, height, title, resizable=True) # Set the working directory (where we expect to find files) to the same # directory this .py file is in. You can leave this out of your own # code, but it is needed to easily run the examples using "python -m" # as mentioned at the top of this program. file_path = os.path.dirname(os.path.abspath(__file__)) os.chdir(file_path) self.set_location(20, 20) arcade.set_background_color(arcade.color.BLACK) self.board_shape_element_list = arcade.ShapeElementList() self.left_flipper = arcade.ShapeElementList() self.balls = [] # -- Pymunk -- self.space = pymunk.Space() self.space.gravity = (0.0, -15.0) my_file = open("pinball_layout.txt") line_number = 0 for line in my_file: line_number += 1 try: parameters = line.split() if parameters[0] == "Box": x = float(parameters[1]) y = float(parameters[2]) angle = float(parameters[3]) width = float(parameters[4]) height = float(parameters[5]) my_shape = Box(width, height, x, y, angle=angle) self.board_shape_element_list.append( my_shape.graphic_shape) self.space.add(my_shape.pymunk_shape) if parameters[0] == "Poly": x = float(parameters[1]) y = float(parameters[2]) angle = float(parameters[3]) count = (len(parameters) - 3) // 2 vertices = [] for i in range(count): x = float(parameters[i * 2 + 1]) y = float(parameters[i * 2 + 2]) vertices.append((x, y)) my_shape = Poly(0, 0, 0, vertices) self.board_shape_element_list.append( my_shape.graphic_shape) self.space.add(my_shape.pymunk_shape) print("Poly") except Exception as e: print(f"Error parsing line {line_number}: '{line}'") print(e) return vertices = [(-0.5, -0.5), (3, 0), (-0.5, 0.5)] mass = 10 moment = pymunk.moment_for_poly(mass, vertices) # right flipper self.right_flipper_poly = arcade.create_polygon( vertices, arcade.color.WHITE, 1) self.right_flipper_shape_list = arcade.ShapeElementList() self.right_flipper_shape_list.append(self.right_flipper_poly) self.right_flipper_shape_list.center_x = 2 self.right_flipper_shape_list.center_y = 2 self.right_flipper_body = pymunk.Body(mass, moment) self.right_flipper_body.position = pymunk.Vec2d( self.right_flipper_shape_list.center_x, self.right_flipper_shape_list.center_y) self.right_flipper_pymunk_shape = pymunk.Poly(self.right_flipper_body, vertices) self.space.add(self.right_flipper_body, self.right_flipper_pymunk_shape) r_flipper_joint_body = pymunk.Body(body_type=pymunk.Body.KINEMATIC) r_flipper_joint_body.position = pymunk.Vec2d( self.right_flipper_shape_list.center_x, self.right_flipper_shape_list.center_y) j = pymunk.PinJoint(self.right_flipper_body, r_flipper_joint_body, (0, 0), (5, 5)) #s = pymunk.DampedRotarySpring(self.right_flipper.body, r_flipper_joint_body, 0, 500, 110) #self.space.add(j, s) self.space.add(j, r_flipper_joint_body) print("X1", self.right_flipper_shape_list.center_x, self.right_flipper_shape_list.center_y) print("X2", self.right_flipper_body.position.x, self.right_flipper_body.position.y) """
def create_more_shapes(current_shapes, win_height): poly_points = [(400, win_height - 50), (350, win_height - 100), (450, win_height - 100)] triangle = arcade.create_polygon(poly_points, arcade.color.BLOND) current_shapes.append(triangle)
def create_more_shapes(existing_shapes): list_of_points = [(400, 650), (350, 600), (450, 600)] triangle = arcade.create_polygon(list_of_points, arcade.color.NAPIER_GREEN) existing_shapes.append(triangle)