Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import PIL
- import numpy as np
- import math
- from PIL import Image, ImageDraw
- w, h = 300, 300
- def func(figure_type, args):
- if figure_type == "circle":
- img = func_circle(args['radius'], args['x'], args['y'], args['width_line'], args['color_line'], args['is_fill'],
- args['color_fill'])
- else:
- img = func_square(args['x1'], args['y1'], args['x2'], args['y2'], args['width_line'], args['color_line'],
- args['is_fill'],
- args['color_fill'])
- return img
- def func_circle(r, x, y, width_line, color_line, is_fill, color_fill):
- img = Image.new("RGB", (w, h), "black")
- coordinates = []
- sectors = 6
- for i in range(1, sectors + 1):
- angle = 2 * math.pi * i / sectors
- coordinate_x = r * math.cos(angle) + x
- coordinate_y = r * math.sin(angle) + y
- coordinates += [(coordinate_x, coordinate_y)]
- color_fill = color_fill if is_fill else ''
- drawing = ImageDraw.Draw(img)
- drawing.polygon(coordinates, fill=color_fill, outline=color_line, width=width_line)
- return img
- def func_square(x1, y1, x2, y2, width_line, color_line, is_fill, color_fill):
- img = Image.new("RGB", (w, h), "black")
- coordinates = []
- sectors = 6
- radius = abs(x2 - x1) // 2
- center_x = x2 - radius
- center_y = y2 - radius
- for i in range(1, sectors + 1):
- angle = 2 * math.pi * i / sectors
- coordinate_x = radius * math.cos(angle) + center_x
- coordinate_y = radius * math.sin(angle) + center_y
- coordinates += [(coordinate_x, coordinate_y)]
- color_fill = color_fill if is_fill else ''
- drawing = ImageDraw.Draw(img)
- drawing.polygon(coordinates, fill=color_fill, outline=color_line, width=width_line)
- return img
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement