コード例 #1
0
    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))
コード例 #2
0
    def __init__(self, width, height, title):
        """ Initializer """

        # Call the parent class initializer
        super().__init__(width, height, title)

        # 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)

        # Variables that will hold sprite lists
        self.player_list = None
        self.star_sprite_list = None
        self.enemy_sprite_list = None
        self.bullet_sprite_list = None

        # Set up the player info
        self.player_sprite = None

        # Track the current state of what key is pressed
        self.left_pressed = False
        self.right_pressed = False
        self.up_pressed = False
        self.down_pressed = False

        self.view_bottom = 0
        self.view_left = 0

        # Set the background color
        arcade.set_background_color(arcade.color.BLACK)

        # --- Bloom related ---

        # Frame to receive the glow, and color attachment to store each pixel's
        # color data
        self.bloom_color_attachment = self.ctx.texture(
            (SCREEN_WIDTH, SCREEN_HEIGHT))
        self.bloom_screen = self.ctx.framebuffer(
            color_attachments=[self.bloom_color_attachment])

        # Down-sampling helps improve the blur.
        # Note: Any item with a size less than the down-sampling size may get missed in
        # the blur process. Down-sampling by 8 and having an item of 4x4 size, the item
        # will get missed 50% of the time in the x direction, and 50% of the time in the
        # y direction for a total of being missed 75% of the time.
        down_sampling = 4
        # Size of the screen we are glowing onto
        size = (SCREEN_WIDTH // down_sampling, SCREEN_HEIGHT // down_sampling)
        # Gaussian blur parameters.
        # To preview different values, see:
        # https://observablehq.com/@jobleonard/gaussian-kernel-calculater
        kernel_size = 21
        sigma = 4
        mu = 0
        step = 1
        # Control the intensity
        multiplier = 2

        # Create a post-processor to create a bloom
        self.bloom_postprocessing = postprocessing.BloomEffect(
            size, kernel_size, sigma, mu, multiplier, step)
    def __init__(self, width, height, title):
        """ Initializer """

        # Call the parent class initializer
        super().__init__(width, height, title)

        # 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)

        # Variables that will hold sprite lists
        self.player_list = None
        self.star_sprite_list = None
        self.enemy_sprite_list = None
        self.bullet_sprite_list = None

        # Set up the player info
        self.player_sprite = None

        # Track the current state of what key is pressed
        self.left_pressed = False
        self.right_pressed = False
        self.up_pressed = False
        self.down_pressed = False

        self.view_bottom = 0
        self.view_left = 0

        # Set the background color
        arcade.set_background_color(arcade.color.BLACK)

        # --- Bloom related ---

        # Make stars glow dimly
        self.slight_bloom_color_attachment = self.ctx.texture(
            (SCREEN_WIDTH, SCREEN_HEIGHT))
        self.slight_bloom_screen = self.ctx.framebuffer(
            color_attachments=[self.slight_bloom_color_attachment])

        # --- Bloom Related ---
        # Down-sampling helps improve the blur.
        # Note: Any item with a size less than the down-sampling size may get missed in
        # the blur process. Down-sampling by 8 and having an item of 4x4 size, the item
        # will get missed 50% of the time in the x direction, and 50% of the time in the
        # y direction for a total of being missed 75% of the time.
        DOWN_SAMPLING = 4

        size = (SCREEN_WIDTH // DOWN_SAMPLING, SCREEN_HEIGHT // DOWN_SAMPLING)
        kernel_size = 21
        sigma = 4
        mu = 0
        multiplier = 1.5
        step = 1
        self.slight_bloom = postprocessing.BloomEffect(size, kernel_size,
                                                       sigma, mu, multiplier,
                                                       step)

        # Make lasers and particles glow bright
        self.intense_bloom_color_attachment = self.ctx.texture(
            (SCREEN_WIDTH, SCREEN_HEIGHT))
        self.intense_bloom_screen = self.ctx.framebuffer(
            color_attachments=[self.intense_bloom_color_attachment])

        size = (SCREEN_WIDTH // DOWN_SAMPLING, SCREEN_HEIGHT // DOWN_SAMPLING)
        kernel_size = 21
        sigma = 4
        mu = 0
        multiplier = 5
        step = 1
        self.intense_bloom = postprocessing.BloomEffect(
            size, kernel_size, sigma, mu, multiplier, step)