def tileit(clist,tilewd): global inc,pbox cliplist=clist # g.select([boxsel[0]-20,boxsel[1]-20,20,20]) # g.clear(0) # make_text(str(posi)).put(boxsel[0]-20,boxsel[1]) pbox = rect( [0, 0] + cliplist[0 : 2] ) wd=tilewd*pbox.wd ht=tilewd*pbox.ht boxsel=[-int(wd/2),-int(wd/2),wd,ht] g.select(boxsel) selrect = rect( g.getselrect() ) inc=2 cliplist[0 : 2] = [] # remove wd,ht p = pattern( cliplist ) if len(cliplist) & 1 == 1: inc = 3 # multi-state? g.clear(inside) if len(cliplist) > 0: # tile selrect with p, clipping right & bottom edges if necessary y = selrect.top while y <= selrect.bottom: bottom = y + pbox.height - 1 x = selrect.left while x <= selrect.right: right = x + pbox.width - 1 if (right <= selrect.right) and (bottom <= selrect.bottom): p.put(x, y) else: clip_rb( p(x, y), selrect.right, selrect.bottom ).put() x += pbox.width y += pbox.height if not selrect.visible(): g.fitsel()
deltax, deltay = 0, 0 if pat != []: deltax, deltay = -pat[0], -pat[1] if j == 0: minstr = str(g.transform(pat, deltax, deltay)) else: strpat = str(g.transform(pat, deltax, deltay)) if strpat < minstr: minstr = strpat return " " + get9char(minstr) r = g.getselrect() if r == []: g.exit("No selection. Select something to find by fingerprint.") g.fitsel() r = g.getselrect() if r == []: g.exit("No selection. Select something to find by fingerprint.") count = NUMLINES outptrx, outptry, matches = 0, 0, 0 pat = g.getcells(r) g.addlayer() # do tests in a new layer, then put results there hash = getoctohash(pat) g.new("Output") if pat != []: g.putcells(pat, -pat[0] - GRIDSIZE, -pat[1]) for i in range(10):
# Use the current selection to create a toroidal universe. # Author: Andrew Trevorrow ([email protected]), Sept 2010. from glife import inside, outside import golly as g selrect = g.getselrect() if len(selrect) == 0: g.exit("There is no selection.") x = selrect[0] y = selrect[1] wd = selrect[2] ht = selrect[3] selcells = g.getcells(selrect) if not g.empty(): g.clear(inside) g.clear(outside) # get current rule, remove any existing suffix, then add new suffix rule = g.getrule().split(":")[0] g.setrule(rule + ":T" + str(wd) + "," + str(ht)) newx = -int(wd/2) newy = -int(ht/2) selrect[0] = newx selrect[1] = newy g.select(selrect) if len(selcells) > 0: g.putcells(selcells, newx - x, newy - y) g.fitsel()
mode = "or" # abort shift if the new selection would be outside a bounded grid if g.getwidth() > 0: gridl = -int(g.getwidth()/2) gridr = gridl + g.getwidth() - 1 newl = selrect[0] + x newr = newl + selrect[2] - 1 if newl < gridl or newr > gridr: g.exit("New selection would be outside grid.") if g.getheight() > 0: gridt = -int(g.getheight()/2) gridb = gridt + g.getheight() - 1 newt = selrect[1] + y newb = newt + selrect[3] - 1 if newt < gridt or newb > gridb: g.exit("New selection would be outside grid.") # do the shift by cutting the current selection and pasting it into # the new position without changing the current clipboard pattern selcells = g.getcells(selrect) g.clear(inside) selrect[0] += x selrect[1] += y g.select(selrect) if mode == "copy": g.clear(inside) g.putcells(selcells, x, y, 1, 0, 0, 1, mode) if not g.visrect(selrect): g.fitsel()
# ------------------------------------------------------------------------------ selrect = rect( g.getselrect() ) if selrect.empty: g.exit("There is no selection.") cliplist = g.getclip() # 1st 2 items are wd,ht pbox = rect( [0, 0] + cliplist[0 : 2] ) cliplist[0 : 2] = [] # remove wd,ht p = pattern( cliplist ) if len(cliplist) & 1 == 1: inc = 3 # multi-state? g.clear(inside) if len(cliplist) > 0: # tile selrect with p, clipping right & bottom edges if necessary y = selrect.top while y <= selrect.bottom: bottom = y + pbox.height - 1 x = selrect.left while x <= selrect.right: right = x + pbox.width - 1 if (right <= selrect.right) and (bottom <= selrect.bottom): p.put(x, y) else: clip_rb( p(x, y), selrect.right, selrect.bottom ).put() x += pbox.width y += pbox.height if not selrect.visible(): g.fitsel()
# Invert all cell states in the current selection. # Author: Andrew Trevorrow ([email protected]), Jun 2006. # Updated to use exit command, Nov 2006. # Updated to use numstates command, Jun 2008. from glife import rect from time import time import golly as g r = rect( g.getselrect() ) if r.empty: g.exit("There is no selection.") oldsecs = time() maxstate = g.numstates() - 1 for row in xrange(r.top, r.top + r.height): # if large selection then give some indication of progress newsecs = time() if newsecs - oldsecs >= 1.0: oldsecs = newsecs g.update() # also allow keyboard interaction g.dokey( g.getkey() ) for col in xrange(r.left, r.left + r.width): g.setcell(col, row, maxstate - g.getcell(col, row)) if not r.visible(): g.fitsel()
# Invert all cell states in the current selection. # Author: Andrew Trevorrow ([email protected]), Jun 2006. # Updated to use exit command, Nov 2006. # Updated to use numstates command, Jun 2008. from glife import rect from time import time import golly as g r = rect( g.getselrect() ) if r.empty: g.exit("There is no selection.") oldsecs = time() maxstate = g.numstates() - 1 for row in xrange(r.top, r.top + r.height): # if large selection then give some indication of progress newsecs = time() if newsecs - oldsecs >= 1.0: oldsecs = newsecs g.update() for col in xrange(r.left, r.left + r.width): g.setcell(col, row, maxstate - g.getcell(col, row)) if not r.visible(): g.fitsel()
right += bbox.width i += 1 if right <= selrect.right: selpatt.put(bbox.width * i, 0) else: clip_right( selpatt(bbox.width * i, 0), selrect.right ).put() # get new selection pattern and tile vertically, clipping where necessary selpatt = pattern( g.getcells(g.getselrect()) ) bbox = getminbox(selpatt) top = bbox.top i = 0 while top > selrect.top: top -= bbox.height i += 1 if top >= selrect.top: selpatt.put(0, -bbox.height * i) else: clip_top( selpatt(0, -bbox.height * i), selrect.top ).put() bottom = bbox.bottom i = 0 while bottom < selrect.bottom: bottom += bbox.height i += 1 if bottom <= selrect.bottom: selpatt.put(0, bbox.height * i) else: clip_bottom( selpatt(0, bbox.height * i), selrect.bottom ).put() if not selrect.visible(): g.fitsel()