Esempio n. 1
0
def setup():
    global toolbar, frames

    arcadeplus.open_window(WIDTH, HEIGHT, "AnimationCreator")
    arcadeplus.set_background_color(arcadeplus.color.WHITE)
    scheduling_update_time = 0.01666666666  # float value is same as 1/60
    arcadeplus.schedule(on_update, scheduling_update_time)

    # Create Vertex Buffer Object (VBO) shape lists
    frames.append(arcadeplus.ShapeElementList())
    toolbar = arcadeplus.ShapeElementList()

    # Override arcade window methods
    window = arcadeplus.get_window()
    window.on_draw = on_draw
    window.on_key_press = on_key_press
    window.on_key_release = on_key_release
    window.on_mouse_press = on_mouse_press
    window.on_mouse_release = on_mouse_release
    window.on_mouse_drag = on_mouse_drag

    # Render toolbar
    render_toolbar_dividers()
    render_toolbar_shapes()
    render_toolbar_colors()
    render_toolbar_icons()
    render_toolbar_text()

    arcadeplus.run()
Esempio n. 2
0
    def setup(self):
        """
        This, and any function with the arcadeplus.decorator.init decorator,
        is run automatically on start-up.
        """

        self.mountains = []

        background = arcadeplus.ShapeElementList()

        points = (0, 0), (SCREEN_WIDTH, 0), (SCREEN_WIDTH,
                                             SCREEN_HEIGHT), (0, SCREEN_HEIGHT)
        colors = (arcadeplus.color.SKY_BLUE, arcadeplus.color.SKY_BLUE,
                  arcadeplus.color.BLUE, arcadeplus.color.BLUE)
        rect = arcadeplus.create_rectangles_filled_with_colors(points, colors)

        background.append(rect)
        self.mountains.append(background)

        for i in range(1, 4):
            color_start = (i * 10, i * 30, i * 10)
            color_end = (i * 20, i * 40, i * 20)
            min_y = 0 + 70 * (3 - i)
            max_y = 120 + 70 * (3 - i)
            mountain_range = create_mountain_range(min_y, max_y, color_start,
                                                   color_end)
            self.mountains.append(mountain_range)
Esempio n. 3
0
    def recreate_grid(self):
        lin = np.linspace(0, 5, ROW_COUNT, endpoint=False)
        y, x = np.meshgrid(lin, lin)
        self.grid = (perlin(x, y, seed=0))

        self.grid *= 255
        self.grid += 128

        # for row in range(ROW_COUNT):
        #     for column in range(COLUMN_COUNT):
        #         print(f"{self.grid[row][column]:5.2f} ", end="")
        #     print()

        self.shape_list = arcadeplus.ShapeElementList()
        for row in range(ROW_COUNT):
            for column in range(COLUMN_COUNT):
                color = self.grid[row][column], 0, 0

                x = (MARGIN + WIDTH) * column + MARGIN + WIDTH // 2
                y = (MARGIN + HEIGHT) * row + MARGIN + HEIGHT // 2

                current_rect = arcadeplus.create_rectangle_filled(
                    x, y, WIDTH, HEIGHT, color)
                self.shape_list.append(current_rect)

        im = Image.fromarray(np.uint8(self.grid), "L")
        im.save("test.png")
Esempio n. 4
0
    def __init__(self, width, height, title):
        """
        Set up the application.
        """
        super().__init__(width, height, title)

        self.shape_list = arcadeplus.ShapeElementList()
        point_list = ((0, 50),
                      (10, 10),
                      (50, 0),
                      (10, -10),
                      (0, -50),
                      (-10, -10),
                      (-50, 0),
                      (-10, 10),
                      (0, 50))
        colors = [
            getattr(arcadeplus.color, color)
            for color in dir(arcadeplus.color)
            if not color.startswith("__")
        ]
        for i in range(200):
            x = SCREEN_WIDTH // 2 - random.randrange(SCREEN_WIDTH)
            y = SCREEN_HEIGHT // 2 - random.randrange(SCREEN_HEIGHT)
            color = random.choice(colors)
            points = [(px + x, py + y) for px, py in point_list]

            my_line_strip = arcadeplus.create_line_strip(points, color, 5)
            self.shape_list.append(my_line_strip)

        self.shape_list.center_x = SCREEN_WIDTH // 2
        self.shape_list.center_y = SCREEN_HEIGHT // 2
        self.shape_list.angle = 0

        arcadeplus.set_background_color(arcadeplus.color.BLACK)
