Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/cca/rev/94406d1874a2
Дата изменения: Unknown
Дата индексирования: Mon Oct 1 22:59:37 2012
Кодировка:
cca: 94406d1874a2

cca

changeset 49:94406d1874a2

repr in State, little optimized Automata, cell_size = 8, delay = 1
author darkhan
date Mon, 06 Dec 2010 12:36:59 +0300
parents dd0494c85c81
children 9cbbff6dbbaf f411a1e0a5cb
files Automata.py Interface.py State.py
diffstat 3 files changed, 9 insertions(+), 14 deletions(-) [+]
line diff
     1.1 --- a/Automata.py	Sun Dec 05 17:23:16 2010 +0300
     1.2 +++ b/Automata.py	Mon Dec 06 12:36:59 2010 +0300
     1.3 @@ -9,7 +9,7 @@
     1.4  		self.width = width
     1.5  		self.height = height
     1.6  		if states == None:
     1.7 -			self.states = [State("Dead", ' ', "white", [5]),
     1.8 +			self.states = [State("Dead", '-', "white", [5]),
     1.9  							State("Alive", '+', "black", [0, 1] + range(4, 9))]
    1.10  		else:
    1.11  			self.states = states
    1.12 @@ -24,9 +24,7 @@
    1.13  
    1.14  	def next_step(self):
    1.15  		changed = []
    1.16 -		new_state = []
    1.17  		for row in range(self.height):
    1.18 -			new_state.append([])
    1.19  			for col in range(self.width):
    1.20  				symbol = self.field[row][col]
    1.21  				num = 0
    1.22 @@ -38,16 +36,13 @@
    1.23  						horiz = horiz_long % self.width
    1.24  						if self.field[vert][horiz] == symbol:
    1.25  							num += 1
    1.26 -				new_state[row].append(
    1.27 -						self.states[self.symbols[symbol]].next_state(num - 1))
    1.28 +				if self.states[self.symbols[symbol]].next_state(num - 1):
    1.29 +					changed.append((row, col))
    1.30  						
    1.31 -		for row in range(self.height):
    1.32 -			for col in range(self.width):
    1.33 -				if new_state[row][col]:
    1.34 -					changed.append((row, col))
    1.35 -					index = (self.symbols[self.field[row][col]] + 
    1.36 +		for row, col in changed:
    1.37 +			index = (self.symbols[self.field[row][col]] + 
    1.38  														1) %  len(self.states)
    1.39 -					self.field[row][col] = self.states[index].symbol
    1.40 +			self.field[row][col] = self.states[index].symbol
    1.41  		return changed
    1.42  
    1.43  	def change_size(self, value, side):
     2.1 --- a/Interface.py	Sun Dec 05 17:23:16 2010 +0300
     2.2 +++ b/Interface.py	Mon Dec 06 12:36:59 2010 +0300
     2.3 @@ -6,7 +6,7 @@
     2.4  
     2.5  class Handlers(object):
     2.6  	
     2.7 -	def __init__(self, cell_size=10, line_width=1 ,delay=100, offset_x=0, offset_y=0):# cell_size is size of cell, including line width, if there is it
     2.8 +	def __init__(self, cell_size=8, line_width=1 ,delay=1, offset_x=0, offset_y=0):# cell_size is size of cell, including line width, if there is it
     2.9  		self.cell_size = cell_size
    2.10  		self.line_width = line_width
    2.11  		self.delay = delay
    2.12 @@ -249,7 +249,7 @@
    2.13  canvas = Canvas(root, background="grey")
    2.14  canvas.config(width=500, height=400)
    2.15  
    2.16 -automata = Automata(50, 50) 
    2.17 +automata = Automata() 
    2.18  handlers = Handlers()
    2.19  
    2.20  canvas.bind("<1>", handlers.press1)
     3.1 --- a/State.py	Sun Dec 05 17:23:16 2010 +0300
     3.2 +++ b/State.py	Mon Dec 06 12:36:59 2010 +0300
     3.3 @@ -16,4 +16,4 @@
     3.4  		return num in self.nums
     3.5  
     3.6  	def __repr__(self):
     3.7 -		return self.name + " " + self.symbol
     3.8 +		return self.symbol + " " + self.name