if not tile == []: # add a layer layername = "Topology_Search" poplayer = -1 for i in xrange(g.numlayers()): if g.getname(i) == layername: poplayer = i break if poplayer == -1 and g.numlayers() == g.maxlayers(): g.exit("You need to delete a layer.") if poplayer == -1: poplayer = g.addlayer() else: g.setlayer(poplayer) tilelayer = g.getlayer() g.new(layername) if not g.empty(): g.select(g.getrect()) g.clear(0) rule = g.getrule().split(':')[0] rule0 = rule rule = rule.replace('/', '-') out = 0 next = 0 posi = 0 input = g.getstring('subset?', '') poslist = input.split(',') if len(poslist) == 1:
# Use multiple layers to create a history of the current pattern. # The "envelope" layer remembers all live cells. # Author: Andrew Trevorrow ([email protected]), December 2006. # Updated for better compatibility with envelope.pl, June 2007. # Updated to use new setcolors command, September 2008. import golly as g if g.empty(): g.exit("There is no pattern.") currindex = g.getlayer() startindex = 0 envindex = 0 startname = "starting pattern" envname = "envelope" if currindex > 1 and g.getname(currindex - 1) == startname \ and g.getname(currindex - 2) == envname : # continue from where we left off startindex = currindex - 1 envindex = currindex - 2 elif currindex + 2 < g.numlayers() \ and g.getname(currindex + 1) == startname \ and g.getname(currindex) == envname : # switch from envelope layer to current layer and continue currindex += 2 g.setlayer(currindex) startindex = currindex - 1 envindex = currindex - 2
def burp(): test_signal=pattern(""" 40bo$41bo$39b3o17$40bo4bo4bo4bo4bo$41bo4bo4bo4bo4bo$39b3o2b3o2b3o2b3o 2b3o3$40bo4bo4bo4bo4bo$41bo4bo4bo4bo4bo$39b3o2b3o2b3o2b3o2b3o3$40bo4bo 4bo4bo4bo$41bo4bo4bo4bo4bo$39b3o2b3o2b3o2b3o2b3o3$40bo4bo4bo4bo4bo$41b o4bo4bo4bo4bo$39b3o2b3o2b3o2b3o2b3o3$bo38bo4bo4bo4bo4bo18bo$2bo38bo4bo 4bo4bo4bo18bo$3o36b3o2b3o2b3o2b3o2b3o16b3o37$40bo$41bo$39b3o!""") prepare_burp() ticks=0 tickstep=5 last_signal=-99999 viewport_speed=16 sel_speed=0.0 delta_sel=0.0 delay=-1.0 run_flag=False ch="" selx=600.0 sely=365.0 place_signal=3 helpstring="""Use ENTER and SPACE to run or halt the pattern; use + and - to change the step size or delay value; use arrow keys and mouse tools to pan and zoom in any pane; T toggles between a tiled view and a single-pane view; S creates another signal fleet near the detection mechanism; R resets the Heisenburp device to its initial state; Q quits out of the script and restores original settings.""" instr="Press H for help. " g.show(instr + str(tickstep)) g.select([selx,sely,50,50]) # keyboard handling while ch<>"q": if place_signal>0: if ticks-last_signal>1846: test_signal.put(-150,60) last_signal=ticks place_signal-=1 if place_signal>0 and run_flag==True: show_status_text("Next signal placement in " \ + str(1847 - ticks + last_signal) + " ticks. " + instr, delay, tickstep) else: show_status_text(instr,delay,tickstep) event = g.getevent() if event.startswith("key"): evt, ch, mods = event.split() else: ch = "" if ch=="r": prepare_burp() ticks=0 last_signal=-99999 viewport_speed=16 sel_speed=0 run_flag=False selx=600.0 sely=365.0 place_signal=3 g.select([selx,sely,50,50]) elif ch=="h": g.note(helpstring) elif ch=="t": g.setoption("tilelayers",1-g.getoption("tilelayers")) elif ch=="=" or ch=="+": if delay>.01: delay/=2 elif delay==.01: delay=-1 else: if tickstep==1: tickstep=3 elif tickstep<250: tickstep=(tickstep-1)*2+1 elif ch=="-" or ch=="_": if delay==-1: if tickstep==1: delay=.01 else: if tickstep==3: tickstep=1 else: tickstep=(tickstep-1)/2+1 else: if delay<1: delay*=2 elif ch=="space": run_flag=False elif ch=="return": run_flag=not run_flag elif ch=="s": place_signal+=1 else: # just pass any other keyboard/mouse event through to Golly g.doevent(event) # generation and selection speed handling if ch=="space" or run_flag==True: g.run(tickstep) currlayer = g.getlayer() if currlayer != 4: # user has switched layer so temporarily change it back # so we only change location of bottom right layer g.check(False) g.setlayer(4) x, y = getposint() oldticks=ticks ticks+=tickstep delta_view=int(ticks/viewport_speed) - int(oldticks/viewport_speed) if delta_view <> 0: # assumes diagonal motion for now setposint(x + delta_view, y + delta_view) sel = g.getselrect() if len(sel)<>0: x, y, w, h = sel if int(selx)<>x: # user changed selection # prepare to move new selection instead (!?!) # -- use floating-point selx, sely to account for fractional speeds selx=x sely=y else: selx+=sel_speed*tickstep sely+=sel_speed*tickstep g.select([selx, sely, w, h]) else: g.select([selx, sely, 50, 50]) if currlayer != 4: g.setlayer(currlayer) g.check(True) # change viewport speed at appropriate times to follow the action if oldticks<4570 and ticks>=4570: sel_speed=.666667 # one-time correction to catch up with the signal at high sim speeds g.select([600+(ticks-4570)*1.5, 365+(ticks-4570)*1.5, w, h]) if selx>2125: sel_speed=0 g.select([2125, sely+2125-selx, w, h]) if oldticks<4750 and ticks>=4750: viewport_speed=1.5 if oldticks<6125 and ticks>=6125: viewport_speed=16 if oldticks>=11995: viewport_speed=99999.9 # stop automatically after the last signal passes through the device if oldticks - last_signal<8705 and ticks - last_signal>=8705: run_flag=False if run_flag==True and delay>0: sleep(delay) g.update()
import os import golly as g #g.select(g.getrect()) oldrule=g.getrule() i=0 g.autoupdate(0) while i==0: g.run(1) g.save('temp','rle') g.setrule('S_input') g.run(1) cellindex=g.getlayer() execfile("histogram_2002_r75.py") histindex=g.getlayer() g.setlayer(cellindex) g.open('temp') g.setlayer(histindex) g.fit() g.update() g.setlayer(cellindex) i=+1
"\nNeed a Z and NZ line for each state, or * / ZZ syntax." ) g.exit() numstates = len(progonly) statedict = {} for i in range(0, numstates, 2): parts = progonly[i].split("; ") statedict[parts[0]] = i if g.getname()[:3] != "GPC": g.new("Compiled " + progname) GPClayer = -1 else: GPClayer = g.getlayer() g.addlayer() g.setname("Compiled " + progname) g.putcells(startpat) firstreflx, firstrefly = -1, -1 for k in range(0, numstates, 2): g.putcells(Snark_N, 184 + k * 72, -20 + k * 56) g.putcells(Snark_E, -2177 + numstates * 72 + len(outputdict) * 16, -2369 - k * 16 + numstates * 72 + len(outputdict) * 16) g.putcells( Snark_S, -7121 - k * 24 - len(outputdict) * 32 + len(outputdict) * 16 + numstates * 72, 2567 + k * 8 + len(outputdict) * 32 + len(outputdict) * 16 + numstates * 72) # The '72' above is mostly 64 per Z/NZ program row, but also 16 more cells diagonally for each state