-
Notifications
You must be signed in to change notification settings - Fork 0
/
task_class.py
120 lines (81 loc) · 2.64 KB
/
task_class.py
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import math
class Frange:
def __init__(self, start=None, stop=None, step=1):
if stop is None:
self.start = 0
self.stop = start
else:
self.start = start
self.stop = stop
self.step = step
def __iter__(self):
return self
def __next__(self):
if self.step >= 0 and self.start >= self.stop:
raise StopIteration
elif self.step <= 0 and self.start <= self.stop:
raise StopIteration
value = self.start
self.start += self.step
return value
class Colorizer:
colors = {"GREY": 90, "RED": 91, "GREEN": 92, "YELLOW": 93, "BLUE": 94, "PINK": 95, "TURQUOISE": 96}
def __init__(self, color):
self.color = Colorizer.colors.get(color, 0)
def __enter__(self):
print(f'\033[{self.color}m', end='')
def __exit__(self, exc_type, exc_val, exc_tb):
print(f'\033[0m', end='')
class Point:
def __init__(self, x=0, y=0):
self.x = x
self.y = y
class Shape:
def __init__(self, x, y):
self.x = x
self.y = y
def square(self):
return 0
class Circle(Shape):
def __init__(self, x, y, radius):
super().__init__(x, y)
self.radius = radius
def square(self):
return math.pi * self.radius ** 2
def __contains__(self, point: Point):
return True if (self.x - point.x) ** 2 + (self.y - point.y) ** 2 <= self.radius ** 2 else False
class Rectangle(Shape):
def __init__(self, x, y, height, width):
super().__init__(x, y)
self.height = height
self.width = width
def square(self):
return self.width * self.height
class Parallelogram(Rectangle):
def __init__(self, x, y, height, width, angle):
super().__init__(x, y, height, width)
self.angle = angle
def print_angle(self):
print(self.angle)
def __str__(self):
result = super().__str__()
return result + f'\nParallelogram: {self.width}, {self.height}, {self.angle}'
def __eq__(self, other):
return self.__dict__ == other.__dict__
def square(self):
return self.width * self.height * math.sin(self.angle)
class Triangle(Parallelogram):
def __init__(self, x, y, height, width, angle):
super().__init__(x, y, height, width, angle)
def square(self):
return super().square() / 2
pass
class Scene:
def __init__(self):
self._figures = []
def add_figure(self, figure):
self._figures.append(figure)
def total_square(self):
return sum(f.square() for f in self._figures)
def __str__(self):
pass