Esempio n. 5
0
    def setup(self):
        """
        This, and any function with the arcadeplus.decorator.init decorator,
        is run automatically on start-up.
        """
        self.mountains = []

        background = arcadeplus.ShapeElementList()

        color1 = (195, 157, 224)
        color2 = (240, 203, 163)
        points = (0, 0), (SCREEN_WIDTH, 0), (SCREEN_WIDTH, SCREEN_HEIGHT), (0, SCREEN_HEIGHT)
        colors = (color1, color1, color2, color2)
        rect = arcadeplus.create_rectangle_filled_with_colors(points, colors)

        background.append(rect)
        self.mountains.append(background)

        layer_4 = create_mountain_range([0, 350], [SCREEN_WIDTH, 320], 1.1, 250, 8, (158, 98, 204))
        self.mountains.append(layer_4)

        layer_3 = create_mountain_range([0, 270], [SCREEN_WIDTH, 190], 1.1, 120, 9, (130, 79, 138))
        self.mountains.append(layer_3)

        layer_2 = create_mountain_range([0, 180], [SCREEN_WIDTH, 80], 1.2, 30, 12, (68, 28, 99))
        self.mountains.append(layer_2)

        layer_1 = create_mountain_range([250, 0], [SCREEN_WIDTH, 200], 1.4, 20, 12, (49, 7, 82))
        self.mountains.append(layer_1)
Esempio n. 6
0
def make_person(head_radius,
                chest_height,
                chest_width,
                leg_width,
                leg_height,
                arm_width,
                arm_length,
                arm_gap,
                shoulder_height):

    shape_list = arcadeplus.ShapeElementList()

    # Head
    shape = arcadeplus.create_ellipse_filled(0, chest_height / 2 + head_radius, head_radius, head_radius,
                                         arcadeplus.color.WHITE)
    shape_list.append(shape)

    # Chest
    shape = arcadeplus.create_rectangle_filled(0, 0, chest_width, chest_height, arcadeplus.color.BLACK)
    shape_list.append(shape)

    # Left leg
    shape = arcadeplus.create_rectangle_filled(-(chest_width / 2) + leg_width / 2, -(chest_height / 2) - leg_height / 2,
                                           leg_width, leg_height, arcadeplus.color.RED)
    shape_list.append(shape)

    # Right leg
    shape = arcadeplus.create_rectangle_filled((chest_width / 2) - leg_width / 2, -(chest_height / 2) - leg_height / 2,
                                           leg_width, leg_height, arcadeplus.color.RED)
    shape_list.append(shape)

    # Left arm
    shape = arcadeplus.create_rectangle_filled(-(chest_width / 2) - arm_width / 2 - arm_gap,
                                           (chest_height / 2) - arm_length / 2 - shoulder_height, arm_width, arm_length,
                                           arcadeplus.color.BLUE)
    shape_list.append(shape)

    # Left shoulder
    shape = arcadeplus.create_rectangle_filled(-(chest_width / 2) - (arm_gap + arm_width) / 2,
                                           (chest_height / 2) - shoulder_height / 2, arm_gap + arm_width,
                                           shoulder_height, arcadeplus.color.BLUE_BELL)
    shape_list.append(shape)

    # Right arm
    shape = arcadeplus.create_rectangle_filled((chest_width / 2) + arm_width / 2 + arm_gap,
                                           (chest_height / 2) - arm_length / 2 - shoulder_height, arm_width, arm_length,
                                           arcadeplus.color.BLUE)
    shape_list.append(shape)

    # Right shoulder
    shape = arcadeplus.create_rectangle_filled((chest_width / 2) + (arm_gap + arm_width) / 2,
                                           (chest_height / 2) - shoulder_height / 2, arm_gap + arm_width,
                                           shoulder_height, arcadeplus.color.BLUE_BELL)
    shape_list.append(shape)

    return shape_list
Esempio n. 7
0
 def setup(self):
     # --- Create the vertex buffers objects for each square before we do
     # any drawing.
     self.shape_list = arcadeplus.ShapeElementList()
     for x in range(0, SCREEN_WIDTH, SQUARE_SPACING):
         for y in range(0, SCREEN_HEIGHT, SQUARE_SPACING):
             shape = arcadeplus.create_rectangle_filled(
                 x, y, SQUARE_WIDTH, SQUARE_HEIGHT,
                 arcadeplus.color.DARK_BLUE)
             self.shape_list.append(shape)
Esempio n. 8
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 = arcadeplus.create_rectangle_filled(self.x, self.y, self.width,
                                                   self.height, self.color,
                                                   self.angle)
        self.shape_list = arcadeplus.ShapeElementList()
        self.shape_list.append(shape)
