Beispiel #1
0
 def draw(self, pil_draw: ImageDraw, **kwargs) -> None:
     """
     :arg
         pil_draw: PIL Draw object
     """
     pil_draw.rectangle([self.x_min, self.y_min, self.x_max, self.y_max],
                        **kwargs)
Beispiel #2
0
def draw_cell(square: Square, draw: ImageDraw, color: tuple):
    border = (
        square.top_left_x,
        square.top_left_y,
        square.top_left_x + square.size,
        square.top_left_y + square.size)
    draw.rectangle(border, color)
Beispiel #3
0
    def draw(self, draw: ImageDraw):
        pen, brush = self._get_pen_brush()

        if hasattr(self, 'de') and self.de > 0:
            brush_s1 = aggdraw.Brush(fade_color(self.fill, self.shade))
            brush_s2 = aggdraw.Brush(fade_color(self.fill, 2 * self.shade))

            draw.line([
                self.x1 + self.de, self.y1 - self.de, self.x1 + self.de,
                self.y2 - self.de
            ], pen)
            draw.line([self.x1 + self.de, self.y2 - self.de, self.x1, self.y2],
                      pen)
            draw.line([
                self.x1 + self.de, self.y2 - self.de, self.x2 + self.de,
                self.y2 - self.de
            ], pen)

            draw.polygon([
                self.x1, self.y1, self.x1 + self.de, self.y1 - self.de,
                self.x2 + self.de, self.y1 - self.de, self.x2, self.y1
            ], pen, brush_s1)

            draw.polygon([
                self.x2 + self.de, self.y1 - self.de, self.x2, self.y1,
                self.x2, self.y2, self.x2 + self.de, self.y2 - self.de
            ], pen, brush_s2)

        draw.rectangle([self.x1, self.y1, self.x2, self.y2], pen, brush)
Beispiel #4
0
    def _draw_cs(self, dr_: ImageDraw, cs: CargoSpace, cord_x: int,
                 cord_y: int, font: ImageFont, col_w: list, we_grp: tuple):

        reset_x = cord_x
        cs_sum_we = sum(col_w)

        for f in range(0, self._dataset.width, 1):
            dr_.text((cord_x + 12, cord_y + 43),
                     '%s%%' % _calc_we_dist(cs_sum_we, col_w[f]),
                     fill='black')
            cord_x += 40
        cord_x = reset_x

        for y in range(0, self._dataset.width, 1):
            for x in range(0, self._dataset.height, 1):
                curr_pack = cs.columns[x].get(y)
                if curr_pack is not None:
                    rgb = 240 - (25 * np.digitize(curr_pack.weight, we_grp))
                    dr_.rectangle(
                        ((cord_x, cord_y), (cord_x + 35, cord_y + 35)),
                        fill=(rgb, rgb, rgb),
                        outline='black')
                    dr_.text((cord_x + 5, cord_y + 5),
                             'ID: %s' % curr_pack.id,
                             fill='black',
                             font=font)
                    dr_.text((cord_x + 5, cord_y + 20),
                             'WE: %s' % curr_pack.weight,
                             fill='black',
                             font=font)
                cord_x += 40
            cord_y -= 40
            cord_x = reset_x
Beispiel #5
0
 def draw(self, draw: ImageDraw) -> None:
     if self._draw_border:
         draw.rectangle(
             (self.abs_col, self.abs_row, self.abs_col + self.width - 1,
              self.abs_row + self.height - 1),
             outline=self.foreground,
             fill=self.background)
Beispiel #6
0
    def __dessiner_entete_nom_mois(self, origine: Point, crayon: ImageDraw):
        """
        Dessine l'en-tête du mois

        :param origine: le point d'insértion de l'en-tête
        :param crayon: l'outil de dessin
        :param couleur_titre: la couleur du texte du nom de mois
        """
        crayon.rectangle(
            (origine.to_tuple(), origine.deplacer(
                self.taille_entete_nom).to_tuple()),
            fill=self.couleur_fond_entete.value)

        if self.inclure_annee:
            annee_str = str(self.donnees.annee)
            taille_annee_mois = calculer_taille_texte(
                annee_str, police=CONST.POLICE_ANNEE_ENTETE_MOIS)
            pt_ins_annee_mois = (origine.x + self.taille_entete_nom.longueur -
                                 taille_annee_mois.longueur, origine.y)
            crayon.text(pt_ins_annee_mois,
                        annee_str,
                        fill=self.couleur_titre.value,
                        font=CONST.POLICE_ANNEE_ENTETE_MOIS)

        # création d’un objet 'dessin' qui permet de dessiner sur l’image
        dessiner_texte(crayon, self.nom_mois, CONST.POLICE_NOM_MOIS,
                       self.taille_entete_nom, origine, self.couleur_titre,
                       AlignementHorizontal.CENTRE)
