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

Method toggle

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

Toggle a cell's state between live and dead

(self, y, x)

Source from the content-addressed store, hash-verified

66 self.state[x, y] = 1
67
68 def toggle(self, y, x):
69 """Toggle a cell's state between live and dead"""
70 if x < 0 or self.X <= x or y < 0 or self.Y <= y:
71 raise ValueError("Coordinates out of range %i,%i" % (y, x))
72 if (x, y) in self.state:
73 del self.state[x, y]
74 self.scr.addch(y + 1, x + 1, ' ')
75 else:
76 self.state[x, y] = 1
77 if curses.has_colors():
78 # Let's pick a random color!
79 self.scr.attrset(curses.color_pair(random.randrange(1, 7)))
80 self.scr.addch(y + 1, x + 1, self.char)
81 self.scr.attrset(0)
82 self.scr.refresh()
83
84 def erase(self):
85 """Clear the entire board and update the board display"""

Callers 1

keyloopFunction · 0.95

Calls 2

randrangeMethod · 0.80
refreshMethod · 0.45

Tested by

no test coverage detected