-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreen.py
More file actions
32 lines (25 loc) · 963 Bytes
/
screen.py
File metadata and controls
32 lines (25 loc) · 963 Bytes
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
class Screen:
def __init__(self, width, height):
self.width = width
self.height = height
self.screen = [["." for _ in range(width)] for _ in range(height)]
def __repr__(self):
return "\n".join(["".join([px for px in row]) for row in self.screen])
def rect(self, a, b):
for row in range(b):
for col in range(a):
self.screen[row][col] = "#"
def rotate_row(self, row_index, by):
self.screen[row_index] = self.screen[row_index][-by:] + self.screen[row_index][:-by]
def rotate_col(self, col_index, by):
prev = [self.screen[r][col_index] for r in range(self.height)]
for r in range(self.height):
self.screen[r][col_index] = prev[r - by]
def test():
screen = Screen(8, 6)
screen.rect(3, 2)
screen.rotate_col(0, 2)
screen.rotate_row(0, 1)
screen.rotate_row(1, 3)
print(screen)
test()