Beispiel #7
0
def draw_text(draw: ImageDraw, image: Image, font, text="Text example", gravity="South", fill=(0, 0, 0), padding=5, margin=10):
    text_width, text_height = draw.textsize(text, font=font)
    gravity = gravity.lower()

    if gravity == 'south':
        x = (image.width - text_width) // 2
        y = image.height - text_height - margin - padding
    elif gravity == 'north':
        x = (image.width - text_width) // 2
        y = margin + padding
    elif gravity == 'center':
        x = (image.width - text_width) // 2
        y = (image.height - text_height) // 2
    elif gravity == 'southwest':
        x = margin + padding
        y = image.height - text_height - margin - padding
    elif gravity == 'southeast':
        x = image.width - margin - padding - text_width
        y = image.height - text_height - margin - padding
    elif gravity == 'northwest':
        x = y = margin + padding
    elif gravity == 'northeast':
        x = image.width - margin - padding - text_width
        y = margin + padding
    else:
        x = y = 0

    draw.rectangle((x - padding, y - padding, x + text_width + padding, y + text_height + padding), fill=fill)
    draw.text((x, y), text=text, font=font)
Beispiel #8
0
def draw_hollow_rect(draw: ImageDraw, rect: Tuple[int, int, int, int],
                     color: Tuple[int, int, int],
                     thickness: int = 2) -> None:
    """
    Fills a rectanglular area with a given color, but erases the inside,
    leaving an outline with a completely transparent inside.

    Parameters
    ----------
    draw: ImageDraw
        The drawing handler.

    rect: Tuple[int, int, int, int]
        The bounds of the rectangle. The bounds are in the format
        (x1, y1, x2, y2), where the points define the edge coordinates.
        The second point lies outside of the rectangle bounds.

    color
        The color of the rectangle.

    thickness: int
        How thick to make the line in pixels. Defaults to 2.
    """

    draw.rectangle(rect, fill=color)
    rect = (rect[0] + 2, rect[1] + 2, rect[2] - 2, rect[3] - 2)
    draw.rectangle(rect, fill=(0, 0, 0, 0))
    def draw_activity(self, draw: ImageDraw, name: str, time: str,
                      progress: float, x: int, y: int):
        title_font_size = 40
        text_progress_margin = 25

        progress_end_y = y + BasicImageCreator.PROGRESS_BAR_HEIGHT + text_progress_margin
        progress_start_xy = (x, y + text_progress_margin)

        background_end_xy = (x + BasicImageCreator.PROGRESS_BAR_WIDTH,
                             progress_end_y)
        foreground_end_xy = (x +
                             BasicImageCreator.PROGRESS_BAR_WIDTH * progress,
                             progress_end_y)

        draw.rectangle(
            (progress_start_xy, background_end_xy),
            fill=self.data_repository.get_setting("progress_background_color"))
        draw.rectangle(
            (progress_start_xy, foreground_end_xy),
            fill=self.data_repository.get_setting("progress_foreground_color"))

        # Draw activity title
        draw.text(
            (x, y - title_font_size),
            name,
            font=ImageFont.truetype(self.get_font("semi_bold"),
                                    title_font_size),
            fill=self.data_repository.get_setting("activity_title_color"))

        # Draw activity time
        draw.text((x + BasicImageCreator.PROGRESS_BAR_WIDTH, y - 20),
                  BasicImageCreator.time_as_str(time),
                  font=ImageFont.truetype(self.get_font("bold"), 30),
                  fill=self.data_repository.get_setting("activity_time_color"),
                  anchor="rt")
