def GunArea(cells, curGunPeriod): maxBox = [10000, 10000, -1000, -1000] for i in xrange(0, curGunPeriod, 4): g.new(str(i)) g.putcells(g.evolve(cells, i)) g.setbase(8) g.setstep(3) g.step() g.step() g.step() g.step() edgeGlider = EdgeGlider() while PerformDelete(edgeGlider, curGunPeriod): edgeGlider = DevolveGlider(edgeGlider, curGunPeriod) for j in xrange(0, 4): maxBox = AppendBox(maxBox, g.getrect()) g.run(1) if i == 0: somegun = g.getcells(g.getrect()) return [BoxValue(maxBox), somegun, maxBox]
def gofast(newgen, delay): ''' Fast goto ''' #Save current settings oldbase = g.getbase() # oldhash = g.setoption("hashing", True) g.show('gofast running, hit escape to abort') oldsecs = time() #Advance by binary powers, to maximize advantage of hashing g.setbase(2) for i, b in enumerate(intbits(newgen)): if b: g.setstep(i) g.step() g.dokey(g.getkey()) newsecs = time() if newsecs - oldsecs >= delay: # do an update every sec oldsecs = newsecs g.update() if g.empty(): break g.show('') #Restore settings # g.setoption("hashing", oldhash) g.setbase(oldbase)
def GunArea(cells, curGunPeriod): maxBox = [] minpop = -100000 for i in xrange(0, curGunPeriod, 4): g.new(str(i)) g.putcells(g.evolve(cells, i)) g.setbase(8) g.setstep(3) g.step() g.step() edgeGlider = EdgeGlider() while PerformDelete(edgeGlider, curGunPeriod): edgeGlider = DevolveGlider(edgeGlider, curGunPeriod) for j in xrange(0, 4): if g.getpop() > minpop: maxpop = g.getpop() maxpopgun = g.getcells(g.getrect()) maxBox = AppendBox(maxBox, g.getrect()) g.run(1) return [BoxValue(maxBox), maxpopgun, maxBox]
def GotoLimited(gen, power): g.setbase(8) g.setstep(power) while gen > int(g.getgen()) + g.getbase()**power: g.step() g.update() goto(gen)
def main(): #Vertical distance between pixels. Maybe get this from user. minimum = 16 pdy = 16 #Generate & display a dot matrix printer from current selection dmprinter(pdy, copies=1) golly.setcursor("Zoom In") golly.setalgo("HashLife") golly.setbase(2) golly.setstep(6)
def AdaptiveGoto(hwssRecipe, enablePrinting=True): #g.setrule("LifeHistory") fense50 = g.parse( "F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F!" ) helixD = CalcHelix(hwssRecipe) curgen = -helixD * 2 curgen += 2 * distForward goto(curgen) g.setbase(8) g.setstep(3) delta = 10 lastmaxi = delta idx = 0 for i in hwssRecipe: if enablePrinting and (100 * (idx + 1)) / len(hwssRecipe) != ( 100 * idx) / len(hwssRecipe): percent = (100 * (idx + 1)) / len(hwssRecipe) g.update() g.show("Iterating forward progress " + str(percent) + "%") curgen += 2 * distForward idx += 1 while int(g.getgen()) < curgen: g.step() if i == 'SKIP': continue if i > lastmaxi: g.select([fenseX, helixD + fenseY + lastmaxi - delta, 1, delta]) g.clear(0) lastmaxi += delta #g.update() if i < lastmaxi - delta: g.putcells(fense50, fenseX, helixD + fenseY + lastmaxi - 2 * delta) lastmaxi -= delta
def AdaptiveGoto(hwssRecipe, enablePrinting = True): #g.setrule("LifeHistory") fense50 = g.parse("F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F$F!") helixD = CalcHelix(hwssRecipe) curgen = -helixD * 2 curgen += 2 * distForward goto(curgen) g.setbase(8) g.setstep(3) delta = 10 lastmaxi = delta idx = 0 for i in hwssRecipe: if enablePrinting and (100 * (idx + 1)) / len(hwssRecipe) != (100 * idx) / len(hwssRecipe): percent = (100 * (idx + 1)) / len(hwssRecipe) g.update() g.show("Iterating forward progress " + str(percent) + "%") curgen += 2 * distForward idx += 1 while int(g.getgen()) < curgen: g.step() if i == 'SKIP': continue if i > lastmaxi: g.select([fenseX, helixD + fenseY + lastmaxi - delta, 1, delta]) g.clear(0) lastmaxi += delta #g.update() if i < lastmaxi - delta: g.putcells(fense50, fenseX, helixD + fenseY + lastmaxi - 2 * delta) lastmaxi -= delta
def find_all_glider_idx(mask): idxs = extract_indexes(mask) idxs.sort(key=lambda idx: (1.01 * gliders_in[idx][0] + gliders_in[idx][1])) copy_idxs = idxs[:] for edge_i in enum_shooters(mask): reaction_cells = shoot_defs[edge_i][4] stable_cells = shoot_defs[edge_i][5] for g_i in list(copy_idxs): g.new("") for g_j in idxs: x, y, idx = gliders_in[g_j] if g_j == g_i: g.putcells(g.evolve(reaction_cells, idx), x, y) else: g.putcells(g.evolve(gld, idx), x - 128, y + 128) g.setbase(8) g.setstep(3) g.step() x, y, _ = gliders_in[g_i] # test if the pattern consists of the stable cells plus the # necessary gliders and nothing else g.putcells(stable_cells, x, y, 1, 0, 0, 1, "xor") if int(g.getpop()) != 5 * len(idxs): continue for g_j in idxs: x, y, idx = gliders_in[g_j] g.putcells(g.evolve(gld, idx), x, y, 1, 0, 0, 1, "xor") if g.empty(): copy_idxs.remove(g_i) yield g_i,edge_i
def PeriodCalculator(): g.setbase(8) g.setstep(3) g.step() g.step() cells = g.getrect() rect = g.getrect() cells = g.getcells(rect) for i in xrange(0, 10000): g.run(1) if str(g.getcells(rect)) == str(cells): #g.show(str(i + 1)) #g.reset return i + 1 return -1
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 # indistinguishable from OFFcells until after the initial construction phase.
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 # indistinguishable from OFFcells until after the initial construction phase.