-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfigures.py
More file actions
106 lines (77 loc) · 2.55 KB
/
Copy pathfigures.py
File metadata and controls
106 lines (77 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import matplotlib.pyplot as plt
class Screen:
def __init__(self, fg_color, bg_color, height, width):
self.__fg_color = fg_color
self.__bg_color = bg_color
self.__height = height
self.__width = width
@property
def background(self):
return plt.Rectangle((0, 0), self.__width, self.__height, color=self.__bg_color)
@property
def canvas(self):
return plt.figure(figsize=(self.__width, self.__height), dpi=1)
@property
def fg_color(self):
return self.__fg_color
class Figure:
def __init__(self, color):
self._color = color
def artist(self):
return None
@staticmethod
def create(color, fig):
return None
class Point(Figure):
def __init__(self, color, x, y):
super().__init__(color)
self.__x = x
self.__y = y
def artist(self):
return plt.Circle((self.__x, self.__y), 1, color=self._color)
@staticmethod
def create(color, fig):
return Point(color, fig['x'], fig['y'])
class Polygon(Figure):
def __init__(self, color, points):
super().__init__(color)
self.__points = points
def artist(self):
return plt.Polygon(self.__points, color=self._color)
@staticmethod
def create(color, fig):
return Polygon(color, fig['points'])
class Rectangle(Figure):
def __init__(self, color, x, y, height, width):
super().__init__(color)
self.__width = width
self.__height = height
self.__x = x
self.__y = y
def artist(self):
return plt.Rectangle((self.__x, self.__y), self.__width, self.__height, color=self._color)
@staticmethod
def create(color, fig):
return Rectangle(color, fig['x'], fig['y'], fig['height'], fig['width'])
class Square(Figure):
def __init__(self, color, x, y, size):
super().__init__(color)
self.__x = x
self.__y = y
self.__size = size
def artist(self):
return plt.Rectangle((self.__x, self.__y), self.__size, self.__size, color=self._color)
@staticmethod
def create(color, fig):
return Square(color, fig['x'], fig['y'], fig['size'])
class Circle(Figure):
def __init__(self, color, x, y, radius):
super().__init__(color)
self.__x = x
self.__y = y
self.__radius = radius
def artist(self):
return plt.Circle((self.__x, self.__y), radius=self.__radius, color=self._color)
@staticmethod
def create(color, fig):
return Circle(color, fig['x'], fig['y'], fig['radius'])