Example #1
0
def draw_texture_rectangle(center_x: float,
                           center_y: float,
                           width: float,
                           height: float,
                           texture: Texture,
                           angle: float = 0,
                           alpha: int = 255,
                           repeat_count_x: int = 1,
                           repeat_count_y: int = 1):
    """
    Draw a textured rectangle on-screen.

    :param float center_x: x coordinate of rectangle center.
    :param float center_y: y coordinate of rectangle center.
    :param float width: width of the rectangle.
    :param float height: height of the rectangle.
    :param int texture: identifier of texture returned from load_texture() call
    :param float angle: rotation of the rectangle. Defaults to zero.
    :param float alpha: Transparency of image. 0 is fully transparent, 255 (default) is visible
    :param int repeat_count_x: Unused for now
    :param int repeat_count_y: Unused for now
    """

    texture.draw(center_x, center_y, width, height, angle, alpha, False,
                 repeat_count_x, repeat_count_y)
Example #2
0
def draw_lrwh_rectangle_textured(bottom_left_x: float,
                                 bottom_left_y: float,
                                 width: float,
                                 height: float,
                                 texture: Texture,
                                 angle: float = 0,
                                 alpha: int = 255):
    """
    Draw a texture extending from bottom left to top right.

    :param float bottom_left_x: The x coordinate of the left edge of the rectangle.
    :param float bottom_left_y: The y coordinate of the bottom of the rectangle.
    :param float width: The width of the rectangle.
    :param float height: The height of the rectangle.
    :param int texture: identifier of texture returned from load_texture() call
    :param float angle: rotation of the rectangle. Defaults to zero.
    :param int alpha: Transparency of image. 0 is fully transparent, 255 (default) is visible
    """

    center_x = bottom_left_x + (width / 2)
    center_y = bottom_left_y + (height / 2)
    texture.draw_sized(center_x,
                       center_y,
                       width,
                       height,
                       angle=angle,
                       alpha=alpha)
