本文整理汇总了Python中Life.Life.simulate方法的典型用法代码示例。如果您正苦于以下问题:Python Life.simulate方法的具体用法?Python Life.simulate怎么用?Python Life.simulate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Life.Life
的用法示例。
在下文中一共展示了Life.simulate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SubWindow
# 需要导入模块: from Life import Life [as 别名]
# 或者: from Life.Life import simulate [as 别名]
class SubWindow(QtGui.QScrollArea):
sequenceNumber = 1
x = 0
y = 0
timerId = 0
step = 2
delay = 50
cellsCount = 0
def __init__(self, width, height):
super(SubWindow, self).__init__()
self.width = width
self.height = height
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.isUntitled = True
widget = QtGui.QScrollArea()
self.qp = QtGui.QPainter()
if width and height:
self.field = Field(width, height)
self.setWidget(self.field)
self.life = Life(width, height, False)
self.reset()
self.field.cells = self.life.cells
def isSimulate(self):
if self.timerId:
return True
return False
def reset(self):
self.life.reset(self.width, self.height)
self.field.cells = self.life.cells
self.field.update()
if self.timerId:
self.killTimer(self.timerId)
self.timerId = 0
def changeSpeed(self, speed):
self.delay = speed
if self.timerId:
self.killTimer(self.timerId)
self.timerId = self.startTimer(speed)
def play(self):
if not self.timerId:
self.timerId = self.startTimer(self.delay)
else:
self.killTimer(self.timerId)
self.timerId = 0
def nextStep(self):
self.field.cells = self.life.simulate()
self.field.update()
def timerEvent(self, event):
self.field.cells = self.life.simulate()
self.field.update()
def currentFile(self):
return self.curFile
def new(self):
self.isUntitled = True
self.curFile = "Game %d" % SubWindow.sequenceNumber
SubWindow.sequenceNumber += 1
self.setWindowTitle(self.curFile + '[*]')
def loadFile(self, fileName):
file = QtCore.QFile(fileName)
if not file.open( QtCore.QFile.ReadOnly | QtCore.QFile.Text):
QtGui.QMessageBox.warning(self, "Reading error",
"Cannot read file %s:\n%s." % (fileName, file.errorString()))
return False
instr = QtCore.QTextStream(file)
start = False
width = 0
lines = []
while not instr.atEnd():
line = instr.readLine()
if width < len(line):
width = len(line)
if line[0] != '#':
start = True
lines.append(line)
if line[0] == '#' and start:
break
height = len(lines)
if not width or not height:
return False
self.width = width
self.height = height
self.field = Field(width, height)
self.setWidget(self.field)
self.life = Life(width, height, False)
self.field.cells = self.life.cells
y=0
for line in lines:
x = 0
#.........这里部分代码省略.........
示例2: test_simulate_3
# 需要导入模块: from Life import Life [as 别名]
# 或者: from Life.Life import simulate [as 别名]
def test_simulate_3(self):
x = Life(2, 2, [['.','.'], ['*','*']])
x.moat_grid()
x.simulate()
x.generation = 1