Changeset 42:ff86e9e36638
- Timestamp:
- 12/05/10 16:20:10 (5 years ago)
- Branch:
- default
- Children:
- 43:9f5aef655747, 45:ba9fa6850b45
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
Automata.py
r41 r42 ˆà 24 24 ˆà 25 25 def next_step(self):ˆà ˆà 26 changed = []ˆà 26 27 new_state = []ˆà 27 28 for row in range(self.height):ˆà òÀæ òÀæ ˆà 45 46 for col in range(self.width):ˆà 46 47 if new_state[row][col]:ˆà ˆà 48 changed.append((row, col))ˆà 47 49 self.field[row][col] = self.states[(self.symbols[symbol]ˆà 48 50 + 1) % len(self.states)].symbolˆà ˆà 51 return changedˆà 49 52 ˆà 50 53 def change_size(self, value, side):ˆà -
Interface.py
r39 r42 ˆà 7 7 class Handlers(object):ˆà 8 8 ˆà 9 ˆà def __init__(self, cell_size= 5, line_width=1 ,delay=10, 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=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ˆà 10 10 self.cell_size = cell_sizeˆà 11 11 self.line_width = line_widthˆà òÀæ òÀæ ˆà 84 84 self.draw()ˆà 85 85 ˆà ˆà 86 def draw_step(self):ˆà ˆà 87 for row, col in automata.next_step():ˆà ˆà 88 index = automata.symbols[automata.field[row][col]]ˆà ˆà 89 color = automata.states[index].colorˆà ˆà 90 canvas.itemconfig(self.cells[row][col], fill=color)ˆà ˆà 91 ˆà 86 92 def draw(self):ˆà 87 93 canvas.delete("all")ˆà ˆà 94 self.cells = []ˆà 88 95 ˆà 89 96 shift = self.cell_size + self.line_widthˆà 90 ˆà left = -self.offset_xˆà 91 ˆà top = -self.offset_xˆà 92 ˆà for row in range(automata.height + 1):ˆà 93 ˆà canvas.create_rectangle(left,ˆà 94 ˆà top + row * shift,ˆà 95 ˆà left + (automata.width) * shift + 1,ˆà 96 ˆà top + row * shift + self.line_width,ˆà 97 ˆà fill="grey", outline="")ˆà 98 ˆà for col in range(automata.width + 1):ˆà 99 ˆà canvas.create_rectangle(left + col * shift,ˆà 100 ˆà top,ˆà 101 ˆà left + col * shift + self.line_width,ˆà 102 ˆà top + (automata.height) * shift + 1,ˆà 103 ˆà fill="grey", outline="")ˆà 104 ˆà left += self.line_widthˆà 105 ˆà top += self.line_widthˆà ˆà 97 ˆà ˆà 98 left = -self.offset_x + self.line_widthˆà ˆà 99 top = -self.offset_y + self.line_widthˆà 106 100 for row in range(automata.height):ˆà ˆà 101 self.cells.append([])ˆà 107 102 for col in range(automata.width):ˆà 108 103 index = automata.symbols[automata.field[row][col]]ˆà 109 104 color = automata.states[index].colorˆà 110 ˆà c anvas.create_rectangle(left + col * shift,ˆàˆà 105 cell = canvas.create_rectangle(left + col * shift,ˆà 111 106 top + row * shift,ˆà 112 107 left + col * shift + self.cell_size,ˆà 113 108 top + row * shift + self.cell_size,ˆà 114 109 fill=color, outline="")ˆà ˆà 110 self.cells[row].append(cell)ˆà 115 111 ˆà 116 112 def press1(self, event):# drawerˆà òÀæ òÀæ ˆà 250 246 root.title("Cyclic Cellular Automata")ˆà 251 247 ˆà 252 ˆà canvas = Canvas(root, background=" white")ˆàˆà 248 canvas = Canvas(root, background="grey")ˆà 253 249 canvas.config(width=500, height=400)ˆà 254 250 ˆà
Note: See TracChangeset
for help on using the changeset viewer.