MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / display

Method display

tools/python-3.11.9-amd64/Tools/demo/life.py:89–133  ·  view source on GitHub ↗

Display the whole board, optionally computing one generation

(self, update_board=True)

Source from the content-addressed store, hash-verified

87 self.display(update_board=False)
88
89 def display(self, update_board=True):
90 """Display the whole board, optionally computing one generation"""
91 M, N = self.X, self.Y
92 if not update_board:
93 for i in range(0, M):
94 for j in range(0, N):
95 if (i, j) in self.state:
96 self.scr.addch(j + 1, i + 1, self.char)
97 else:
98 self.scr.addch(j + 1, i + 1, ' ')
99 self.scr.refresh()
100 return
101
102 d = {}
103 self.boring = 1
104 for i in range(0, M):
105 L = range(max(0, i - 1), min(M, i + 2))
106 for j in range(0, N):
107 s = 0
108 live = (i, j) in self.state
109 for k in range(max(0, j - 1), min(N, j + 2)):
110 for l in L:
111 if (l, k) in self.state:
112 s += 1
113 s -= live
114 if s == 3:
115 # Birth
116 d[i, j] = 1
117 if curses.has_colors():
118 # Let's pick a random color!
119 self.scr.attrset(curses.color_pair(
120 random.randrange(1, 7)))
121 self.scr.addch(j + 1, i + 1, self.char)
122 self.scr.attrset(0)
123 if not live:
124 self.boring = 0
125 elif s == 2 and live:
126 # Survival
127 d[i, j] = 1
128 elif live:
129 # Death
130 self.scr.addch(j + 1, i + 1, ' ')
131 self.boring = 0
132 self.state = d
133 self.scr.refresh()
134
135 def make_random(self):
136 "Fill the board with a random pattern"

Callers 2

eraseMethod · 0.95
keyloopFunction · 0.95

Calls 4

maxFunction · 0.85
minFunction · 0.85
randrangeMethod · 0.80
refreshMethod · 0.45

Tested by

no test coverage detected