Esempio n. 9
0
def create_mountain_range(start, end, roughness, vertical_displacement, num_of_iterations, color_start):

    shape_list = arcadeplus.ShapeElementList()

    layer_1 = midpoint_displacement(start, end, roughness, vertical_displacement, num_of_iterations)
    layer_1 = fix_points(layer_1)

    color_list = [color_start] * len(layer_1)
    lines = arcadeplus.create_rectangles_filled_with_colors(layer_1, color_list)
    shape_list.append(lines)

    return shape_list
Esempio n. 10
0
    def __init__(self, width, height, title):
        """
        Set up the application.
        """

        super().__init__(width, height, title)

        arcadeplus.set_background_color(arcadeplus.color.BLACK)

        self.shapes = arcadeplus.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 = arcadeplus.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 = arcadeplus.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 = arcadeplus.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 = arcadeplus.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)
        shape = arcadeplus.create_ellipse_filled_with_colors(SCREEN_WIDTH // 2, 350, 50, 50,
                                                         inside_color=color1, outside_color=color2)
        self.shapes.append(shape)
Esempio n. 11
0
def create_line_strip():
    shape_list = arcadeplus.ShapeElementList()

    colors = (arcadeplus.color.RED, arcadeplus.color.BLACK,
              arcadeplus.color.GREEN, arcadeplus.color.BLACK,
              arcadeplus.color.BLUE, arcadeplus.color.BLACK)
    line_strip = arcadeplus.create_lines_with_colors(
        ([10, 10], [500, 10], [10, 250], [500, 250], [10, 500], [500, 500]),
        colors,
        line_width=4)

    shape_list.append(line_strip)

    return shape_list
Esempio n. 12
0
    def recreate_grid(self):
        self.shape_list = arcadeplus.ShapeElementList()
        for row in range(ROW_COUNT):
            for column in range(COLUMN_COUNT):
                if self.grid[row][column] == 0:
                    color = arcadeplus.color.WHITE
                else:
                    color = arcadeplus.color.GREEN

                x = (MARGIN + WIDTH) * column + MARGIN + WIDTH // 2
                y = (MARGIN + HEIGHT) * row + MARGIN + HEIGHT // 2

                current_rect = arcadeplus.create_rectangle_filled(
                    x, y, WIDTH, HEIGHT, color)
                self.shape_list.append(current_rect)
Esempio n. 13
0
def make_star_field(star_count):
    """ Make a bunch of circles for stars. """

    shape_list = arcadeplus.ShapeElementList()

    for star_no in range(star_count):
        x = random.randrange(SCREEN_WIDTH)
        y = random.randrange(SCREEN_HEIGHT)
        radius = random.randrange(1, 4)
        brightness = random.randrange(127, 256)
        color = (brightness, brightness, brightness)
        shape = arcadeplus.create_rectangle_filled(x, y, radius, radius, color)
        shape_list.append(shape)

    return shape_list
Esempio n. 14
0
def make_shape():

    shape_list = arcadeplus.ShapeElementList()

    # Shape center around which we will rotate
    center_x = 20
    center_y = 30

    width = 30
    height = 40

    shape = arcadeplus.create_ellipse_filled(center_x, center_y, width, height,
                                             arcadeplus.color.WHITE)
    shape_list.append(shape)

    return shape_list
Esempio n. 15
0
def create_mountain_range(height_min, height_max, color_start, color_end):

    shape_list = arcadeplus.ShapeElementList()

    step_max = 1.5
    step_change = 0.5

    height = random.random() * height_max
    slope = (random.random() * step_max * 2) - step_max

    line_point_list = []
    line_color_list = []

    for x in range(SCREEN_WIDTH):
        height += slope
        slope += (random.random() * step_change * 2) - step_change

        if slope > step_max:
            slope = step_max
        elif slope < -step_max:
            slope = -step_max

        if height > height_max:
            height = height_max
            slope *= -1
        elif height < height_min:
            height = height_min
            slope *= -1

        line_point_list.extend(((x, height), (x, 0)))
        line_color_list.extend((color_start, color_end))

    lines = arcadeplus.create_lines_with_colors(line_point_list,
                                                line_color_list)
    shape_list.append(lines)

    return shape_list
