def paste(self, event=None): global mode global auto global paste paste = 1 mode = 3 auto = 0 #Gets clipboard and gets the coords clip = root.clipboard_get() if clip[0] == '1' and clip[-1] == '}': p = clip.split(':') display.Viewer.rule = p[0] display.Viewer.universe.rule = cca.Rule(p[0]) ppatt = eval(p[1]) elif clip[0] == 'x': p = clip.split('\n') rule = p[0].split(',')[2].split('=')[1].strip() display.Viewer.rule = rule display.Viewer.universe.rule = cca.Rule(rule) ppatt = rle2coords(''.join(p[1:])) else: ppatt = rle2coords(clip) paste = ppatt display.Viewer.grid.config(cursor='bottom_side')
def __init__(self, root): self.universe = cca.Universe(rule='1891891-2_3_2-3') self.pattern = cca.Pattern() self.rule = '1891891-2_3_2-3' self.pop = len(self.pattern) self.grid = tk.Canvas(root, bg='black', relief='sunken') self.grid.bind('<Button-1>', self.click) self.grid.pack(fill='both', expand='yes', padx=10, pady=10) self.cSize = 10 self.color = 'white'
def openCl(event=None): clip = root.clipboard_get() if clip[0] == '1': p = clip.split(':') display.Viewer.rule = p[0] display.Viewer.universe.rule = cca.Rule(p[0]) display.Viewer.pattern = eval(p[1]) else: p = clip.split('\n') rule = p[0].split(',')[2].split('=')[1].strip() display.Viewer.rule = rule display.Viewer.universe.rule = cca.Rule(rule) display.Viewer.pattern = rle2coords(''.join(p[1:]))
def step(self): simulator = cca.Simulator(self.pattern, self.universe.rule.neighborhood, self.universe.rule.birth, self.universe.rule.survival) new = simulator.step() self.pattern = new
def okay(self): if testRule(self.field.get()): display.Viewer.rule = self.field.get() display.Viewer.universe.rule = cca.Rule(self.field.get()) else: tk.messagebox.showerror("Error","Invalid rule \""+self.field.get()+"\", using current rule instead.") self.rm.destroy()
def __init__(self): self.file = tk.filedialog.askopenfilename(initialdir=filePath+'/examples', title="Open pattern...", filetypes=[("Supported pattern files","*.rle *.cca"),("All","*.*")]) if self.file != '': self.file = open(self.file,'r').read() else: self.file = 'wright stinky' if self.file[0]=='1': self.p = self.file.split(':') display.Viewer.rule = self.p[0] display.Viewer.universe.rule = cca.Rule(self.p[0]) display.Viewer.pattern = eval(self.p[1]) else: self.p = self.file.split('\n') self.rule = self.p[0].split(',')[2].split('=')[1].strip() display.Viewer.rule = self.rule display.Viewer.universe.rule = cca.Rule(self.rule) display.Viewer.pattern = rle2coords(''.join(self.p[1:]))
def clear(event=None): global auto global gens global viewx global viewy global cSize global selC1 global selC2 display.Viewer.pattern = cca.Pattern() auto = 0 gens = 0 viewx = 0 viewy = 0 cSize = 10 selC1 = () selC2 = ()
def rle2coords(rle): n = '' e = '' x = 0 y = 0 r = cca.Pattern() for c in rle: if c.isdigit(): n += c else: if n == '': n = 1 e += c * int(n) n = '' for c in e: if c == 'o' or c == 'b': if c == 'o': r.add((x, y)) x += 1 elif c == '$': y += 1 x = 0 return r