Beispiel #10
0
 def render_text(self, _: Image, draw: ImageDraw, draw_property: Mapping,
                 bounding_box: Tuple[Tuple[int, int], Tuple[int, int]], current_x: int, current_y: int,
                 backwards: bool) -> Tuple[int, int]:
     font = ImageFont.truetype(draw_property["font"], draw_property["font_size"])
     text = self.properties.get(draw_property["property"])
     current_x, current_y = self.resolve_position(draw_property["position"], bounding_box, current_x, current_y)
     if text is not None:
         background = self.properties.get(draw_property["background_property"])
         if background is None:
             background = draw_property["background_default"]
         text_color = self.properties.get(draw_property["text_color_property"])
         if text_color is None:
             text_color = draw_property["text_color_default"]
         text_width, text_height = draw.textsize(text, font)
         desired_width = draw_property["size"][0] if draw_property["size"][0] != "auto" else text_width
         desired_height = draw_property["size"][1] if draw_property["size"][1] != "auto" else text_height
         if backwards:
             current_x -= desired_width
         draw.rectangle(((current_x, current_y), (current_x + desired_width, current_y + desired_height)),
                        fill=background)
         # CodeReview: center between current_y and bottom of bounding box
         x_coord = (current_x + (desired_width - text_width) // 2) if draw_property["centered_width"] else current_x
         y_coord = (current_y + (desired_height - text_height) // 2) if draw_property["centered_height"] \
             else current_y
         draw.text((x_coord, y_coord), text, fill=text_color, font=font)
         current_x += desired_width
     elif draw_property["required"]:
         raise Exception(f"Missing required property: {draw_property['property']} from card {self.properties}")
     return current_x, current_y
Beispiel #11
0
    def draw(self, draw: ImageDraw):
        x0 = self.x - self.size / 2
        y0 = self.y - self.size / 2
        x1 = self.x + self.size / 2
        y1 = self.y + self.size / 2

        draw.rectangle([x0, y0, x1, y1], self.color)
Beispiel #12
0
    def render_layer(self, dungeon: Dungeon,
                     paintableRooms: Dict[DungeonRoom, PaintableRoom],
                     img: Image, draw: ImageDraw) -> None:
        """See RenderLayer for docs."""

        rect = (0, 0, img.size[0], img.size[1])
        draw.rectangle(rect, fill=self.color)
Beispiel #13
0
def rounded_rectangle(draw: ImageDraw, xy, r, fill=None, outline=None):
    draw.rectangle([(xy[0][0], xy[0][1] + r), (xy[1][0], xy[1][1] - r)],
                   fill=fill,
                   outline=outline)
    draw.rectangle([(xy[0][0] + r, xy[0][1]), (xy[1][0] - r, xy[1][1])],
                   fill=fill,
                   outline=outline)
    draw.pieslice([xy[0], (xy[0][0] + r * 2, xy[0][1] + r * 2)],
                  180,
                  270,
                  fill=fill,
                  outline=outline)
    draw.pieslice([(xy[1][0] - r * 2, xy[1][1] - r * 2), xy[1]],
                  0,
                  90,
                  fill=fill,
                  outline=outline)
    draw.pieslice([(xy[0][0], xy[1][1] - r * 2), (xy[0][0] + r * 2, xy[1][1])],
                  90,
                  180,
                  fill=fill,
                  outline=outline)
    draw.pieslice([(xy[1][0] - r * 2, xy[0][1]), (xy[1][0], xy[0][1] + r * 2)],
                  270,
                  360,
                  fill=fill,
                  outline=outline)
Beispiel #14
0
 def _render_outer_rect(self, draw: ImageDraw, x1: int, y1: int,
                        y2: int) -> None:
     x3 = x1
     y3 = y1 + int(self.corner_radius * self.upper_outer_radius_y)
     x4 = x1 + int(self.corner_radius * max(self.upper_outer_radius_x,
                                            self.lower_outer_radius_x))
     y4 = y2 - int(self.corner_radius * self.lower_outer_radius_y)
     draw.rectangle(((x3, y3), (x4, y4)), fill=1)
Beispiel #15
0
 def _render_lower_rect(self, draw: ImageDraw, x1: int, x2: int,
                        y2: int) -> None:
     x3 = x1 + int(self.corner_radius * self.lower_outer_radius_x)
     y3 = y2 - int(self.corner_radius * max(self.lower_outer_radius_y,
                                            self.lower_inner_radius_y))
     x4 = x2 - int(self.corner_radius * self.lower_inner_radius_x)
     y4 = y2
     draw.rectangle(((x3, y3), (x4, y4)), fill=1)
Beispiel #16
0
def render_candlestick(ohlc: Tuple[float, ...], x: int,
                       y_transformer: Callable[[float], int], draw: ImageDraw):
    color = (255, 55, 55, 255) if ohlc[3] < ohlc[0] else (55, 255, 55, 255)
    draw.rectangle((x, y_transformer(max(
        ohlc[0], ohlc[3])), x + 2, y_transformer(min(ohlc[0], ohlc[3]))),
                   fill=color)
    draw.line((x + 1, y_transformer(ohlc[1]), x + 1, y_transformer(ohlc[2])),
              fill=color)
Beispiel #17
0
 def draw(self, draw: ImageDraw, scale: float):
     half_width, half_height = self.width / 2, self.height / 2
     x1, y1 = self.x - half_width, self.y - half_height
     x2, y2 = self.x + half_width, self.y + half_height
     xy = x1 * scale, y1 * scale, x2 * scale, y2 * scale
     fill = self.fill if self.children > 0 else (211, 211, 211)
     draw.rectangle(xy, fill=fill, outline=self.outline)
     return
Beispiel #18
0
def _draw_punch(draw: ImageDraw, col_start, row_start):
    punch_height = 19
    punch_width = 10
    punch_color = (0, 0, 0)

    col_end = col_start + punch_width
    row_end = row_start + punch_height

    draw.rectangle([col_start, row_start, col_end, row_end], fill=punch_color)
Beispiel #19
0
    def render_layer(self, dungeon: Dungeon,
                     paintableRooms: Dict[DungeonRoom, PaintableRoom],
                     img: Image, draw: ImageDraw) -> None:
        """See RenderLayer for docs."""

        for room in dungeon.rooms:
            rect = paintableRooms[room].rect
            col = self.get_gradient_color(room.difficulty)
            draw.rectangle(rect, fill=col)
Beispiel #20
0
def render_candlestick(ohlc: Tuple[float, ...], x: int,
                       y_transformer: Callable[[float], int], draw: ImageDraw):
    #empty rectangle to represent negative candle sticks
    fill_rectangle = 0 if ohlc[3] < ohlc[0] else 1
    draw.line((x + 1, y_transformer(ohlc[1]), x + 1, y_transformer(ohlc[2])),
              fill=1)
    draw.rectangle((x, y_transformer(max(
        ohlc[0], ohlc[3])), x + 2, y_transformer(min(ohlc[0], ohlc[3]))),
                   fill=fill_rectangle,
                   outline=1)
Beispiel #21
0
 def _draw_selections(self, draw: ImageDraw) -> None:
     y = 2 + self._display.character_height
     for i, v in enumerate(self._selections):
         # only show items that fit
         if y < (self._display.height - self._display.character_height * 3):
             # has room still
             if self._selected == i:
                 draw.rectangle([(0, y), (self._display.width, y + self._display.character_height)], fill=(255, 0, 0))
             draw.text((1, y), v.title, fill=(255, 255, 255))
             y += self._display.character_height
Beispiel #22
0
 def _render_center_rect(self, draw: ImageDraw, x1: int, y1: int, x2: int,
                         y2: int) -> None:
     x3 = x1 + int(self.corner_radius * max(self.upper_outer_radius_x,
                                            self.lower_outer_radius_x)) - 2
     y3 = y1 + int(self.corner_radius * max(self.upper_outer_radius_y,
                                            self.upper_inner_radius_y)) - 1
     x4 = x2 - int(self.corner_radius * max(self.upper_inner_radius_y,
                                            self.lower_inner_radius_y)) + 2
     y4 = y2 - int(self.corner_radius * max(self.lower_outer_radius_y,
                                            self.lower_inner_radius_y)) + 1
     draw.rectangle(((x3, y3), (x4, y4)), fill=1)
Beispiel #23
0
 def _rect(self,
           draw: ImageDraw,
           x: int,
           y: int,
           w: int,
           h: int,
           color: str = None):
     m = self.multiplier
     if color is None:
         color = self.theme.details
     draw.rectangle([x * m, y * m, (x + w) * m - 1, (y + h) * m - 1], color)
Beispiel #24
0
    def _render_rect(self, draw: ImageDraw,
                     rect: Tuple[float, float, float, float],
                     fill: Optional[str],
                     outline: str,
                     **kwargs):

        bb = BoundingBox(rect)
        for bb in bb.partition_x(self.width, self.row_height):
            (w, h) = self.image.size
            r = (bb.bb[0], bb.bb[1], min(w - 1, bb.bb[2]), min(h - 1, bb.bb[3]))
            draw.rectangle(r, fill=fill, outline=outline, **kwargs)
def draw_rectangle(draw_context: ImageDraw,
                   box_coordinates: np.array,
                   color="red",
                   width=3):
    x1, y1, x2, y2 = box_coordinates
    offset = 1
    for i in range(0, width):
        draw_context.rectangle(((x1, y1), (x2, y2)), outline=color)
        x1 = x1 - offset
        y1 = y1 + offset
        x2 = x2 + offset
        y2 = y2 - offset
Beispiel #26
0
 def draw_rectangle(self, draw: ImageDraw, percent: float, font: ImageFont):
     left_x = self.width / 6
     left_y = self.height * 15 / 24
     right_x = self.width * 4 / 6
     right_y = left_y + self.height * 0.08
     draw.rectangle(((left_x, left_y), (right_x, right_y)),
                    outline=(255, 0, 0),
                    width=5)
     draw.rectangle(((left_x, left_y), (right_x * percent / 100, right_y)),
                    fill=(255, 0, 0))
     draw.text((right_x + self.width * 0.03, left_y + self.height * 0.02),
               f'{percent:2.2f}%', (255, 0, 0),
               font=font)
Beispiel #27
0
def rounded_rectangle(
        draw: ImageDraw, box: Tuple[int, int, int, int],
        radius: int,
        fill: Any = None,
        outline: Any = None) -> None:
    """Draw a rounded rectangle on the given image."""
    x1, y1, x2, y2 = box

    draw.rectangle(
        (x1 + radius, y1, x2 - radius, y2),
        fill=fill,
        outline=outline
    )

    draw.rectangle(
        (x1, y1 + radius, x2, y2 - radius),
        fill=fill,
        outline=outline
    )

    diameter = radius * 2

    draw.pieslice(
        (x1, y1, x1 + diameter, y1 + diameter),
        start=180,
        end=270,
        fill=fill,
        outline=outline
    )
    draw.pieslice(
        (x2 - diameter, y1, x2, y1 + diameter),
        start=270,
        end=360,
        fill=fill,
        outline=outline
    )
    draw.pieslice(
        (x2 - diameter, y2 - diameter, x2, y2),
        start=0,
        end=90,
        fill=fill,
        outline=outline
    )
    draw.pieslice(
        (x1, y2 - diameter, x1 + diameter, y2),
        start=90,
        end=180,
        fill=fill,
        outline=outline
    )
Beispiel #28
0
    def render_layer(self, dungeon: Dungeon,
                     paintableRooms: Dict[DungeonRoom, PaintableRoom],
                     img: Image, draw: ImageDraw) -> None:
        """See RenderLayer for docs."""

        regionColors = [(0, 0, 0)] * dungeon.region_count()
        for i in range(len(regionColors)):
            r = rand(128) + 128
            g = rand(128) + 128
            b = rand(128) + 128
            regionColors[i] = (r, g, b)

        for room in dungeon.rooms:
            rect = paintableRooms[room].rect
            draw.rectangle(rect, fill=regionColors[room.region])
Beispiel #29
0
 def draw(self, active_index: float, canvas: ImageDraw):
     """Draw the menu into a canvas.
     `active_index` can be a float for smooth transitions
     """
     # copy the relevant part of the pre-rendered menu
     y_start = self._y_offset + \
         self._lineToEntryIndex(active_index, 0) * self._line_h
     rect = (0, y_start, self._line_w,
             y_start + self._num_rows * self._line_h)
     visible = self._full_menu.crop(rect)
     canvas.bitmap((0, 0), visible, fill="white")
     # then draw the active menu frame
     n = active_index % self._num_rows
     canvas.rectangle((0, int(n * self._line_h), self._line_w - 1,
                       int((n + 1) * self._line_h - 1)),
                      outline="white")
def draw_rectangle(draw: ImageDraw, position: int, width: int, tier: str):
    """
    Draws a rectangle over the image given a ImageDraw object and the intended
    position, width, and tier.

    :param draw: an picture we're editing
    :param position: the position of the rectangle to be added
    :param width: the width of the rectangle to be added
    :param tier: the tier which determines the outline
    :return: nothing
    """
    draw.rectangle(((IMAGE_WIDTH - width - X_OFFSET * 2, position),
                    (IMAGE_WIDTH, position + RECTANGLE_HEIGHT)),
                   fill=RECTANGLE_FILL,
                   outline=TIER_MAP.get(tier.lower(), None),
                   width=7)
Beispiel #31
0
def drawpixel(target: ImageDraw, x, y, size, color):
    target.rectangle((x * size, y * size, (x + 1) * size, (y + 1) * size), fill=color)