def envelope(): # draw stacked layers using same location and scale g.setoption("stacklayers", 1) g.show("Hit escape key to stop script...") while True: g.run(1) if g.empty(): g.show("Pattern died out.") break # copy current pattern to envelope layer; # we temporarily disable event checking so thumb scrolling # and other mouse events won't cause confusing changes currpatt = g.getcells(g.getrect()) g.check(0) g.setlayer(envindex) g.putcells(currpatt) g.setlayer(currindex) g.check(1) step = 1 exp = g.getstep() if exp > 0: step = g.getbase()**exp if int(g.getgen()) % step == 0: # display all 3 layers (envelope, start, current) g.update()
def envelope (): # draw stacked layers using same location and scale g.setoption("stacklayers", 1) g.show("Hit escape key to stop script...") while True: g.run(1) if g.empty(): g.show("Pattern died out.") break # copy current pattern to envelope layer; # we temporarily disable event checking so thumb scrolling # and other mouse events won't cause confusing changes currpatt = g.getcells(g.getrect()) g.check(0) g.setlayer(envindex) g.putcells(currpatt) g.setlayer(currindex) g.check(1) step = 1 exp = g.getstep() if exp > 0: step = g.getbase()**exp if int(g.getgen()) % step == 0: # display all 3 layers (envelope, start, current) g.update()
# ----------------------------------------------------- def show_status_text(s, d, t): if d==-1: if t==1: g.show(s + "Speed is " + str(t) + " tick per step.") else: g.show(s + "Speed is " + str(t) + " ticks per step.") else: g.show(s + "Delay between ticks is " + str(d) + " seconds.") # ----------------------------------------------------- # if there are multiple layers, get permission to remove them if g.numlayers() > 1: answer = g.getstring("All existing layers will be removed. OK?") if lower(answer[:1]) == "n": g.exit() oldswitch = g.setoption("switchlayers", True) # allow user to switch layers oldtile = g.setoption("tilelayers", True) rule() try: burp() finally: # remove the cloned layers added by the script while g.numlayers() > 1: g.dellayer() g.setname("Stable Pseudo-Heisenburp Device") g.setoption("tilelayers", oldtile) g.setoption("switchlayers", oldswitch) g.show("")
def export_icons(iconsection, rulename): global multi_color_icons if multi_color_icons: # prepend a new @COLORS section with the average colors in each icon iconsection = create_average_colors(iconsection) + iconsection # replace any illegal filename chars with underscores filename = rulename.replace("/", "_").replace("\\", "_") # we will only create/update a .rule file in the user's rules folder # (ie. we don't modify the supplied Rules folder) rulepath = g.getdir("rules") + filename + ".rule" fileexists = os.path.isfile(rulepath) if fileexists: # .rule file already exists so replace or add @ICONS section rulefile = open(rulepath, "rU") # create a temporary file for writing new rule info temphdl, temppath = mkstemp() tempfile = open(temppath, "w") wroteicons = False skiplines = False for line in rulefile: if line.startswith("@ICONS"): # replace the existing @ICONS section tempfile.write(iconsection) wroteicons = True skiplines = True elif line.startswith("@COLORS") and multi_color_icons: # skip the existing @COLORS section # (iconsection contains a new @COLORS section) skiplines = True elif skiplines and line.startswith("@"): if wroteicons: tempfile.write("\n") skiplines = False if not skiplines: tempfile.write(line) if not wroteicons: # .rule file had no @ICONS section tempfile.write("\n") tempfile.write(iconsection) # close files rulefile.close() tempfile.flush() tempfile.close() os.close(temphdl) # remove original .rule file and rename temporary file os.remove(rulepath) move(temppath, rulepath) else: # .rule file doesn't exist so create it rulefile = open(rulepath, "w") rulefile.write("@RULE " + filename + "\n\n") if not multi_color_icons: # grayscale icons, so check if Rules/filename.rule exists # and if so copy any existing @COLORS section suppliedrule = g.getdir("app") + "Rules/" + filename + ".rule" if os.path.isfile(suppliedrule): colordata = get_color_section(suppliedrule) if len(colordata) > 0: rulefile.write(colordata) rulefile.write(iconsection) rulefile.flush() rulefile.close() # create another layer for displaying the new icons if g.numlayers() < g.maxlayers(): g.addlayer() g.new("icon test") g.setrule(rulename) for i in range(g.numstates() - 1): g.setcell(i, 0, i + 1) g.fit() g.setoption("showicons", True) g.update() if fileexists: g.note("Updated the icon data in " + rulepath) else: g.note("Created " + rulepath)
while True: event = g.getevent() if event == "key space none": break g.doevent(event) # allow keyboard/mouse interaction sleep(0.01) # avoid hogging cpu # if all patterns have been displayed then restore original algo and rule # (don't do this if user hits escape in case they want to explore pattern) g.new("untitled") g.setalgo(oldalgo) g.setrule(oldrule) # ------------------------------------------------------------------------------ # show status bar but hide other info to maximize viewport oldstatus = g.setoption("showstatusbar", True) oldtoolbar = g.setoption("showtoolbar", False) oldlayerbar = g.setoption("showlayerbar", False) oldeditbar = g.setoption("showeditbar", False) oldfiles = g.setoption("showfiles", False) try: slideshow() finally: # this code is always executed, even after escape/error; # clear message line in case there was no escape/error g.show("") # restore original state g.setoption("showstatusbar", oldstatus) g.setoption("showtoolbar", oldtoolbar) g.setoption("showlayerbar", oldlayerbar)
if grayscale_icons: deadrgb = (0, 0, 0) draw_icon_boxes(livestates, graystate) draw_icons(iconinfo31, deadrgb) draw_icons(iconinfo15, deadrgb) draw_icons(iconinfo7, deadrgb) # create missing icons by scaling up/down the existing icons if len(iconinfo31) == 0 and len(iconinfo15) > 0: create31x31icons() iconnote += "The 31x31 icons were created by scaling up the 15x15 icons.\n\n" if len(iconinfo15) == 0 and len(iconinfo31) > 0: create_smaller_icons(31, 15) iconnote += "The 15x15 icons were created by scaling down the 31x31 icons.\n\n" if len(iconinfo7) == 0: if len(iconinfo15) > 0: create_smaller_icons(15, 7) iconnote += "The 7x7 icons were created by scaling down the 15x15 icons.\n\n" elif len(iconinfo31) > 0: create_smaller_icons(31, 7) iconnote += "The 7x7 icons were created by scaling down the 31x31 icons.\n\n" g.setoption("showlayerbar", True) g.setoption("showallstates", True) g.setoption("showicons", False) g.fit() g.update() g.note(iconnote + "Edit the icons and then run icon-exporter.py.")
g.new(layername) g.setalgo("QuickLife") # qlife's setcell is faster for j in xrange(selheight): for i in xrange(selwidth): golly.show("Placing (" + str(i+1) + "," + str(j+1) + ") tile" + " in a " + str(selwidth) + " by " + str(selheight) + " rectangle.") if livecell[i][j]: ONcell.put(2048 * i - 5, 2048 * j - 5) else: OFFcell.put(2048 * i - 5, 2048 * j - 5) g.fit() g.show("") g.setalgo("HashLife") # no point running a metapattern without hashing g.setoption("hyperspeed", False) # avoid going too fast g.setbase(8) g.setstep(4) g.step() # save start and populate hash tables # g.run(35328) # run one full cycle (can lock up Golly if construction has failed) # # Note that the first cycle is abnormal, since it does not advance the metapattern by # one metageneration: the first set of communication signals to adjacent cells is # generated during this first cycle. Thus at the end of 35328 ticks, the pattern # is ready to start its first "normal" metageneration (where cell states may change). # # It should be possible to define a version of ONcell that is not fully populated # with LWSSs and HWSSs until the end of the first full cycle. This would be much # quicker to generate from a script definition, and so it wouldn't be necessary to # save it to a file. The only disadvantage is that ONcells would be visually
def dmprinter(pdy, copies=1): ''' Generate & display a dot matrix printer for named bitmap pattern ''' #Horizontal pixel separation between LineMakers. minimum = 5 LMsx = 5 #Horizontal distance between bitmap pixels. Constant, due to LineMaker period pdx = 15 #Distance between LineMakers LMdx, LMdy = -LMsx * pdx, pdy #Get bitmap pattern from current selection. bm = get_bitmap() #Make printer in a new layer golly.duplicate() golly.setoption("syncviews", False) #Build new window title from old title = golly.getname().split('.')[0] title = '%s_Printer [%d] v0.10' % (title, pdy) golly.new(title) #Make sure we're using the standard Life generation rule golly.setrule("B3/S23") #Bitmap dimensions. Width MUST be of form 4m, for m >=1 bmheight = len(bm) bmwidth = len(bm[0]) mid = (bmheight + 1) // 2 loopw = (bmwidth - 8) // 4 loopm = pdx * loopw #Gliders, heading north-east g0 = pattern('2bo$2o$b2o!') g1 = pattern('obo$2o$bo!') gliders = [ g0, g1, g1(0, 2, rccw), g0(0, 2, rccw), g0(2, 2, flip), g1(2, 2, flip), g1(2, 0, rcw), g0(2, 0, rcw) ] #Create full Glider loop. gg = [] ox, oy = 35, 23 for j in xrange(loopw + 1): dd = pdx * j gg += [ gliders[0](ox + dd, oy - dd), gliders[1](ox + 8 + dd, oy - 7 - dd) ] dd = loopm gg += [gliders[2](45 + dd, 4 - dd), gliders[3](37 + dd, -3 - dd)] ox, oy = 26 + loopm, -4 - loopm for j in xrange(loopw + 1): dd = pdx * j gg += [ gliders[4](ox - dd, oy + dd), gliders[5](ox - 8 - dd, oy + 7 + dd) ] dd = loopm gg += [gliders[6](16, 15), gliders[7](24, 22)] parity = 2 * ((loopw + 1) * (0, 0) + (1, 1)) def buildLM(): ''' Build a complete LineMaker ''' #Populate glider loop. (jj, ii) are bitmap coords gloop = pattern() for j in xrange(bmwidth): jj = (j - delta + bmwidth - 1) % bmwidth #Is there a pixel at this location? if bm[ii][jj] == parity[j]: gloop += gg[j] #Add glider to the loop #Only put LineMaker if glider loop isn't empty if len(gloop) > 0: (LMBlank + gloop).put(Lx, Ly, trans) #Assemble blank LineMaker LMBlank = linemaker(loopm) #Do upper LineMakers trans = identity for i in xrange(mid): ii = mid - (i + 1) io = mid + (i + 1) Lx, Ly = io * LMdx, ii * LMdy delta = LMsx * io buildLM() #Do lower LineMakers trans = flip_y for i in xrange(mid, bmheight): ii = i io = i + 2 Lx, Ly = io * LMdx + pdx, ii * LMdy + 128 delta = LMsx * io - 1 buildLM() #Eaters facing south-east & north-east eaterSE = pattern('2o$bo$bobo$2b2o!') eaterNE = eaterSE(0, 10, flip_y) eY = 59 eaters = (eaterNE(0, eY), eaterSE(0, eY)) #Eater horizontal displacement. Must be odd #bmwidth muliplier determines number of copies visible 'outside' printer. eX = (bmheight + 1) * LMdx - (copies * bmwidth - 1) * pdx eX = 1 + eX // 2 * 2 #Adjust parity all = pattern() for i in xrange(bmheight): all += eaters[i % (1 + LMsx % 2)](eX, i * LMdy) all.put() #Centre view over bitmap output area golly.setpos(str(-pdx * bmwidth // 2 + (bmheight - 1) * LMdx), str(Ly // 2)) #golly.setmag(-2) #Aliasing effects happen at smaller scales than -2 :( golly.fit()
currpatt = g.getcells(g.getrect()) g.check(0) g.setlayer(envindex) g.putcells(currpatt) g.setlayer(currindex) g.check(1) step = 1 exp = g.getstep() if exp > 0: step = g.getbase()**exp if int(g.getgen()) % step == 0: # display all 3 layers (envelope, start, current) g.update() # ------------------------------------------------------------------------------ # show status bar but hide layer & edit bars (faster, and avoids flashing) oldstatus = g.setoption("showstatusbar", True) oldlayerbar = g.setoption("showlayerbar", False) oldeditbar = g.setoption("showeditbar", False) try: envelope() finally: # this code is always executed, even after escape/error; # restore original state of status/layer/edit bars g.setoption("showstatusbar", oldstatus) g.setoption("showlayerbar", oldlayerbar) g.setoption("showeditbar", oldeditbar)
if grayscale_icons: deadrgb = (0,0,0) draw_icon_boxes(livestates, graystate) draw_icons(iconinfo31, deadrgb) draw_icons(iconinfo15, deadrgb) draw_icons(iconinfo7, deadrgb) # create missing icons by scaling up/down the existing icons if len(iconinfo31) == 0 and len(iconinfo15) > 0: create31x31icons() iconnote += "The 31x31 icons were created by scaling up the 15x15 icons.\n\n" if len(iconinfo15) == 0 and len(iconinfo31) > 0: create_smaller_icons(31, 15) iconnote += "The 15x15 icons were created by scaling down the 31x31 icons.\n\n" if len(iconinfo7) == 0: if len(iconinfo15) > 0: create_smaller_icons(15, 7) iconnote += "The 7x7 icons were created by scaling down the 15x15 icons.\n\n" elif len(iconinfo31) > 0: create_smaller_icons(31, 7) iconnote += "The 7x7 icons were created by scaling down the 31x31 icons.\n\n" g.setoption("showlayerbar",True) g.setoption("showallstates",True) g.setoption("showicons",False) g.fit() g.update() g.note(iconnote + "Edit the icons and then run icon-exporter.py.")
genlist.append( int(g.getgen()) ) newsecs = time() if newsecs - oldsecs >= 1.0: # show pattern every second oldsecs = newsecs fit_if_not_visible() g.update() g.show("Step %i of %i" % (i+1, numsteps)) fit_if_not_visible() # save some info before we switch layers stepsize = "%i^%i" % (g.getbase(), g.getstep()) pattname = g.getname() # create population plot in separate layer g.setoption("stacklayers", 0) g.setoption("tilelayers", 0) g.setoption("showlayerbar", 1) if poplayer == -1: poplayer = g.addlayer() else: g.setlayer(poplayer) g.new(layername) # use same rule but without any suffix (we don't want a bounded grid) g.setrule(g.getrule().split(":")[0]) deadr, deadg, deadb = g.getcolor("deadcells") if (deadr + deadg + deadb) / 3 > 128: # use black if light background g.setcolors([1,0,0,0])
eX = 1 + eX // 2 * 2 all = pattern() for i in xrange(bmheight): all += eaters[i % (1 + LMsx % 2)](eX, i * LMdy) all.put() golly.setpos(str(-pdx * bmwidth // 2 + (bmheight - 1) * LMdx), str(Ly//2)) golly.fit() #golly.setcursor(3) """ if __name__ == '__main__': title = golly.getname().split('.')[0] + '-printer' prog = "bits = '%s'\n%s" % (get_bitmap(), prog) exec compile(prog, '<string>', 'exec') golly.duplicate() golly.setoption("syncviews", False) main(16, 1, title) #Save pattern as a Python program hdr = '#Golly Python script\nimport golly\nfrom glife import *\n' ftr = "main(16, 1, '%s')" % title s = """#Golly Python script import zlib,base64 s=zlib.decompress(base64.decodestring(''' %s''')) try:import golly except ImportError:print s else: from glife import * exec compile(s,'<string>','exec') main(16, 1, '%s')
g.check(0) g.setlayer(envindex) g.putcells(currpatt) g.setlayer(currindex) g.check(1) step = 1 exp = g.getstep() if exp > 0: step = g.getbase()**exp if int(g.getgen()) % step == 0: # display all 3 layers (envelope, start, current) g.update() # ------------------------------------------------------------------------------ # show status bar but hide layer & edit bars (faster, and avoids flashing) oldstatus = g.setoption("showstatusbar", True) oldlayerbar = g.setoption("showlayerbar", False) oldeditbar = g.setoption("showeditbar", False) try: envelope() finally: # this code is always executed, even after escape/error; # restore original state of status/layer/edit bars g.setoption("showstatusbar", oldstatus) g.setoption("showlayerbar", oldlayerbar) g.setoption("showeditbar", oldeditbar)
import golly as g import hashlib import os libpath = g.getdir("data") + "recognizer-library/" if not os.path.isdir(libpath): os.makedirs(libpath) # for filename in os.listdir(libpath): # g.note(filename) # g.exit oldsavexrle = g.setoption("savexrle", 1) xformlist = [[1, 0, 0, 1], [0, -1, 1, 0], [-1, 0, 0, -1], [0, 1, -1, 0], [0, 1, 1, 0], [1, 0, 0, -1], [0, -1, -1, 0], [-1, 0, 0, 1]] xformnames = [ "identity", "rcw", "flip", "rccw", "swap_xy", "flip_y", "swap_xy_flip", "flip_x" ] # for glife script g.setrule("B3/S23") # returns a cell list sorted into TL/BR order def cellsort(clist): return g.evolve(clist, 0) def findTL(clist): return findTLsorted(cellsort(clist)) # version of findTL() for cell lists already known to be in TL/BR order
def export_icons(iconsection, rulename): global multi_color_icons if multi_color_icons: # prepend a new @COLORS section with the average colors in each icon iconsection = create_average_colors(iconsection) + iconsection # replace any illegal filename chars with underscores filename = rulename.replace("/","_").replace("\\","_") # we will only create/update a .rule file in the user's rules folder # (ie. we don't modify the supplied Rules folder) rulepath = g.getdir("rules") + filename + ".rule" fileexists = os.path.isfile(rulepath) if fileexists: # .rule file already exists so replace or add @ICONS section rulefile = open(rulepath,"rU") # create a temporary file for writing new rule info temphdl, temppath = mkstemp() tempfile = open(temppath,"w") wroteicons = False skiplines = False for line in rulefile: if line.startswith("@ICONS"): # replace the existing @ICONS section tempfile.write(iconsection) wroteicons = True skiplines = True elif line.startswith("@COLORS") and multi_color_icons: # skip the existing @COLORS section # (iconsection contains a new @COLORS section) skiplines = True elif skiplines and line.startswith("@"): if wroteicons: tempfile.write("\n") skiplines = False if not skiplines: tempfile.write(line) if not wroteicons: # .rule file had no @ICONS section tempfile.write("\n") tempfile.write(iconsection) # close files rulefile.close() tempfile.flush() tempfile.close() os.close(temphdl) # remove original .rule file and rename temporary file os.remove(rulepath) move(temppath, rulepath) else: # .rule file doesn't exist so create it rulefile = open(rulepath,"w") rulefile.write("@RULE " + filename + "\n\n") if not multi_color_icons: # grayscale icons, so check if Rules/filename.rule exists # and if so copy any existing @COLORS section suppliedrule = g.getdir("app") + "Rules/" + filename + ".rule" if os.path.isfile(suppliedrule): colordata = get_color_section(suppliedrule) if len(colordata) > 0: rulefile.write(colordata) rulefile.write(iconsection) rulefile.flush() rulefile.close() # create another layer for displaying the new icons if g.numlayers() < g.maxlayers(): g.addlayer() g.new("icon test") g.setrule(rulename) for i in xrange(g.numstates()-1): g.setcell(i, 0, i+1) g.fit() g.setoption("showicons",True) g.update() if fileexists: g.note("Updated the icon data in " + rulepath) else: g.note("Created " + rulepath)
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()
event = g.getevent() if event == "key space none": break g.doevent(event) # allow keyboard/mouse interaction sleep(0.01) # avoid hogging cpu # if all patterns have been displayed then restore original algo and rule # (don't do this if user hits escape in case they want to explore pattern) g.new("untitled") g.setalgo(oldalgo) g.setrule(oldrule) # ------------------------------------------------------------------------------ # show status bar but hide other info to maximize viewport oldstatus = g.setoption("showstatusbar", True) oldtoolbar = g.setoption("showtoolbar", False) oldlayerbar = g.setoption("showlayerbar", False) oldeditbar = g.setoption("showeditbar", False) oldfiles = g.setoption("showfiles", False) try: slideshow() finally: # this code is always executed, even after escape/error; # clear message line in case there was no escape/error g.show("") # restore original state g.setoption("showstatusbar", oldstatus) g.setoption("showtoolbar", oldtoolbar) g.setoption("showlayerbar", oldlayerbar)
sleep(0.01) # avoid hogging cpu if "CVS" in dirs: dirs.remove("CVS") # don't visit CVS directories # if all patterns have been displayed then restore original algo and rule # (don't do this if user hits escape in case they want to explore pattern) g.new("untitled") g.setalgo(oldalgo) g.setrule(oldrule) # ------------------------------------------------------------------------------ # show status bar but hide other info to maximize viewport oldstatus = g.setoption("showstatusbar", True) oldtoolbar = g.setoption("showtoolbar", False) oldlayerbar = g.setoption("showlayerbar", False) oldeditbar = g.setoption("showeditbar", False) oldscripts = g.setoption("showscripts", False) oldpatterns = g.setoption("showpatterns", False) try: slideshow() finally: # this code is always executed, even after escape/error; # clear message line in case there was no escape/error g.show("") # restore original state g.setoption("showstatusbar", oldstatus) g.setoption("showtoolbar", oldtoolbar)
g.doevent(event) # allow keyboard/mouse interaction sleep(0.01) # avoid hogging cpu if "CVS" in dirs: dirs.remove("CVS") # don't visit CVS directories # if all patterns have been displayed then restore original algo and rule # (don't do this if user hits escape in case they want to explore pattern) g.new("untitled") g.setalgo(oldalgo) g.setrule(oldrule) # ------------------------------------------------------------------------------ # show status bar but hide other info to maximize viewport oldstatus = g.setoption("showstatusbar", True) oldtoolbar = g.setoption("showtoolbar", False) oldlayerbar = g.setoption("showlayerbar", False) oldeditbar = g.setoption("showeditbar", False) oldscripts = g.setoption("showscripts", False) oldpatterns = g.setoption("showpatterns", False) try: slideshow() finally: # this code is always executed, even after escape/error; # clear message line in case there was no escape/error g.show("") # restore original state g.setoption("showstatusbar", oldstatus) g.setoption("showtoolbar", oldtoolbar)
g.setalgo("QuickLife") # qlife's setcell is faster for j in xrange(selheight): for i in xrange(selwidth): golly.show("Placing (" + str(i + 1) + "," + str(j + 1) + ") tile" + " in a " + str(selwidth) + " by " + str(selheight) + " rectangle.") if livecell[i][j]: ONcell.put(2048 * i - 5, 2048 * j - 5) else: OFFcell.put(2048 * i - 5, 2048 * j - 5) g.fit() g.show("") g.setalgo("HashLife") # no point running a metapattern without hashing g.setoption("hyperspeed", False) # avoid going too fast g.setbase(8) g.setstep(4) g.step() # save start and populate hash tables # g.run(35328) # run one full cycle (can lock up Golly if construction has failed) # # Note that the first cycle is abnormal, since it does not advance the metapattern by # one metageneration: the first set of communication signals to adjacent cells is # generated during this first cycle. Thus at the end of 35328 ticks, the pattern # is ready to start its first "normal" metageneration (where cell states may change). # # It should be possible to define a version of ONcell that is not fully populated # with LWSSs and HWSSs until the end of the first full cycle. This would be much # quicker to generate from a script definition, and so it wouldn't be necessary to # save it to a file. The only disadvantage is that ONcells would be visually
g.show("Counting cell states... %.2f%%" % done) g.dokey(g.getkey()) statecount = [int(10 * math.log((x + 1), 2)) for x in statecount] totalcells = sum(statecount) if statecount[0] == counted: g.exit("Selection is empty.") # save current layer's info before we switch layers currname = g.getname() currcursor = g.getcursor() currcolors = g.getcolors() currstates = g.numstates() deads, deadr, deadg, deadb = g.getcolors(0) # create histogram in separate layer g.setoption("stacklayers", 0) g.setoption("tilelayers", 0) g.setoption("showlayerbar", 1) if histlayer == -1: histlayer = g.addlayer() else: g.setlayer(histlayer) g.new(histname) g.setcursor(currcursor) # use a Generations rule so we can append extra state for drawing text & lines g.setrule("//" + str(currstates + 1)) extrastate = currstates currcolors.append(extrastate) if (deadr + deadg + deadb) / 3 > 128:
# Slow glider page, for Mozilla CA presentation import golly as g from glife.base import glider, flip_x import time # Conway's Life g.setrule("B3/S23") glider.display("Slow Glider", x=-20, y=20, A = flip_x) g.setpos('0', '0') g.setoption('fullscreen', True) g.setstep(0) while True: time.sleep(.5) g.step() g.update()