how to draw squircle python

Solutions on MaxInterview for how to draw squircle python by the best coders in the world

showing results for - "how to draw squircle python"
Damien
31 Sep 2020
1from PIL.ImageDraw import ImageDraw
2
3
4def rounded_rectangle(self: ImageDraw, xy, corner_radius, fill=None, outline=None):
5    upper_left_point = xy[0]
6    bottom_right_point = xy[1]
7    self.rectangle(
8        [
9            (upper_left_point[0], upper_left_point[1] + corner_radius),
10            (bottom_right_point[0], bottom_right_point[1] - corner_radius)
11        ],
12        fill=fill,
13        outline=outline
14    )
15    self.rectangle(
16        [
17            (upper_left_point[0] + corner_radius, upper_left_point[1]),
18            (bottom_right_point[0] - corner_radius, bottom_right_point[1])
19        ],
20        fill=fill,
21        outline=outline
22    )
23    self.pieslice([upper_left_point, (upper_left_point[0] + corner_radius * 2, upper_left_point[1] + corner_radius * 2)],
24        180,
25        270,
26        fill=fill,
27        outline=outline
28    )
29    self.pieslice([(bottom_right_point[0] - corner_radius * 2, bottom_right_point[1] - corner_radius * 2), bottom_right_point],
30        0,
31        90,
32        fill=fill,
33        outline=outline
34    )
35    self.pieslice([(upper_left_point[0], bottom_right_point[1] - corner_radius * 2), (upper_left_point[0] + corner_radius * 2, bottom_right_point[1])],
36        90,
37        180,
38        fill=fill,
39        outline=outline
40    )
41    self.pieslice([(bottom_right_point[0] - corner_radius * 2, upper_left_point[1]), (bottom_right_point[0], upper_left_point[1] + corner_radius * 2)],
42        270,
43        360,
44        fill=fill,
45        outline=outline
46    )
47
48
49ImageDraw.rounded_rectangle = rounded_rectangle
50