Esempio n. 16
0
    def setup(self):
        self.shape_list = arcadeplus.ShapeElementList()

        # --- Create all the rectangles

        # We need a list of all the points and colors
        point_list = []
        color_list = []

        # Now calculate all the points
        for x in range(0, SCREEN_WIDTH, SQUARE_SPACING):
            for y in range(0, SCREEN_HEIGHT, SQUARE_SPACING):

                # Calculate where the four points of the rectangle will be if
                # x and y are the center
                top_left = (x - HALF_SQUARE_WIDTH, y + HALF_SQUARE_HEIGHT)
                top_right = (x + HALF_SQUARE_WIDTH, y + HALF_SQUARE_HEIGHT)
                bottom_right = (x + HALF_SQUARE_WIDTH, y - HALF_SQUARE_HEIGHT)
                bottom_left = (x - HALF_SQUARE_WIDTH, y - HALF_SQUARE_HEIGHT)

                # Add the points to the points list.
                # ORDER MATTERS!
                # Rotate around the rectangle, don't append points caty-corner
                point_list.append(top_left)
                point_list.append(top_right)
                point_list.append(bottom_right)
                point_list.append(bottom_left)

                # Add a color for each point. Can be different colors if you want
                # gradients.
                for i in range(4):
                    color_list.append(arcadeplus.color.DARK_BLUE)

        shape = arcadeplus.create_rectangles_filled_with_colors(
            point_list, color_list)
        self.shape_list.append(shape)
