本文整理匯總了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)