-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFigure.py
65 lines (46 loc) · 1.54 KB
/
Figure.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
#!/usr/bin/env python3
class Figure:
def __init__(self, shape, x=0, y=0):
self.FIGURE = shape
self.COLOR = None
for i in shape[0]:
if i != 0:
self.COLOR = i
break
self.x = x
self.y = y
def print_self(self):
for row in self.FIGURE:
for col in row:
print(col, end="")
print()
def get_cw_rotation(self):
new_figure = [[None for j in range(len(self.FIGURE))]
for k in range(len(self.FIGURE[0]))]
for column in range(len(self.FIGURE[0])):
for row in range(len(self.FIGURE)):
new_figure[column][row] = self.FIGURE[row][column]
return [i[::-1] for i in new_figure]
def get_ccw_rotation(self):
new_figure = [[None for j in range(len(self.FIGURE))]
for k in range(len(self.FIGURE[0]))]
for column in range(len(self.FIGURE[0])):
for row in range(len(self.FIGURE)):
new_figure[column][row] = self.FIGURE[row][column]
return new_figure[::-1]
def rotate_cw(self):
self.FIGURE = self.get_cw_rotation()
def rotate_ccw(self):
self.FIGURE = self.get_ccw_rotation()
def move_left(self):
self.x -= 1
def move_right(self):
self.x += 1
def move_down(self):
self.y += 1
if __name__ == "__main__":
a_shape = [[1, 1, 1, 1], [0, 1, 1, 0]]
a = Figure(a_shape)
a.print_self()
a.rotate_cw()
a.print_self()