def loadtopo(maxnum,step,boxwidth): global pboxlist tile=[] for i in range(step,maxnum+step,step): make_text(str(i)).put(boxwidth*(i-1),0) box.put(boxwidth*(i-1),0) boxsel=[boxwidth*(i-1)+1,1,38,38] g.select(boxsel) g.shrink() if g.getselrect()==boxsel: continue else: sel=g.getselrect() pbox=g.getselrect() clist=g.getcells(pbox) for i in range(int(len(clist)/3)): clist[3*i] = clist[3*i]-sel[0] clist[3*i+1] = clist[3*i+1]-sel[1] clist.insert(0,sel[2]) clist.insert(1,sel[3]) tile.append(clist) pboxlist.append(pbox) return tile
def show_it(recipe, lane, move, elbow_type, start_elbow): global offset start_cells, start_type, start_lane = start_elbow res = "" phase = 0 if lane is not None: direction = lane[1] phase = lane[2] if direction == 0: res = "Rev%d" % lane[0] elif direction == 1: res = "R%d" % (lane[0] - start_lane) elif direction == 2: res = "L%d" % (lane[0] - start_lane) # elif direction == 3: # res = "LWSS_W" # elif direction == 4: # res = "LWSS_S" if move is None: res += "k" else: res += "m%d%s%s" % (move - start_lane, str(start_type), elbow_type) g.putcells(make_text(res, "mono"), offset, -80) g.putcells(start_cells, offset, 0) for i, t in enumerate(recipe[::2]): if t is not None: d = 80*i + MAX_DIFF / 4 + 20 g.putcells(g.evolve(G1, t + MAX_DIFF), offset-d, d) for i, t in enumerate(recipe[1::2]): if t is not None: d = 80*i + MAX_DIFF / 4 + 20 g.putcells(g.evolve(G2, t + MAX_DIFF), offset-d, d) res += ": " for i in range(0, len(recipe), 2): if recipe[i] is None: res += "eo"[(recipe[i+1]+phase)%2] + "-9999 " elif recipe[i+1] is None: res += "eo"[(recipe[i]+phase)%2] + "9999 " else: res += "eo"[(recipe[i]+phase)%2] + str(recipe[i]-recipe[i+1]) + " " f.write(res + "\n") f.flush() offset += 100 g.update()
def parsefreq(freq): '''Get the frequency and convert it to glife.pattern.''' # Format string and convert it to cell list. pat = list(make_text('{:.3f}'.format(freq), font='mono')) # Convert one-state cell list to multi-state cell list pat = g.join(pat, [0]) # Set cell state to state 4 for idx in xrange(2, len(pat), 3): pat[idx] = 4 return glife.pattern(pat)
def parsename(name): '''Get the catalyst name and convert it to glife.pattern.''' # Convert the string to cell list. pat = list(make_text(name, font='mono')) # Convert one-state cell list to multi-state cell list pat = g.join(pat, [0]) # Set cell state to state 4 for idx in xrange(2, len(pat), 3): pat[idx] = 4 return glife.pattern(pat)
def loadtopo(): for i in range(step, max + step, step): make_text(str(i)).put(boxwidth * (i - 1), 0) box.put(boxwidth * (i - 1), 0) boxsel = [boxwidth * (i - 1) + 1, 1, 38, 38] g.select(boxsel) g.shrink() if g.getselrect() == boxsel: continue else: clist = g.getcells(g.getselrect()) sel = g.getselrect() for i in range(int(len(clist) / 3)): clist[3 * i] = clist[3 * i] - sel[0] clist[3 * i + 1] = clist[3 * i + 1] - sel[1] clist.insert(0, sel[2]) clist.insert(1, sel[3]) tile.append(clist) return tile
def color_text(string, extrastate): t = make_text(string, "mono") bbox = getminbox(t) # convert two-state pattern to multi-state and set state to extrastate mlist = [] tlist = list(t) for i in xrange(0, len(tlist), 2): mlist.append(tlist[i]) mlist.append(tlist[i + 1]) mlist.append(extrastate) if len(mlist) % 2 == 0: mlist.append(0) p = pattern(mlist) return p, bbox.wd, bbox.ht
def color_text(string, extrastate): t = make_text(string, "mono") bbox = getminbox(t) # convert two-state pattern to multi-state and set state to extrastate mlist = [] tlist = list(t) for i in xrange(0, len(tlist), 2): mlist.append(tlist[i]) mlist.append(tlist[i+1]) mlist.append(extrastate) if len(mlist) % 2 == 0: mlist.append(0) p = pattern(mlist) return p, bbox.wd, bbox.ht
def AddText(val, x, y): t = make_text(val, "mono") newt = [] cnt = 0 for i in t: cnt += 1 newt.append(i) if cnt % 2 == 0: newt.append(4) if len(newt) % 2 == 0: newt.append(0) g.putcells(newt, x, y)
while x < len(clist): if (clist[x] > right) or (clist[y] > bottom): # remove cell from list clist[x:x + inc] = [] else: x += inc y += inc # append padding int if necessary if (inc == 3) and (len(clist) & 1 == 0): clist.append(0) return pattern(clist) for i in range(step, maxnum + step, step): make_text(str(i)).put(boxwidth * (i - 1), 0) g.putcells(box, boxwidth * (i - 1), 0) boxsel = [boxwidth * (i - 1) + 1, 1, boxwidth - 2, boxwidth - 2] g.select(boxsel) g.shrink() if g.getselrect() == boxsel: continue else: clist = g.getcells(g.getselrect()) sel = g.getselrect() for i in range(int(len(clist) / 3)): clist[3 * i] = clist[3 * i] - sel[0] clist[3 * i + 1] = clist[3 * i + 1] - sel[1] clist.insert(0, sel[2]) clist.insert(1, sel[3])
if y >= ysize - 1 or len(searchlist) >= MAXOBJ: # we've reached the end of the frame. # Time to clear the last placed object, go back to that x,y if searchlist == []: g.new("TestPage") g.exit("Search is complete.") x, y, ptr, nearlist, filledlist = searchlist.pop() # no point in looking at configurations with no object on the first line g.new("TestPage") s, count = "", 0 f = open(outfname, "w") for item in sorted(patdict): y = 0 t = make_text(item + " (" + str(len(patdict[item])) + ")", "mono") f.write("# " + item + " (" + str(len(patdict[item])) + ")\n") g.putcells(t, x - 6, y) y += 30 for pat in patdict[item]: blinkercenters = [] for i, j in pat: if [i - 1, j] in pat and [i + 1, j] in pat and [ i, j - 1 ] in pat and [i, j + 1] in pat: blinkercenters += [[i, j]] if len(blinkercenters) > 0: if len(blinkercenters) == 1: i, j = blinkercenters[0] patphase1 = [ coord for coord in pat
import golly as g from glife import * from glife.text import make_text t = g.getstring('what text?', g.getclipstr()) make_text(t).put(-50, -50)
elif i == "HALT": g.note("Program reached halt state.") g.setclipstr(s) g.exit() elif i[:4] == "MUL ": bit = str(i[4:]) if "MUL" not in registers: registers["MUL"] = "00000" nextoutput, registers["MUL"] = mullookup["MUL" + bit + " " + registers["MUL"]] elif i[:7] == "OUTPUT ": outputtext += i[7:] outpat = make_text(outputtext) g.putcells(outpat, 0, 10) g.update() elif i[:4] == "SUB ": if "SUB" not in registers: registers["SUB"] = "000 stopper0 bit0" whichinput = i[4:] out, registers["SUB"] = sublookup[registers["SUB"] + " " + whichinput] if registers["SUB"] == "FAILURE": g.note("Program crashed at line '" + i + "'. SUB A1 must have been run twice (?).") g.exit() if out != "NONE": nextoutput = out
maxpop = max(poplist) if minpop == maxpop: # avoid division by zero minpop -= 1 popscale = float(maxpop - minpop) / float(ylen) mingen = min(genlist) maxgen = max(genlist) genscale = float(maxgen - mingen) / float(xlen) # draw axes with origin at 0,0 draw_line(0, 0, xlen, 0) draw_line(0, 0, 0, -ylen) # add annotation using mono-spaced ASCII font t = make_text(pattname.upper(), "mono") bbox = getminbox(t) t.put((xlen - bbox.wd) / 2, -ylen - 10 - bbox.ht) t = make_text("POPULATION", "mono") bbox = getminbox(t) t.put(-10 - bbox.ht, -(ylen - bbox.wd) / 2, rccw) t = make_text(str(minpop), "mono") bbox = getminbox(t) t.put(-bbox.wd - 10, -bbox.ht / 2) t = make_text(str(maxpop), "mono") bbox = getminbox(t) t.put(-bbox.wd - 10, -ylen - bbox.ht / 2)
popscale = int(popscale) mingen = min(genlist) maxgen = max(genlist) xlen = maxgen - mingen ylen = int(min(xlen, (maxpop - minpop) / popscale)) # popscale = float(maxpop - minpop) / float(ylen) genscale = 1 # genscale = float(maxgen - mingen) / float(xlen) # draw axes with origin at 0,0 draw_line(0, 0, xlen, 0) draw_line(0, 0, 0, -ylen) # add annotation using mono-spaced ASCII font t = make_text(pattname.upper(), "mono") bbox = getminbox(t) t.put((xlen - bbox.wd) / 2, -ylen - 10 - bbox.ht) t = make_text(ytitle, "mono") bbox = getminbox(t) t.put(-10 - bbox.ht, -(ylen - bbox.wd) / 2, rccw) t = make_text(str(minpop), "mono") bbox = getminbox(t) t.put(-bbox.wd - 10, -bbox.ht / 2) t = make_text(str(maxpop), "mono") bbox = getminbox(t) t.put(-bbox.wd - 10, -ylen - bbox.ht / 2)
from collections import Counter import golly as g from glife import * from glife.text import make_text from time import time import random import math as m import csv import os input = g.getstring('max/step/boxwidth', '36/2/20') max = int(input.split('/')[0]) step = int(input.split('/')[1]) boxwidth = int(input.split('/')[2]) box = g.parse( "40o$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$\ o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38b\ o$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o38bo$o\ 38bo$o38bo$o38bo$o38bo$40o!") box = pattern(box) # box=pattern() for i in range(step, max + step, step): make_text(str(i)).put(boxwidth * (i - 1), 0) box.put(boxwidth * (i - 1), 0)