def slideshow (): oldalgo = g.getalgo() oldrule = g.getrule() message = "Hit space to continue or escape to exit the slide show..." g.show(message) for root, dirs, files in os.walk(g.getdir("app") + "Patterns"): for name in files: if name.startswith("."): # ignore hidden files (like .DS_Store on Mac) pass else: fullname = join(root, name) g.open(fullname, False) # don't add file to Open/Run Recent submenu g.update() if name.endswith(".pl") or name.endswith(".py"): # reshow message in case it was changed by script g.show(message) 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 "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)
def slideshow(): oldalgo = g.getalgo() oldrule = g.getrule() message = "Hit space to continue or escape to exit the slide show..." g.show(message) for root, dirs, files in os.walk(g.getdir("app") + "Patterns"): for name in files: if name.startswith("."): # ignore hidden files (like .DS_Store on Mac) pass else: g.new("") g.setalgo("QuickLife") # nicer to start from this algo fullname = join(root, name) g.open(fullname, False) # don't add file to Open/Run Recent submenu g.update() if name.endswith(".lua") or name.endswith(".py"): # reshow message in case it was changed by script g.show(message) 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)
def paste(g, fichier, x, y): g.addlayer() g.open(fichier) g.select([-1000, -1000, 2000, 2000]) g.copy() g.dellayer() g.paste(x - 1000, y - 1000, 'or')
def write(asm): binary = translateAll(asm) g.open("computer.mc") g.duplicate() g.setname("programmed", 0) g.movelayer(1, 0) g.dellayer() g.select([-25950, 1890, 450, 240]) g.cut() for i in range(len(binary)): for j in range(21): if int(binary[i][j]): g.select([-23639+i*600+j*300, 2159+i*600-j*300, 450, 240]) g.clear(0) g.paste(-23639+i*600+j*300, 2159+i*600-j*300, "or")
for item in readmelist: period, size, basegun = item.replace("\n", "").split(" ") basegun = basegun.replace("'", "").replace(")", "") bb, usebb = [], 0 # g.note(str([basegun+"_special_p" + ("0000"+period)[-5:], (basegun+"_special_p" + ("0000"+period)[-5:] in specialguns)])) if basegun == "fixed" or basegun + "_special_p" + ( "0000" + period)[-5:] in specialguns: if basegun == "fixed": fixedname = "p" + ("0000" + period)[-5:] folder = fixedfolder else: # g.note(basegun) ################# fixedname = basegun + "_special_p" + ("0000" + period)[-5:] + ",0,0,0" folder = specialfolder g.open(os.path.join(folder, fixedname + ".rle")) bb = g.getrect() usebb = 1 g.setrule("LifeHistoryToLife") g.run(1) g.setrule("Life") if basegun == "fixed": g.save(os.path.join(outfolder, fixedname) + "_fixed.rle", "rle") g.show("[fixed]") countfixed += 1 else: g.save( os.path.join(outfolder, "p" + ("0000" + period)[-5:] + "_custom") + ".rle", "rle") countspecial += 1
g.save(path.join(dir, str(step) + "_" + str(period) + "_Back.rle"), "rle", False) #''' #This code synchronize the backward recipes to fit with forward created at 0,0 g.show("synchronize the backward recipes to fit with forward") g.new("") MakeForwardSalvo(step, 0, 0, 0, True, True) forwardRecipe = FindWssByDirection(True, distForward) x0, y0, id = forwardRecipe[0] ConvertToRelative(forwardRecipe, distForward) g.open(path.join(dir, str(step) + "_" + str(period) + "_Back.rle"), False) rect = g.getrect() cells = g.getcells([rect[0], rect[1], rect[2], 4 * distBack]) g.new("") g.putcells(cells) for i in xrange(4): cRecipe = FindWssByDirection(True, distForward) x1, y1, id1 = cRecipe[0] ConvertToRelative(cRecipe, distForward) if str(forwardRecipe) == str(cRecipe): break
from glife import * import golly as g import os import time pattern_fp = None if ("outfilename" in os.environ): pattern_fp = os.environ["outfilename"] g.open(os.environ["outfilename"]) if pattern_fp: fpath = pattern_fp else: fpath = g.getpath() dirpath = os.path.dirname(fpath) basename = os.path.basename(fpath) timestr = time.strftime("%Y%m%d-%H%M%S") backuppath = os.path.join(dirpath, "backups", basename[:-3] + "_" + timestr + ".mc") g.show(backuppath) g.save(backuppath,"mc") bitOff = pattern('4.DBD$5.B$4.2B$5.D$D.B2.F2.3D$3BD2FD4B$D4.D2.3D$5.B$4.DBD$4.DBD$4.DBD!') bitOn = pattern('4.DBD$5.B.B$4.2B.2B$5.D.2D$D.B2.F.D2.D$3BD2FDF.2B$D4.D2.B.D$5.B2.B$4.DBD$4.DBD$4.DBD!') bitOffRedLin = pattern('4.DBD$5.B$4.2B$5.D$D.B2.F2.3D$3BD2FD4B$D4.D2.3D$5.B$4.DBD$4.DBD$3F.DBD.3F!') bitOnRedLine = pattern('4.DBD$5.B.B$4.2B.2B$5.D.2D$D.B2.F.D2.D$3BD2FDF.2B$D4.D2.B.D$5.B2.B$4.DBD$4.DBD$3F.DBD.3F!') bitOffHorzLine = pattern('4.DBD$.F3.B$.F2.2B$5.D$D.B2.F2.3D$3BD2FD4B$D4.D2.3D$5.B$.F2.DBD$.F2.DBD$4.DBD!') bitOnHorzLine = pattern('4.DBD$.F3.B.B$.F2.2B.2B$5.D.2D$D.B2.F.D2.D$3BD2FDF.2B$D4.D2.B.D$5.B2.B$.F2.DBD$.F2.DBD$4.DBD!')
import golly as g """ generates a adaptator between 2 streams of gliders with a delta*15 pixels diagonal shift """ delta = 2 ref2 = [0, -60, 11, 23] ref3 = [30, -60, 23, 11] ref4 = [60, -60, 23, 11] d1 = delta * 15 + 9 d2 = 0 d3 = 9 g.open("reflecteur.mc") # 2eme reflecteur g.select(ref2) g.cut() g.run(29 + 4 * d1) g.paste(-19 - d1, 16 + d1, "or") # 3eme reflecteur g.select(ref3) g.cut() g.run(4 * d1) g.run(4 + 4 * d2) g.paste(d2 + 1 - d1, 34 + d2 + d1, "or") # 4eme reflecteur
g.clear(1) g.save(path.join(dir, str(step) + "_" + str(period) + "_Back.rle"), "rle", False) #''' #This code synchronize the backward recipes to fit with forward created at 0,0 g.show("synchronize the backward recipes to fit with forward") g.new("") MakeForwardSalvo(step, 0, 0, 0, True, True) forwardRecipe = FindWssByDirection(True, distForward) x0, y0, id = forwardRecipe[0] ConvertToRelative(forwardRecipe, distForward) g.open(path.join(dir, str(step) + "_" + str(period) + "_Back.rle"), False) rect = g.getrect() cells = g.getcells([rect[0], rect[1], rect[2], 4 * distBack]) g.new("") g.putcells(cells) for i in xrange(4): cRecipe = FindWssByDirection(True, distForward) x1, y1, id1 = cRecipe[0] ConvertToRelative(cRecipe, distForward) if str(forwardRecipe) == str(cRecipe): break
if tuple( pattern.ravel().tolist() ) not in memo: #If we haven't seen this type of pattern before, let's remember it if pattern.shape[0] == 2: #Pattern is a leaf, write leaf line outfile.write('{} {} {} {} {}\n'.format( pattern.shape[0].bit_length() + 10, pattern[0, 0], pattern[0, 1], pattern[1, 0], pattern[1, 1])) else: #Pattern is a branch, keep going down quadtree subpatterns = pattern.reshape(2, pattern.shape[0] >> 1, 2, pattern.shape[0] >> 1).swapaxes( 1, 2) outfile.write('{} {} {} {} {}\n'.format( pattern.shape[0].bit_length() + 10, createLine(subpatterns[0, 0], outfile), createLine(subpatterns[0, 1], outfile), createLine(subpatterns[1, 0], outfile), createLine(subpatterns[1, 1], outfile))) memo[tuple(pattern.ravel().tolist())] = linenum[0] linenum[0] += 1 return memo[tuple(pattern.ravel().tolist())] copyfile('metatemplate11.mc', 'output.mc') with open('output.mc', 'a') as outputfile: createLine(metapattern, outputfile) #Display output.mc g.addlayer() g.open('output.mc') #TODO: Use metatemplate10?
# tile_clist=g.putcells(tile_clist,0,0) # t2=time() # tempfile=g.getdir('rules')+'topoS_temptile' # g.save(tempfile,'rle') # t3=time() # g.open(tempfile) # t4=time() # g.note('clist io %ims,temptile io %ims '%(1000*(t2-t1),1000*(t4-t3))) for j in range(soupnum): if out or next: break g.show('processing topo %i, soup %i' % (posi, j)) g.new('') g.open(tempfile) g.setname(layername) if debug == 'load': g.exit() t1 = time() # wd=soupwd*pbox.wd # ht=soupwd*pbox.ht # soupsel=[-int(wd/2),-int(ht/2),wd,ht] wd = tilewd * pbox.wd ht = tilewd * pbox.ht boxsel = [-int(wd / 2), -int(wd / 2), wd, ht] randfill_mash(boxsel, density) while not oscillating(): t3 = time()
except ValueError: space_len = len(comments[i])-1 if not began: #if still introduction comments2 += comments[i] + '\n' elif i != len(comments)-1 and '#O' in comments[i+1]: #puts pattern discoverer on name line with brackets comments2 += comments[i] + ' [' + comments[i+1][3:] + ']\n' elif '#C' in comments[i] and '----' not in comments[i]: #spaces comment lines to match pattern number comments2 += '#C' + ' '*space_len*began + comments[i][3:] + '\n' elif '#O' in comments[i]: #discoverers are put on the previous line; this is so that they're not duplicated pass else: comments2 += comments[i] + '\n' comments2_intro = comments2[:comments2.index('1.0.0')] comments2_patterns = comments2[comments2.index('1.0.0'):] comments2_patterns = comments2_patterns.replace("#N ","#C ") #comments file only has one #N, and it's at the very beginning comments2_patterns = comments2_patterns.replace(' #C', '\n#C') comments2 = comments2_intro + comments2_patterns # show_message('Comments size: %s KB' % ((len(comments2)+500)//1000),0.5) show_message('Comments size: %s KB text, %s KB LifeViewer labels' % ((len(comments2)+500)//1000, (len(lvcomments)+500)//1000),0) tempname = os.path.join(g.getdir("temp"),"oscillators.rle") g.save(tempname, "rle") with open(tempname,"r") as f: allrle = f.read() with open(tempname,"w") as f: f.write(comments2 + "\n" + allrle) g.open(tempname) # this integrates the comments into the currently open pattern file # there still seem to be some issues with keeping the comments after re-saving the file, # but I'll deal with that separately. Meanwhile: g.note("Click OK to copy pattern to the clipboard, including comments at the beginning and LifeViewer commands at the end.") g.setclipstr(comments2 + "\n" + allrle + lvcomments)
from subprocess import call import golly as g import sys from config0 import * for se in range(2): pic_addr = xdir+g.getstring('pic addr\n') d = g.getstring('d\n') call([py3,xdir+'config1.py',pic_addr,str(d)]) sys.path.append(xdir[:-1]) x = open(xdir+'config2.py') exec(x.read()) x.close() g.open(xdir+'s0.png') g.setrule("b3/s23") f = open(xdir+'config3.py','w') f.write('l=[]\n') for i in xrange(d): g.run(1) g.update() cells = g.getcells(bound) f.write('l.append('+str(cells)+')\n') f.close() call([py3,xdir+'config4.py','e' if se else 's']) interd = int(g.getstring('inter d\n')) call([py3,xdir+'bridge.py',xdir+'s'+str(d)+'.png',xdir+'e1.png',str(interd)])
g.update() # TODO: replace the test in this next if statement with the tests from the pseudocode for clean OTTs and splitters g.run(4096) remainder = g.getcells([-120, -120, 256, 256]) if len(remainder) == 0: pop = int(g.getpop()) if pop != 0: justgliders = 1 if pop % 5 == 0: for test in range(8): g.run(1) pop = int(g.getpop()) if pop % 5 != 0: justgliders = 0 # population only remains a multiple of 10 for 3 ticks at most if it's not a glider else: justgliders = 0 if justgliders != 0: # These next three lines write a pattern to the chosen output file, # so they should only be executed if a pattern passes the test with open(output_fname, "a") as outf: outf.write(rle + "$$$$$$$$$$$$$$$$$$$$$$$$$\n") match += 1 # just for the record, make the output file into valid RLE with open(output_fname, "a") as outf: outf.write("!") g.open(output_fname) g.show("Done.")
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
ipat.put(startx, starty) return "Pattern load data: width={}, height={} startx={}, starty={}, xval={}, yval={}, bytes={}".format(minbox.wd, minbox.height, startx, starty, xval, yval, len(input_str)) attempt_id = os.getenv("GOLLY_ATTEMPT_ID") if attempt_id is None and os.getenv("LIFEBOX_DEBUG") is not None: attempt_id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeffffff" BASE_RESULTS_PATH = os.path.join(os.sep, "tmp", attempt_id) if not os.path.exists(BASE_RESULTS_PATH): os.makedirs(BASE_RESULTS_PATH) RESULTS_FN = os.path.join(BASE_RESULTS_PATH, "results.log") open(RESULTS_FN,"a").write("Opening up MC file..\n") g.open("adventure_lifebooox.mc") g.setrule('Varlife') g.show("Starting....") g.update() g.setstep(6) start_time = time.time() open(RESULTS_FN,"a").write("BOOTING..\n") PATTERN_FN = os.path.join(BASE_RESULTS_PATH, "pattern.dat") results = add_data(PATTERN_FN) open(RESULTS_FN,"a").write(results + "\n") boot_completed = False for x in range(0, 40):
neightup = neighbor_census[index][0] cindex = 9 * neightup[0] + neightup[1] changes[cindex] = currcombocopy % 2 currcombocopy /= 2 index += 1 for index, change in enumerate(changes): newrule[index] = currrule[index] ^ change #g.note(str(counts) + ', ' + str(currcombo) + ', ' + str(currcount) + ', ' + str(newrule)) if newrule not in rulelist: currrule = newrule rulelist.append(currrule) break testnum += 1 rulestring = 'B/S' for index, condition in enumerate(currrule): if index < 9: if condition == 1: rulestring = rulestring[:-2] + str(index) + rulestring[-2:] else: if condition == 1: rulestring += str(index - 9) f = open(rules, 'a') f.write(rulestring + '\n') f.close() g.setrule(rulestring) g.open(rules)