Exemplo n.º 1
0
 def draw(self, image: ImageDraw, x_shift: int = 0, y_shift: int = 0):
     self.x_shift += x_shift
     self.y_shift += y_shift
     for child in self.children:
         image.line(
             (
                 self.x * X_UNIT,
                 self.y * Y_UNIT,
                 child.x * X_UNIT + self.x_shift * X_UNIT,
                 child.y * Y_UNIT + self.y_shift * Y_UNIT,
             ),
             fill='black',
             width=LINE_WIDTH,
         )
         child.draw(image, self.x_shift, self.y_shift)
     image.ellipse(
         (
             self.x * X_UNIT - DOT_SIZE / 2,
             self.y * Y_UNIT - DOT_SIZE / 2,
             self.x * X_UNIT + DOT_SIZE / 2,
             self.y * Y_UNIT + DOT_SIZE / 2,
         ),
         fill='white',
         outline='black',
         width=LINE_WIDTH,
     )
Exemplo n.º 2
0
def __visualize_joint(draw: ImageDraw,
                      joint: Joint2D,
                      color: Color,
                      radius: int = 5):
    draw.ellipse(
        (int(joint.x) - radius, int(joint.y) - radius, int(joint.x) + radius,
         int(joint.y) + radius), color.tuple_rgb)
Exemplo n.º 3
0
    def draw(self, draw: ImageDraw):
        x0 = self.x - self.radius / 2
        y0 = self.y - self.radius / 2
        x1 = self.x + self.radius / 2
        y1 = self.y + self.radius / 2

        draw.ellipse([x0, y0, x1, y1], self.color)
Exemplo n.º 4
0
def __draw_node_circle(centre: Tuple[float, float],
                       draw: ImageDraw,
                       color: str = "green"):
    x, y = centre
    draw.ellipse(
        (x - NODE_RADIUS, y - NODE_RADIUS, x + NODE_RADIUS, y + NODE_RADIUS),
        fill=color,
    )
Exemplo n.º 5
0
def draw_circle(draw: ImageDraw,
                center: complex,
                radius: float,
                color: str = "#000000"):
    # Define the bounds of the circle
    bounds = [(center.real - radius, center.imag - radius)]
    bounds.append((center.real + radius, center.imag + radius))

    draw.ellipse(bounds, outline=color)
Exemplo n.º 6
0
    def render_layer(self, dungeon: Dungeon,
                     paintableRooms: Dict[DungeonRoom, PaintableRoom],
                     img: Image, draw: ImageDraw) -> None:
        """See RenderLayer for docs."""

        for key in dungeon.keys:
            keyRoom = key.keyLocation
            keyX, keyY = paintableRooms[keyRoom].center

            rect = (keyX - self.keyRadius, keyY - self.keyRadius,
                    keyX + self.keyRadius, keyY + self.keyRadius)
            draw.ellipse(rect, fill=self.keyColor)
Exemplo n.º 7
0
def stroke_poly(img: Image, draw: ImageDraw, points, color: Tuple[int, ...], width: int):
    draw.line(points, fill=color, width=width)
    for point in points:
        draw.ellipse(
            (
                point[0] - (int(width / 2) - 1),
                point[1] - (int(width / 2) - 1),
                point[0] + (int(width / 2) - 1),
                point[1] + (int(width / 2) - 1)
            ),
            fill=color
        )
    return draw, img
