-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpascal.py
90 lines (66 loc) · 2.01 KB
/
pascal.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
import time
class Tile():
def __init__(self, r, g, b):
self.color = [r, g, b]
def add(self, t, n):
r = self.color[0] + t.color[0]
g = self.color[1] + t.color[1]
b = self.color[2] + t.color[2]
c = [r, g, b]
minval = min(c)
diff = max(c) - minval
c = [i-minval for i in c]
c = [i/diff for i in c]
c = [i * 255 for i in c]
return Tile(*c)
def drawTile(self):
# print(self.color, end = '')
return self.color
class Pascal():
def __init__(self, n = 3):
# self.arr = [
# [1],
# [1, 1],
# [1, 2, 1]
# ]
self.arr = [
[Tile(254, 254, 254)],
[Tile(254, 254, 254), Tile(254, 254, 254)],
[Tile(10, 20, 10), Tile(5, 10, 15), Tile(20, 10, 5)]
]
# print(type(self.arr[0][0]))
self.n = n
self.generate()
def print_pascal(self):
for i in self.arr:
print(*i)
def print_tiles(self):
for i in self.arr:
for j in i:
j.drawTile()
print()
def generate(self):
nt = 2
if self.n <= 3:
self.arr = self.arr[:self.n]
else:
ptr = 1
while nt < self.n:
# newarr = [1]
newarr = [Tile(80, 10, 100)]
while ptr < len(self.arr[-1]):
# newarr.append(self.arr[nt][ptr] + self.arr[nt][ptr-1])
newarr.append(self.arr[nt][ptr].add(self.arr[nt][ptr-1], self.n))
ptr += 1
# newarr.append(1)
newarr.append(Tile(0, 69, 60))
self.arr.append(newarr)
nt += 1
ptr = 1
def getTriangle(self):
return self.arr
# if __name__ == '__main__':
# start_time = time.time()
# triangle = Pascal(10)
# print("--- %s seconds ---" % (time.time() - start_time))
# triangle.print_tiles()