Äîêóìåíò âçÿò èç êýøà ïîèñêîâîé ìàøèíû. Àäðåñ îðèãèíàëüíîãî äîêóìåíòà : http://kodomo.cmm.msu.ru/trac/cca/changeset/42
Äàòà èçìåíåíèÿ: Unknown
Äàòà èíäåêñèðîâàíèÿ: Sun Apr 10 17:27:34 2016
Êîäèðîâêà: IBM-866
Changeset 42:ff86e9e36638 òÀÓ Cyclyc Cell Automata

Changeset 42:ff86e9e36638


Ignore:
Timestamp:
12/05/10 16:20:10 (5 years ago)
Author:
darkhan
Branch:
default
Children:
43:9f5aef655747, 45:ba9fa6850b45
Message:

New next_step in Automata and new: draw_step

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Automata.py

    r41 r42 ˆà
    2424ˆà
    2525        def next_step(self):ˆà
    ˆà26                changed = []ˆà
    2627                new_state = []ˆà
    2728                for row in range(self.height):ˆà
    òÀæ òÀæ ˆà
    4546                        for col in range(self.width):ˆà
    4647                                if new_state[row][col]:ˆà
    ˆà48                                        changed.append((row, col))ˆà
    4749                                        self.field[row][col] = self.states[(self.symbols[symbol]ˆà
    4850                                                                                        + 1) % len(self.states)].symbolˆà
    ˆà51                return changedˆà
    4952ˆà
    5053        def change_size(self, value, side):ˆà
  • Interface.py

    r39 r42 ˆà
    77class Handlers(object):ˆà
    88        ˆà
    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ˆà
    1010                self.cell_size = cell_sizeˆà
    1111                self.line_width = line_widthˆà
    òÀæ òÀæ ˆà
    8484                        self.draw()ˆà
    8585        ˆà
    ˆà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        ˆà
    8692        def draw(self):ˆà
    8793                canvas.delete("all")ˆà
    ˆà94                self.cells = []ˆà
    8895                ˆà
    8996                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ˆà
    106100                for row in range(automata.height):ˆà
    ˆà101                        self.cells.append([])ˆà
    107102                        for col in range(automata.width):ˆà
    108103                                index = automata.symbols[automata.field[row][col]]ˆà
    109104                                color = automata.states[index].colorˆà
    110ˆà                                canvas.create_rectangle(left + col * shift,ˆà
    ˆà105                                cell = canvas.create_rectangle(left + col * shift,ˆà
    111106                                                                top + row * shift,ˆà
    112107                                                                left + col * shift + self.cell_size,ˆà
    113108                                                                top + row * shift + self.cell_size,ˆà
    114109                                                                fill=color, outline="")ˆà
    ˆà110                                self.cells[row].append(cell)ˆà
    115111        ˆà
    116112        def press1(self, event):# drawerˆà
    òÀæ òÀæ ˆà
    250246root.title("Cyclic Cellular Automata")ˆà
    251247ˆà
    252ˆàcanvas = Canvas(root, background="white")ˆà
    ˆà248canvas = Canvas(root, background="grey")ˆà
    253249canvas.config(width=500, height=400)ˆà
    254250ˆà
Note: See TracChangeset for help on using the changeset viewer.