Exemplo n.º 8
0
def draw_circle(img_draw: ImageDraw, area, brightness):
    x_min, y_min, x_max, y_max = area
    br = brightness[0] * 0.3 + brightness[1] * 0.59 + brightness[2] * .11
    radius = custom_map(br, 0, 255, CHUNK_SIZE // MINIMUM_RADIAL_FACTOR,
                        CHUNK_SIZE // MAXIMUM_RADIAL_FACTOR)

    if INVERTED:
        radius = CHUNK_SIZE // 2 - radius
    x_mid = x_min + (x_max - x_min) // 2
    y_mid = y_min + (y_max - y_min) // 2

    circle_region = (x_mid - radius, y_mid - radius, x_mid + radius,
                     y_mid + radius)
    img_draw.ellipse(circle_region, fill=brightness, width=1)
Exemplo n.º 9
0
def draw_circle(draw: ImageDraw,
                xy: Tuple[float, float],
                radius: float,
                fill=None,
                outline=None,
                width=1) -> None:
    """
    Pillowを使って画像に円を描く(ImageDraw.ellipseの簡易Wrapper)
    :param draw: PIL.ImageDraw
    :param xy: 円の中心座標(x, y)を表すタプル
    :param radius: 円の半径
    :param fill: 円の塗りつぶし色(tuple or string)
    :param outline: 円の輪郭色(tuple or string)
    :param width: 線の太さ
    :return: なし
    """
    x1 = int(xy[0] - radius)
    y1 = int(xy[1] - radius)
    x2 = int(xy[0] + radius)
    y2 = int(xy[1] + radius)
    draw.ellipse((x1, y1, x2, y2), fill, outline, width)
Exemplo n.º 10
0
 def draw_func(draw: ImageDraw):
     if vacuum_pos.a is None:
         vacuum_pos.a = 0
     point = vacuum_pos.to_img(image.dimensions)
     r_scaled = r / 16
     # main outline
     coords = [point.x - r, point.y - r, point.x + r, point.y + r]
     draw.ellipse(coords, outline=outline, fill=fill)
     if r >= 8:
         # secondary outline
         r2 = r_scaled * 14
         x = point.x
         y = point.y
         coords = [x - r2, y - r2, x + r2, y + r2]
         draw.ellipse(coords, outline=outline, fill=None)
     # bin cover
     a1 = (vacuum_pos.a + 104) / 180 * math.pi
     a2 = (vacuum_pos.a - 104) / 180 * math.pi
     r2 = r_scaled * 13
     x1 = point.x - r2 * math.cos(a1)
     y1 = point.y + r2 * math.sin(a1)
     x2 = point.x - r2 * math.cos(a2)
     y2 = point.y + r2 * math.sin(a2)
     draw.line([x1, y1, x2, y2], width=1, fill=outline)
     # lidar
     angle = vacuum_pos.a / 180 * math.pi
     r2 = r_scaled * 3
     x = point.x + r2 * math.cos(angle)
     y = point.y - r2 * math.sin(angle)
     r2 = r_scaled * 4
     coords = [x - r2, y - r2, x + r2, y + r2]
     draw.ellipse(coords, outline=outline, fill=fill)
     # button
     half_color = ((outline[0] + fill[0]) // 2,
                   (outline[1] + fill[1]) // 2,
                   (outline[2] + fill[2]) // 2)
     r2 = r_scaled * 10
     x = point.x + r2 * math.cos(angle)
     y = point.y - r2 * math.sin(angle)
     r2 = r_scaled * 2
     coords = [x - r2, y - r2, x + r2, y + r2]
     draw.ellipse(coords, outline=half_color, fill=half_color)
Exemplo n.º 11
0
 def draw(self, draw: ImageDraw):
     pen, brush = self._get_pen_brush()
     w = self.x2 - self.x1
     d = int(w / 7)
     draw.ellipse([
         self.x1 + (w - d) / 2, self.y1 + 1 * d, self.x1 +
         (w + d) / 2, self.y1 + 2 * d
     ], pen, brush)
     draw.ellipse([
         self.x1 + (w - d) / 2, self.y1 + 3 * d, self.x1 +
         (w + d) / 2, self.y1 + 4 * d
     ], pen, brush)
     draw.ellipse([
         self.x1 + (w - d) / 2, self.y1 + 5 * d, self.x1 +
         (w + d) / 2, self.y1 + 6 * d
     ], pen, brush)
 def draw_func(draw: ImageDraw):
     point = center.to_img(image.dimensions)
     coords = [point.x - r, point.y - r, point.x + r, point.y + r]
     draw.ellipse(coords, outline=outline, fill=fill)
Exemplo n.º 13
0
 def draw(self, draw: ImageDraw):
     pen, brush = self._get_pen_brush()
     draw.ellipse([self.x1, self.y1, self.x2, self.y2], pen, brush)
Exemplo n.º 14
0
def draw_point(draw: ImageDraw,
               point: Point,
               color: Color,
               radius: int = 3) -> None:
    x, y = point
    draw.ellipse((x - radius, y - radius, x + radius, y + radius), fill=color)
Exemplo n.º 15
0
 def draw(self, draw: ImageDraw):
     draw.ellipse(self.points, self.fill, self.outline)
Exemplo n.º 16
0
    def render_list(self, result: 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]:
        theme_font = None
        if "text" in draw_property["type"]:
            theme_font = ImageFont.truetype(draw_property["font"], draw_property["font_size"])
        items = self.properties.get(draw_property["property"])
        current_x, current_y = self.resolve_position(draw_property["position"], bounding_box, current_x, current_y)
        size_x, size_y = draw_property["size"]
        if size_x == "auto":
            size_x = bounding_box[1][0] - current_x + bounding_box[0][0]
            if backwards:
                size_x = current_x - bounding_box[0][0]
        if size_y == "auto":
            size_y = bounding_box[1][1] - current_y + bounding_box[0][1]
        print(current_x, size_x, backwards)
        if backwards:
            current_x = current_x - size_x
        orientation = draw_property["orientation"]
        internal_current_y = current_y
        internal_current_x = current_x
        if items is not None:
            cached_current_x = current_x
            cached_current_y = current_y
            spacing = draw_property["spacing"]
            x_border = current_x + size_x
            y_border = current_y + size_y
            rows = draw_property["rows"]
            columns = draw_property["columns"]
            first = True
            # CodeReview: Specify an order that all will conform to
            for item in items:
                resource_name = f"resources/icons/{item}.png"
                if "icon" in draw_property["type"] and os.path.isfile(resource_name):
                    icon = Image.open(resource_name)
                    icon_width, icon_height = icon.size
                    icon = icon.resize((self.format["icon_height"] * icon_width // icon_height,
                                        self.format["icon_height"]), Image.HAMMING)
                    icon_width, icon_height = icon.size
                    x_coord = internal_current_x
                    y_coord = internal_current_y
                    if orientation == "horizontal":
                        if not first:
                            x_coord += spacing
                        first = False
                        if draw_property["centered_height"]:
                            y_coord += (size_y // (rows or 1) - icon_height) // 2
                    if orientation == "vertical":
                        if not first:
                            y_coord += spacing
                        first = False
                        if draw_property["centered_width"]:
                            x_coord += (size_x // (columns or 1) - icon_width) // 2
                    if orientation == "horizontal" and x_coord + icon_width > x_border \
                            and rows is not None and internal_current_y < current_y + (rows - 1) * (size_y // rows):
                        internal_current_y += size_y // rows
                        internal_current_x = cached_current_x
                        x_coord = internal_current_x
                        y_coord += size_y // rows
                    elif orientation == "vertical" and y_coord + icon_height > y_border \
                            and columns is not None and \
                            internal_current_x < current_x + (columns - 1) * (size_y // columns):
                        internal_current_x += size_x // rows
                        internal_current_y = cached_current_y
                    result.paste(icon, (x_coord, y_coord))
                    if orientation == "horizontal":
                        internal_current_x = x_coord + icon_width
                    elif orientation == "vertical":
                        internal_current_y = y_coord + icon_height
                elif "text" in draw_property["type"]:
                    text_width, text_height = draw.textsize(item, theme_font)
                    if draw_property["wrap"] is not None:
                        item = textwrap.fill(item, draw_property["wrap"])
                        text_width, text_height = draw.multiline_textsize(item, theme_font)
                    x_coord = internal_current_x
                    y_coord = internal_current_y
                    text_color = self.properties.get(draw_property["text_color_property"]) or \
                        draw_property["text_color_default"]
                    if draw_property["bulleted"]:
                        draw.ellipse((internal_current_x + spacing,
                                      internal_current_y + (text_height - draw_property["font_size"]) // 2,
                                      internal_current_x + spacing + draw_property["font_size"],
                                      internal_current_y + (text_height + draw_property["spacing"]) // 2),
                                     fill=text_color)
                        x_coord += spacing*2 + draw_property["font_size"]
                    if orientation == "horizontal":
                        if not first:
                            x_coord += spacing
                        first = False
                        if draw_property["centered_height"]:
                            y_coord += (size_y // (rows or 1) - text_height) // 2
                    if orientation == "vertical":
                        if not first:
                            y_coord += spacing
                        first = False
                        if draw_property["centered_width"]:
                            x_coord += (size_x // (columns or 1) - text_width) // 2
                    print(x_coord, text_width, x_border, cached_current_x, internal_current_y)
                    if orientation == "horizontal" and x_coord + text_width > x_border \
                            and rows is not None and internal_current_y < current_y + (rows - 1) * (size_y // rows):
                        internal_current_y += size_y // rows
                        internal_current_x = cached_current_x
                        x_coord = internal_current_x
                        y_coord += size_y // rows
                    elif orientation == "vertical" and y_coord + text_height > y_border \
                            and columns is not None and \
                            internal_current_x < current_x + (columns - 1) * (size_y // columns):
                        internal_current_x += size_x // rows
                        internal_current_y = cached_current_y
                    if draw_property["wrap"] is None:
                        draw.text((x_coord, y_coord), item, fill=text_color, font=theme_font)
                    else:
                        draw.multiline_text((x_coord, y_coord), item, fill=text_color, font=theme_font)

                    if orientation == "horizontal":
                        internal_current_x = x_coord + text_width
                    elif orientation == "vertical":
                        internal_current_y = y_coord + text_height
                else:
                    raise Exception(f"Could not find handler for {item} for {draw_property['type']}")
            if not backwards:
                current_x += size_x
            if orientation == "vertical":
                current_y += size_y
        else:
            if draw_property["required"]:
                raise Exception(f"Missing required property: {draw_property['property']} from card {self.properties}")
        return current_x, current_y