示例#1
0
文件: main.py 项目: rubik/cartesius
    def draw_line(self, x1, y1, x2, y2, color):
        image_x1, image_y1 = utils.cartesius_to_image_coord(x1, y1,
                                                            self.bounds)
        image_x2, image_y2 = utils.cartesius_to_image_coord(x2, y2,
                                                            self.bounds)

        self.pil_draw.line((image_x1, image_y1, image_x2, image_y2), color)
示例#2
0
    def draw_circle(self, x, y, radius, line_color, fill_color):
        x1, y1 = mod_utils.cartesius_to_image_coord(
                x = x - radius / 2.,
                y = y + radius / 2.,
                bounds = self.bounds)
        x2, y2 = mod_utils.cartesius_to_image_coord(
                x = x + radius / 2.,
                y = y - radius / 2.,
                bounds = self.bounds)

        self.pil_draw.ellipse(
                (x1, y1, x2, y2),
                fill = fill_color,
                outline = line_color)
示例#3
0
    def draw_pieslice(self, x, y, radius, start_angle, end_angle, fill_color=None, color=None):
        x1, y1 = mod_utils.cartesius_to_image_coord(
                x=x - radius,
                y=y + radius,
                bounds=self.bounds)
        x2, y2 = mod_utils.cartesius_to_image_coord(
                x=x + radius,
                y=y - radius,
                bounds=self.bounds)

        self.pil_draw.pieslice(
                (int(x1), int(y1), int(x2), int(y2)),
                int(start_angle),
                int(end_angle),
                fill=fill_color,
                outline=color)
示例#4
0
    def draw_text(self, x, y, text, color, label_position=None):
        """
        Draw text.

        label_position: one of the label position constants (CENTER_UP, RIGHT_DOWN, ...). The default
        is set in draw_text()
        """
        label_position = label_position if label_position else RIGHT_DOWN

        image_x, image_y = mod_utils.cartesius_to_image_coord(x, y, self.bounds)

        font = self.get_font()

        label_width, label_height = font.getsize(text)

        if label_position[0] == -1:
            image_x = image_x - label_width - 4. * self.antialiasing_coef
        elif label_position[0] == 0:
            image_x = image_x - label_width / 2.
        elif label_position[0] == 1:
            image_x += 4 * self.antialiasing_coef

        if label_position[1] == -1:
            image_y += 2 * self.antialiasing_coef
        elif label_position[1] == 0:
            image_y = image_y - label_height / 2.
        elif label_position[1] == 1:
            image_y = image_y - label_height - 2 * self.antialiasing_coef

        self.pil_draw.text((image_x, image_y), text, color, font)
示例#5
0
 def draw_polygon(self, points, fill_color):
     image_points = []
     for x, y in points:
         image_coordinates = mod_utils.cartesius_to_image_coord(x, y, self.bounds)
         image_points.append(image_coordinates)
     self.pil_draw.polygon(
         image_points,
         fill=fill_color)
示例#6
0
文件: main.py 项目: rubik/cartesius
    def draw_point(self, x, y, color, style='+', label=None,
                   label_position=None):
        """
        Draw single point.

        style: can be '.' (single pixel), '+', 'x', and 'o' (small circle)
        label: text to be displayed
        label_position: one of the label position constants (CENTER_UP,
        RIGHT_DOWN, ...). The default is set in draw_text()
        """
        image_x, image_y = utils.cartesius_to_image_coord(x, y, self.bounds)

        if label_position:
            assert len(label_position) == 2

        if not color:
            color = DEFAULT_POINT_COLOR

        if style == '.' or style == None:
            self.pil_draw.point((image_x, image_y), color)
        elif style == 'x':
            delta = 2 * self.antialiasing_coef
            self.pil_draw.line((image_x - delta, image_y - delta,
                                image_x + delta, image_y + delta), color)
            self.pil_draw.line((image_x - delta, image_y + delta,
                                image_x + delta, image_y - delta), color)
        elif style == '+':
            delta = 2 * self.antialiasing_coef
            self.pil_draw.line((image_x - delta, image_y,
                                image_x + delta, image_y), color)
            self.pil_draw.line((image_x, image_y + delta,
                                image_x, image_y - delta), color)
        elif style == ' ':
            # No point
            pass
        elif style == 'o':
            delta = 2 * self.antialiasing_coef
            self.pil_draw.ellipse(
                    (image_x - delta, image_y - delta,
                     image_x + delta, image_y + delta),
                    fill=None,
                    outline=color)
        else:
            logging.error('Invalid style: {0}, valid: ".", "x", "+" and ' \
                              '"o"'.format(style))
            self.pil_draw.point((image_x, image_y), color)

        if label:
            self.draw_text(x, y, label, color, label_position=label_position)