<commit_before>"""This module contains classes for representing in-game sprites and
animations via the PyGame Surface and Image modules.

It also contains module level methods to assist in loading and managing
in-game images in other modules.
"""
from __builtin__ import True, False
from math import ceil
from pygame.locals import *
from pygame.surface import Surface
from pygame import image
from pygame import transform
from pygame import color
from pygame import Rect


def load_tuple_of_images(filepaths):
    """Load a collection of Surfaces from file and store them in an
    immutable container -- a tuple.

    Args:
        filepaths: A tuple of Strings for the file paths to each image.

    Returns:
        A list of Surfaces, each containing an image loaded from file.
    """
    all_images = []

    for filepath in filepaths:
        new_image = image.load(filepath).convert_alpha()
        all_images.append(new_image)

    return tuple(all_images)


def render_outlined_text(font, text, text_color, outline_color,
                         position):
        """Render a text Graphic with an outline 1-pixel thick.

        Args:
            font: A PyGame Font object used for rendering the text.
            text: A String for the text that will be rendered.
            text_color: A tuple of integers which specify the RGB color
                of the text.
            outline_color: A tuple of integers which specify the RGB
                color  of the outline.
            position: A tuple containing integer coordinates for the
                text's position relative to its parent Surface.

        Returns:
            A Graphic with the desired text outlined.
        """
        text_surf = font.render(text, True, text_color)
        outline = font.render(text, True, outline_color)

        outlined_text = Surface((text_surf.get_width() + 2,
                                 text_surf.get_height() + 2),
                                SRCALPHA)

        outlined_text.blit(outline, (0, 0))
        outlined_text.blit(outline, (0, 2))
        outlined_text.blit(outline, (2, 0))
        outlined_text.blit(outline, (2, 2))
        outlined_text.blit(text_surf, (1, 1))

        text_graphic = Graphic(outlined_text, position)
        return text_graphic


def convert_to_colorkey_alpha(surf, colorkey=color.Color('magenta')):
        """Give the surface a colorkeyed background that will be
        transparent when drawing.
        Colorkey alpha, unlike per-pixel alpha, will allow the
        surface's transparent background to remain while using
        methods such as Surface.set_alpha().

        Keyword arguments:
            surf        The Surface to convert.
            colorkey    The color value for the colorkey. The default
                        is magenta or RGB(255, 0, 255).
                        This should be set to a color that isn't
                        present in the image, otherwise those areas
                        with a matching colour will be drawn
                        transparent as well.
        """
        colorkeyed_surf = Surface(surf.get_size())

        colorkeyed_surf.fill(colorkey)
        colorkeyed_surf.blit(surf, (0, 0))
        colorkeyed_surf.set_colorkey(colorkey)
        colorkeyed_surf.convert()

        return colorkeyed_surf


def calculate_center_position(obj_size, area_size):
    """Return an integer for the position of a graphical object such
    that the object is positioned at the horizontal or vertical center
    of an area.

    To center an object horizontally, pass the widths of the object and
    area. To center an object vertically, pass their heights.

    Args:
        obj_size (int): Either the width or height of the object in
            pixels.
        area_size (int): Either the width or height, in pixels, of the
             area upon which the object will be centered.
    """
    if obj_size < area_size:
        return (area_size - obj_size) \ 2
    else:
        return (obj_size - area_size) \ 2


def get_line_center(thickness):
    """Return an integer representing the center of a line, or a line
    that is part of a rectangle, drawn by the pygame.draw module.

    The x or y coordinate passed to a pygame.draw function is used as<commit_msg>Use the proper int division operator<commit_after>"""This module contains classes for representing in-game sprites and
animations via the PyGame Surface and Image modules.

It also contains module level methods to assist in loading and managing
in-game images in other modules.
"""
from __builtin__ import True, False
from math import ceil
from pygame.locals import *
from pygame.surface import Surface
from pygame import image
from pygame import transform
from pygame import color
from pygame import Rect


def load_tuple_of_images(filepaths):
    """Load a collection of Surfaces from file and store them in an
    immutable container -- a tuple.

    Args:
        filepaths: A tuple of Strings for the file paths to each image.

    Returns:
        A list of Surfaces, each containing an image loaded from file.
    """
    all_images = []

    for filepath in filepaths:
        new_image = image.load(filepath).convert_alpha()
        all_images.append(new_image)

    return tuple(all_images)


def render_outlined_text(font, text, text_color, outline_color,
                         position):
        """Render a text Graphic with an outline 1-pixel thick.

        Args:
            font: A PyGame Font object used for rendering the text.
            text: A String for the text that will be rendered.
            text_color: A tuple of integers which specify the RGB color
                of the text.
            outline_color: A tuple of integers which specify the RGB
                color  of the outline.
            position: A tuple containing integer coordinates for the
                text's position relative to its parent Surface.

        Returns:
            A Graphic with the desired text outlined.
        """
        text_surf = font.render(text, True, text_color)
        outline = font.render(text, True, outline_color)

        outlined_text = Surface((text_surf.get_width() + 2,
                                 text_surf.get_height() + 2),
                                SRCALPHA)

        outlined_text.blit(outline, (0, 0))
        outlined_text.blit(outline, (0, 2))
        outlined_text.blit(outline, (2, 0))
        outlined_text.blit(outline, (2, 2))
        outlined_text.blit(text_surf, (1, 1))

        text_graphic = Graphic(outlined_text, position)
        return text_graphic


def convert_to_colorkey_alpha(surf, colorkey=color.Color('magenta')):
        """Give the surface a colorkeyed background that will be
        transparent when drawing.
        Colorkey alpha, unlike per-pixel alpha, will allow the
        surface's transparent background to remain while using
        methods such as Surface.set_alpha().

        Keyword arguments:
            surf        The Surface to convert.
            colorkey    The color value for the colorkey. The default
                        is magenta or RGB(255, 0, 255).
                        This should be set to a color that isn't
                        present in the image, otherwise those areas
                        with a matching colour will be drawn
                        transparent as well.
        """
        colorkeyed_surf = Surface(surf.get_size())

        colorkeyed_surf.fill(colorkey)
        colorkeyed_surf.blit(surf, (0, 0))
        colorkeyed_surf.set_colorkey(colorkey)
        colorkeyed_surf.convert()

        return colorkeyed_surf


def calculate_center_position(obj_size, area_size):
    """Return an integer for the position of a graphical object such
    that the object is positioned at the horizontal or vertical center
    of an area.

    To center an object horizontally, pass the widths of the object and
    area. To center an object vertically, pass their heights.

    Args:
        obj_size (int): Either the width or height of the object in
            pixels.
        area_size (int): Either the width or height, in pixels, of the
             area upon which the object will be centered.
    """
    if obj_size < area_size:
        return (area_size - obj_size) // 2
    else:
        return (obj_size - area_size) // 2


def get_line_center(thickness):
    """Return an integer representing the center of a line, or a line
    that is part of a rectangle, drawn by the pygame.draw module.

    The x or y coordinate passed to a pygame.draw function is used as
{'fraction_non_alphanumeric': 0.05883036856179514, 'fraction_numerical': 0.0055807464248343215, 'mean_word_length': 2.260803639120546, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3254893', 'n_tokens_mistral': 2346, 'n_tokens_neox': 2227, 'n_words': 926}