def set_noise(self, __image: ImageDraw, img_width, img_height): for i in range(self.max_line_count): # 噪线的起点横坐标和纵坐标 x1 = random.randint(0, img_width) y1 = random.randint(0, img_height) # 噪线的终点横坐标和纵坐标 x2 = random.randint(0, img_width) y2 = random.randint(0, img_height) # 通过画笔对象draw.line((起点的xy, 终点的xy), fill='颜色')来划线 __image.line((x1, y1, x2, y2), fill=(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))) for i in range(self.max_point_count): __image.point( [random.randint(0, img_width), random.randint(0, img_height)], fill=(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))) x = random.randint(0, img_width) y = random.randint(0, img_height) __image.arc((x, y, x + 4, y + 4), 0, 40, fill=(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)))
def draw(self, draw: ImageDraw): # top right if self.pta == top_pt and self.ptb == right_pt or self.pta == right_pt and self.ptb == top_pt: circle_xy0 = (0.5 - LINE_WIDTH_PCT / 2, -0.5 - LINE_WIDTH_PCT / 2) circle_xy1 = (1.5 + LINE_WIDTH_PCT / 2, 0.5 + LINE_WIDTH_PCT / 2) start_deg = 90 end_deg = 180 # bot right elif self.pta == bot_pt and self.ptb == right_pt or self.pta == right_pt and self.ptb == bot_pt: circle_xy0 = (0.5 - LINE_WIDTH_PCT / 2, 0.5 - LINE_WIDTH_PCT / 2) circle_xy1 = (1.5 + LINE_WIDTH_PCT / 2, 1.5 + LINE_WIDTH_PCT / 2) start_deg = 180 end_deg = 270 # bot left elif self.pta == bot_pt and self.ptb == left_pt or self.pta == left_pt and self.ptb == bot_pt: circle_xy0 = (-0.5 - LINE_WIDTH_PCT / 2, 0.5 - LINE_WIDTH_PCT / 2) circle_xy1 = (0.5 + LINE_WIDTH_PCT / 2, 1.5 + LINE_WIDTH_PCT / 2) start_deg = 270 end_deg = 360 # top left elif self.pta == top_pt and self.ptb == left_pt or self.pta == left_pt and self.ptb == top_pt: circle_xy0 = (-0.5 - LINE_WIDTH_PCT / 2, -0.5 - LINE_WIDTH_PCT / 2) circle_xy1 = (0.5 + LINE_WIDTH_PCT / 2, 0.5 + LINE_WIDTH_PCT / 2) start_deg = 0 end_deg = 90 else: raise Exception circle_xy0_px = tuple_multiply(circle_xy0, self.canvas_px) circle_xy1_px = tuple_multiply(circle_xy1, self.canvas_px) #print(f'{(circle_xy0_px, circle_xy1_px)}, {start_deg}, {end_deg},{int(self.canvas_px * LINE_WIDTH_PCT)}') draw.arc((circle_xy0_px, circle_xy1_px), start_deg, end_deg, fill=self.color.value, width=int(self.canvas_px * LINE_WIDTH_PCT)) return
def draw(self, draw: ImageDraw): draw.arc(self.points, self.start, self.end, self.fill)