Example #3
0
    def _render_toggle(self, right: bool, color, bg_color) -> Texture:
        height = self._height
        width = self._height * 2

        border_radius = height // 2
        radius = height * 0.42
        padding = radius * 0.16
        pos_y = height // 2
        pos_x = width - radius - padding if right else radius + padding

        # Scale to look pretty
        SCALE = 2
        width *= SCALE
        height *= SCALE
        border_radius *= SCALE
        radius *= SCALE
        padding *= SCALE
        pos_x *= SCALE
        pos_y *= SCALE

        # False
        switch = UIToggle._round_rectangle((width, height), border_radius,
                                           bg_color)
        d = ImageDraw.Draw(switch)
        d.ellipse(
            (pos_x - radius, pos_y - radius, pos_x + radius, pos_y + radius),
            fill=color)
        switch = switch.resize((switch.width // SCALE, switch.height // SCALE),
                               resample=Image.LANCZOS)
        return Texture(name=str(uuid4()), image=switch)
Example #4
0
def make_hexagon_texture(diameter: int,
                         color: Color,
                         points: list,
                         color_outline="#918585",
                         width_outline=5) -> Texture:
    resize = 4  # resize hack for pillow to antialias image
    bg_color = (0, 0, 0, 0)  # fully transparent

    img = PIL.Image.new("RGBA", (diameter * 2 * resize, diameter * 2 * resize),
                        bg_color)
    draw = PIL.ImageDraw.Draw(img)
    # shift to center and resize
    points = [(resize * (pair[0] + diameter), resize * (pair[1] + diameter))
              for pair in points]

    draw.polygon(xy=points, fill=color)

    draw.line(points + list(points[0]),
              fill=color_outline,
              width=width_outline)
    img = img.resize((diameter * 2, diameter * 2),
                     resample=PIL.Image.ANTIALIAS)
    name = "{}:{}:{}".format("hexagon_texture", diameter,
                             color)  # name must be unique for caching
    return Texture(name, img)
Example #5
0
    def __init__(self, width, height, color):
        super().__init__()

        image = PIL.Image.new('RGBA', (width, height), color)
        self.texture = Texture(f"Solid-{color[0]}-{color[1]}-{color[2]}",
                               image)
        self._points = self.texture.hit_box_points
Example #6
0
 def _get_texture(self) -> Texture:
     img = Image.new('RGBA', (150, 150), color=(0, 0, 0, 0))
     d = ImageDraw.Draw(img)
     fnt = ImageFont.truetype(
         "arial.ttf" if os.name == 'nt' else "Arial.ttf", 70)
     d.text((10, 10), self._text, fill=(0, 0, 0, 255), font=fnt)
     return Texture(name="Answer{%s}" % self._text, image=img)
Example #7
0
 def _update_hit_box(self):
     color = self.mat_color
     image = PIL.Image.new('RGBA', (self.width, self.height), color)
     self.texture = Texture(f"Solid-{color[0]}-{color[1]}-{color[2]}",
                            image)
     self._points = self.texture.hit_box_points
     self._hit_box_shape = None
Example #8
0
def create_rectangle_outline(width, height, color, opacity, line):
    img = PIL.Image.new("RGBA", (width, height), (0, 0, 0, 0))
    draw = PIL.ImageDraw.Draw(img)
    draw.rectangle(((0, 0), (width, height)),
                   outline=(*color, opacity),
                   width=line)
    name = f"outlinedsquare:{width}x{height}:{color}"
    return Texture(name, img)
Example #9
0
def draw_scaled_texture_rectangle(center_x: float, center_y: float,
                                  texture: Texture,
                                  scale: float = 1.0,
                                  angle: float = 0,
                                  alpha: int = 255):
    """
    Draw a textured rectangle on-screen.

    :param float center_x: x coordinate of rectangle center.
    :param float center_y: y coordinate of rectangle center.
    :param int texture: identifier of texture returned from load_texture() call
    :param float scale: scale of texture
    :param float angle: rotation of the rectangle. Defaults to zero.
    :param float alpha: Transparency of image. 0 is fully transparent, 255 (default) is visible
    """

    texture.draw_scaled(center_x, center_y, scale, angle, alpha)
Example #10
0
    def render_with_text(self, text: str):
        font_size = self.style_attr('font_size', 22)
        font_color = self.style_attr('font_color', arcade.color.GRAY)
        font_color_hover = self.style_attr('font_color_hover',
                                           arcade.color.GRAY)
        font_color_press = self.style_attr('font_color_press',
                                           arcade.color.GRAY)

        if not font_color_hover:
            font_color_hover = font_color
        if not font_color_press:
            font_color_press = font_color_hover

        normal_image = utils.get_image_with_text(
            text,
            background_image=self._normal_texture.image,
            font_color=font_color,
            font_size=font_size,
            align='center',
            valign='middle')
        self.normal_texture = Texture(str(uuid4()), image=normal_image)

        if self._hover_texture:
            hover_image = utils.get_image_with_text(
                text,
                background_image=self._hover_texture.image,
                font_color=font_color_hover,
                font_size=font_size,
                align='center',
                valign='middle')
            self.hover_texture = Texture(str(uuid4()), image=hover_image)

        if self._press_texture:
            press_image = utils.get_image_with_text(
                text,
                background_image=self._press_texture.image,
                font_color=font_color_press,
                font_size=font_size,
                align='center',
                valign='middle')
            self.press_texture = Texture(str(uuid4()), image=press_image)
Example #11
0
    def __init__(self, width:int, height:int, color):
        """
        Create a solid-color rectangular sprite.

        :param int width: Width of the sprite
        :param int height: Height of the sprite
        :param Color color: Color of the sprite
        """
        super().__init__()

        image = PIL.Image.new('RGBA', (width, height), color)
        self.texture = Texture(f"Solid-{color[0]}-{color[1]}-{color[2]}", image)
        self._points = self.texture.hit_box_points
def make_texture(width: int, height: int, color: Color) -> Texture:
    """
    Return a :class:`Texture` of a square with the given diameter and color,
    fading out at its edges.

    :param int size: Diameter of the square and dimensions of the square
    Texture returned.
    :param Color color: Color of the square.
    :param int center_alpha: Alpha value of the square at its center.
    :param int outer_alpha: Alpha value of the square at its edges.

    :returns: New :class:`Texture` object.
    """
    img = PIL.Image.new("RGBA", (width, height), color)
    name = "{}:{}:{}:{}".format("texture_rect", width, height, color)
    return Texture(name, img)
Example #13
0
 def return_original_color(self):
     image = PIL.Image.new('RGBA', (constants.SPACE_WIDTH, constants.SPACE_HEIGHT), self.permanent_color)
     self.texture = Texture(f"Solid-{self.permanent_color[0]}-{self.permanent_color[1]}-{self.permanent_color[2]}"
                            , image)
Example #14
0
 def set_temp_color(self, color):
     image = PIL.Image.new('RGBA', (constants.SPACE_WIDTH, constants.SPACE_HEIGHT), color)
     self.texture = Texture(f"Solid-{color[0]}-{color[1]}-{color[2]}", image)
Example #15
0
    def __init__(self, width, height, color):
        super().__init__()

        image = PIL.Image.new('RGBA', (width, height), color)
        self.texture = Texture("Solid", image)
        self._points = self.texture.unscaled_hitbox_points