Changeset 49:94406d1874a2
- Timestamp:
- 12/06/10 12:36:59 (5 years ago)
- Branch:
- default
- Children:
- 50:9cbbff6dbbaf, 51:f411a1e0a5cb
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
Automata.py
r47 r49 ˆà 10 10 self.height = heightˆà 11 11 if states == None:ˆà 12 ˆà self.states = [State("Dead", ' ˆà 12 self.states = [State("Dead", '-', "white", [5]),ˆà 13 13 State("Alive", '+', "black", [0, 1] + range(4, 9))]ˆà 14 14 else:ˆà òÀæ òÀæ ˆà 25 25 def next_step(self):ˆà 26 26 changed = []ˆà 27 ˆà new_state = []ˆà28 27 for row in range(self.height):ˆà 29 ˆà new_state.append([])ˆà30 28 for col in range(self.width):ˆà 31 29 symbol = self.field[row][col]ˆà òÀæ òÀæ ˆà 39 37 if self.field[vert][horiz] == symbol:ˆà 40 38 num += 1ˆà 41 ˆà new_state[row].append(ˆà42 ˆà self.states[self.symbols[symbol]].next_state(num - 1))ˆàˆà 39 if self.states[self.symbols[symbol]].next_state(num - 1):ˆà ˆà 40 changed.append((row, col))ˆà 43 41 ˆà 44 ˆà for row in range(self.height):ˆà 45 ˆà for col in range(self.width):ˆà 46 ˆà if new_state[row][col]:ˆà 47 ˆà changed.append((row, col))ˆà 48 ˆà index = (self.symbols[self.field[row][col]] + ˆà ˆà 42 for row, col in changed:ˆà ˆà 43 index = (self.symbols[self.field[row][col]] + ˆà 49 44 1) % len(self.states)ˆà 50 ˆà ˆà 45 self.field[row][col] = self.states[index].symbolˆà 51 46 return changedˆà 52 47 ˆà -
Interface.py
r48 r49 ˆà 7 7 class Handlers(object):ˆà 8 8 ˆà 9 ˆà 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ˆàˆà 9 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ˆà 10 10 self.cell_size = cell_sizeˆà 11 11 self.line_width = line_widthˆà òÀæ òÀæ ˆà 250 250 canvas.config(width=500, height=400)ˆà 251 251 ˆà 252 ˆà automata = Automata( 50, 50) ˆàˆà 252 automata = Automata() ˆà 253 253 handlers = Handlers()ˆà 254 254 ˆà -
State.py
r38 r49 ˆà 17 17 ˆà 18 18 def __repr__(self):ˆà 19 ˆà return self. name + " " + self.symbolˆàˆà 19 return self.symbol + " " + self.nameˆà
Note: See TracChangeset
for help on using the changeset viewer.