Esempio n. 17
0
def on_mouse_press(x, y, button, modifiers):
    global frames, current_frame, linked_scenes, captured
    global chosen_color_column, chosen_shape_column, chosen_color_row, chosen_shape_row
    global start_x, start_y, end_x, end_y
    global snd_btn_press

    # Determine what to do based on the location of the user's click
    if 100 < x < 900:
        start_x = x
        start_y = y
        captured[current_frame - 1] = False
    elif x <= 50:
        if 450 <= y <= 750:
            arcadeplus.play_sound(snd_btn_press)
            chosen_shape_row = y // 50 + 1
            chosen_shape_column = 1
        elif y <= 450:
            arcadeplus.play_sound(snd_btn_press)
            chosen_color_row = y // 50 + 1
            chosen_color_column = 1
    elif x <= 100:
        if 450 <= y <= 750:
            arcadeplus.play_sound(snd_btn_press)
            chosen_shape_row = y // 50 + 1
            chosen_shape_column = 2
        elif y <= 450:
            arcadeplus.play_sound(snd_btn_press)
            chosen_color_row = y // 50 + 1
            chosen_color_column = 2
    elif x >= 950:
        if 450 < y < 500:
            gui.theme('Dark Blue 3')
            layout = [[gui.Text("Scenes:")],
                      [gui.Listbox(values=list(list_scenes()), size=(30, 6))],
                      [gui.Text("New Scene Name:"),
                       gui.InputText()],
                      [gui.Button('Create New Scene'),
                       gui.Button('Cancel')]]
            window = gui.Window('AnimationCreator', layout)
            while True:
                event, values = window.read()
                if event in (None, 'Cancel'):
                    break
                if str(values[1]).strip() != "":
                    image = arcadeplus.get_image(100, 0, 800, 800)
                    image.save(f"data/scenes/{str(values[1]).strip()}.png",
                               "PNG")
                    linked_scenes[current_frame - 1] = str(values[1]).strip()
                    frames[current_frame - 1] = arcadeplus.ShapeElementList()
                    print('New Scene Created From Current Frame:',
                          str(values[1]).strip())
                    break
            window.close()
        elif 500 < y < 550:
            arcadeplus.play_sound(snd_btn_press)
            frames.append(arcadeplus.ShapeElementList())
            current_frame = len(frames)
            print("New Frame Created")
            captured.append(False)
        elif 550 < y < 600:
            arcadeplus.play_sound(snd_btn_press)
            frames[current_frame - 1] = arcadeplus.ShapeElementList()
            if (current_frame - 1) in linked_scenes:
                del linked_scenes[current_frame - 1]
            print("Current Frame Cleared")
            captured[current_frame - 1] = False
        elif 600 < y < 650:
            arcadeplus.play_sound(snd_btn_press)
            if current_frame < len(frames):
                current_frame += 1
                print("Forward Frame")
            else:
                print("Cannot Forward Frame - Reached End of Timeline")
    elif x >= 900:
        if 450 < y < 500:
            gui.theme('Dark Blue 3')
            layout = [[gui.Text("Scenes:")],
                      [gui.Listbox(values=list(list_scenes()), size=(30, 6))],
                      [gui.Button('Load Scene'),
                       gui.Button('Cancel')]]
            window = gui.Window('AnimationCreator', layout)
            while True:
                event, values = window.read()
                if event in (None, 'Cancel'):
                    break
                if str(values[0])[2:-2] != "":
                    linked_scenes[current_frame - 1] = str(values[0])[2:-2]
                    frames[current_frame - 1] = arcadeplus.ShapeElementList()
                    print('Loaded Scene:', str(values[0])[2:-2])
                    break
            window.close()
            captured[current_frame - 1] = False
        elif 500 < y < 550:
            arcadeplus.play_sound(snd_btn_press)
            if len(frames) > 1:
                del frames[current_frame - 1]
                if str(current_frame - 1) in linked_scenes.keys():
                    del linked_scenes[current_frame - 1]
                print("Deleted Current Frame")
                captured[current_frame - 1] = False
                for i in range(current_frame - 1, len(captured)):
                    captured[i] = False
                if current_frame > 1:
                    current_frame -= 1
                else:
                    current_frame = 1
            else:
                print("Cannot Delete Frame - At Least One Frame Must Exist")
        elif 550 < y < 600:
            arcadeplus.play_sound(snd_btn_press)
            try:
                frames[current_frame - 1].remove(frames[current_frame - 1][-1])
                print("Last Drawing on Current Frame Undone")
                captured[current_frame - 1] = False
            except:
                print("Cannot Undo Last Drawing on Frame - No Moves to Undo")
                pass
        elif 600 < y < 650:
            arcadeplus.play_sound(snd_btn_press)
            if current_frame > 1:
                current_frame -= 1
                print("Backward Frame")
            else:
                print("Cannot Backward Frame - Reached Beginning of Timeline")

    # Capture functionality
    if x > 900 and y > 750:
        arcadeplus.play_sound(snd_btn_press)
        image = arcadeplus.get_image(100, 0, 800, 800)
        current_frame_name = (10 - len(str(current_frame))) * "0" + str(
            current_frame)
        image.save(f"data/frames/{current_frame_name}.png", "PNG")
        print("Captured Frame")
        captured[current_frame - 1] = True

    # Render functionality
    if x < 100 and y > 750:
        if all(captured):
            gui.theme('Dark Blue 3')
            layout = [[
                gui.Text("Frames per Image (positive integer): "),
                gui.InputText("20")
            ], [gui.Button('Start Render'),
                gui.Button('Cancel')]]
            window = gui.Window('AnimationCreator', layout)
            while True:
                event, values = window.read()
                if event in (None, 'Cancel'):
                    break
                if event in (None, 'Start Render'):
                    if str(values[0]) != "" and str(values[0]).isdigit():
                        print(
                            f"Rendering at {int(values[0])} frames per image..."
                        )
                        render_video.run(int(values[0]), len(captured))
                    else:
                        print(f"Rendering at 20 frames per image...")
                        render_video.run(20, len(captured))
                    print("Render Complete")
                    break
            window.close()
        else:
            gui.theme('Dark Blue 3')
            layout = [[gui.Text("Please Capture All Frames Before Rendering")],
                      [gui.Button('Okay')]]
            window = gui.Window('AnimationCreator', layout)
            while True:
                event, values = window.read()
                if event in (None, 'Okay'):
                    break
            window.close()

    # About button functionality
    if x > 900 and y < 50:
        gui.theme('Dark Blue 3')
        layout = [
            [gui.Text("AnimationCreator was created by George Shao")],
            [
                gui.Text(
                    "Find out more at: https://github.com/GeorgeShao/AnimationCreator"
                )
            ], [gui.Button('Okay')]
        ]
        window = gui.Window('AnimationCreator', layout)
        while True:
            event, values = window.read()
            if event in (None, 'Okay'):
                break
        window.close()
Esempio n. 18
0
    def __init__(self, width, height, title):
        """
        Set up the application.
        """
        super().__init__(width, height, title)

        self.shape_list = arcadeplus.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(arcadeplus.color, color)
            for color in dir(arcadeplus.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 = arcadeplus.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 = arcadeplus.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 = arcadeplus.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 = arcadeplus.create_polygon(point_list, (255, 10, 10))
        self.shape_list.append(poly)

        ellipse = arcadeplus.create_ellipse(20, 30, 50, 20, (230, 230, 0))
        self.shape_list.append(ellipse)

        arcadeplus.set_background_color(arcadeplus.color.BLACK)
Esempio n. 19
0
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 = arcadeplus.ShapeElementList()

    # Add the "base" that we build the buildings on
    shape = arcadeplus.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 = arcadeplus.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 = arcadeplus.create_rectangles_filled_with_colors(
        skyline_point_list, color_list)
    shape_list.append(shape)

    return shape_list