本文整理汇总了Python中rule.Rule.start方法的典型用法代码示例。如果您正苦于以下问题:Python Rule.start方法的具体用法?Python Rule.start怎么用?Python Rule.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rule.Rule
的用法示例。
在下文中一共展示了Rule.start方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from rule import Rule [as 别名]
# 或者: from rule.Rule import start [as 别名]
def main(argv):
try:
options, args = getopt.getopt(argv, "r:n:c:g:f:lh", [
'rule=', 'name=', 'cell=', 'grid=', 'fill=', 'list', 'help'])
except getopt.GetoptError:
usage()
exit(2)
else:
def_grid = 350
def_cell = 10
def_alive = 'black'
def_death = 'white'
for opt, arg in sorted(options):
if opt in ('-h', '--help'):
usage()
exit(2)
elif opt in ('-l', '--list'):
plist()
elif opt in ('-c', '--cell'):
if int(arg) > 0:
def_cell = int(arg)
else:
print "Sure, cells of 0x0."
exit(2)
elif opt in ('-g', '--grid'):
if int(arg) > 0:
def_grid = int(arg)
else:
print "Good luck with a grid of 0x0."
exit(2)
elif opt in ('-f', '--fill'):
colour = arg
if colour[:colour.find(':')] != colour[colour.find(':') + 1:]:
def_alive = colour[:colour.find(':')].replace('-', ' ')
def_death = colour[colour.find(':') + 1:].replace('-', ' ')
elif opt in ('-r', '--rule'):
rule = arg
born = [int(i) for i in rule[:rule.find(':')]]
survive = [int(i) for i in rule[rule.find(':') + 1:]]
thegrid = Grid(def_grid, def_grid, def_cell, alive=def_alive,
death=def_death)
aut = Rule(thegrid, born, survive)
CellularAutomaton.generate_random(250, thegrid,
aut.get_cell_matrix(), thegrid.get_alive_colour())
aut.start()
exit(2)
elif opt in ('-n', '--name'):
name = arg
thegrid = Grid(def_grid, def_grid, def_cell, alive=def_alive,
death=def_death)
aut = CellularAutomaton.factory(name, thegrid)
CellularAutomaton.generate_random(250, thegrid,
aut.get_cell_matrix(), thegrid.get_alive_colour())
aut.start()
exit(2)
else:
usage()
exit(2)