Ejemplo n.º 1
0
def clearlayer():
    r = g.getrect()
    if r:
        g.select(r)
        g.clear(0)
    if withB0:
        # Needed with B0 rules to ensure pattern runs correctly
        g.setgen('0')
Ejemplo n.º 2
0
def render(length, x, y, generation):
    g.setgen("0")
    g.setalgo("Generations")
    g.setrule(generate_rule(x, y, generation))

    pop, extinction = get_pop(length, x, y)
    if extinction < 4410:
        g.show("Rule {} extinct at generation {}.".format(
            g.getrule(), extinction))
        with open("snd/short_lived_rules", "a") as short_lived:
            short_lived.write(g.getrule() + "\n")
        return
    with open("snd/long_lived_rules", "a") as long_lived:
        long_lived.write(g.getrule() + "\n")

    filename = create_name("snd")
    write_wave(filename, pop)

    g.show("Wave saved to " + filename)
Ejemplo n.º 3
0
            for j in range(0, len(clist), 2):
                crd = [x0 + clist[j], y0 + clist[j + 1]]
                if crd in coords:
                    coords.remove(crd)
                else:
                    g.exit(
                        "A coordinate that should have been there wasn't: " +
                        str(crd) + "\n\n" + str(coords))
            rewindable.append([k, x0 - v[3], y0 - v[4]])
            break  # no need to go through rest of items in dictionary
    if not match:
        i += 1  # only increment index if current coord has not been removed due to a match

# at the end of this process, coords should be flattenable to a cell list containing all unrecognized stuff

g.setgen("-1")

# remove all rewindable items
for item in rewindable:
    lookup = odict[item[0]]
    # odict[name+phase]=[ticks, stridex, stridey, dx, dy, clist, getenvelope(clist)]
    clist = lookup[5]
    for i in range(0, len(clist), 2):
        g.setcell(clist[i] + item[1] + lookup[3],
                  clist[i + 1] + item[2] + lookup[4], 0)

# now put them back one tick earlier...
for item in rewindable:
    namephase = item[0]
    ind = namephase.find("_")
    name = namephase[:ind]
Ejemplo n.º 4
0
 g.putcells(movablepat, iadjustment * dx, iadjustment * dy)
 g.putcells(movablebb, iadjustment * dx, iadjustment * dy)
 done = 0
 g.setrule("Life")
 r = g.getrect()
 while done == 0:
     g.putcells(signal)
     g.run(iperiod / subperiod)
     g.fit()
     g.update()
     if g.getcell(signal[0], signal[1]) == 1: done = 1
 g.run(finaladjustment)
 g.run(100 * iperiod / subperiod)
 if subperiod > 1 and outputmatch(output) != 1:
     countdown = subperiod
     g.setgen("0")
     while countdown >= 0:
         countdown -= 1
         g.run(iperiod / subperiod)
         if outputmatch(output) == 1:
             break
 if outputmatch(output) != 1:
     g.exit("Looks like something went wrong at period " + period \
          + ".  Output is not showing up after any reasonable number of subperiod cycles.")
 g.select(r)
 g.clear(1)
 g.select([])
 g.setgen("0")
 g.show("Done!  " + os.path.join(outfolder, str(period)))
 g.putcells(fixedbb)
 g.putcells(movablebb, iadjustment * dx, iadjustment * dy)
Ejemplo n.º 5
0
#  to change behavior at center, comment out one of the lines below
all += eater(6018,5924,rccw) + eater(6037,5943,rccw) # true p1100 gun
# all += block(6018,6787) # synch center to recreate original p1100x5

center = block(1081,6791) + block(2731,6791) + block(3831,6791) \
   + block(9108,6791) + block(10208,6791) + block(11308,6791) \
   + passthrough(8475,6737) + passthrough[39](3365,6737,flip_x) \
   + passthrough(9575,6737) + passthrough[39](2265,6737,flip_x) \
   + passthrough(10675,6737) + passthrough[39](1715,6737,flip_x)

# add asymmetric Equator to mirror-symmetric North and South
MWSSrecipes += MWSSrecipes(0,13583,flip_y)
all += all(0,13583,flip_y) + center

g.putcells(all)
g.fit()

# Different glider paths are different lengths, so incomplete
# glider recipes must be overwritten for a while to prevent disaster.
for i in range(46):
    g.show("Filling glider tracks -- " \
           + str(49500 - i*1100) + " ticks left.")
    g.update()
    g.putcells(MWSSrecipes)
    g.run(1100)
g.show("")

# reset gen count to 0
g.setgen("0")
Ejemplo n.º 6
0
def main ():
  g.update ()
  g.check (False)

  path = g.getstring ("Output directory:")
  files = glob.glob (os.path.join (path, "*.out"))

  mingls = g.getstring ("Min number of gliders at accept:")
  if mingls == "":
    mingl = 0
    minpop = 0
    maxpop = 1024
  else:
    mingl = int (mingls)
    minpops = g.getstring ("Min population except catalyzers:")
    if minpops == "":
      minpop = 0
      maxpop = 1024
    else:
      minpop = int (minpops)
      maxpop = int (g.getstring ("Max population except catalyzers:"))

  if g.getname () != "catbellman_temp":
    g.addlayer ()

  hashdir = {}
  catlist = []
  catix = 0

  g.new ("catbellman_temp")
  g.setrule ("LifeBellman")

  for fix, filename in enumerate (files):
    patt = g.getrect ()
    if patt != []:
      g.select (patt)
      g.clear (0)
  
    g.setgen ("0")
	
    with open(filename, 'r') as f:
      filetext = f.read ()
      if fix % 16 == 0:
        g.show ("Analysing " + str (fix) + "/" + str (len (files)))
		
      (gogen, glcnt) = convbellman (filetext, 0, 0)
      if gogen == -1:
	    gogen = 128
	  
      (use, hash) = analyse (gogen, glcnt, minpop, maxpop, mingl)

      if use:
        if not hash in hashdir:
          catlist.append ([])
          hashdir [hash] = catix
          catix += 1

        cat = hashdir [hash]
        catlist [cat].append (filetext)

  g.new ("catbellman_temp")
  g.setrule ("LifeBellman")

  fix = 0
  y = 0
  for cat in catlist:
    x = 96 * (len (cat) - 1)
    for filetext in cat:
      convbellman (filetext, x, y)
      x -= 96
      fix += 1
      if fix % 32 == 0:
        g.show ("Rendering " + str (fix) + "/" + str (len (files)))
        g.fit ()
        g.check (True)
        g.update ()
        g.check (False)

    y += 96

  g.show ("Done")
  g.fit ()
  g.setstep (-1)
  g.check (True)
Ejemplo n.º 7
0
# For frame rate and timing
frameRate = 100
framePeriod = 1.0 / frameRate
# Attainable sleep resolution on most modern Python/OS combinations (1ms)
sleepTime = 0.001

N = 0
Npatts = len(sssPatterns)
while N < Npatts:
    ship = sssPatterns[N]
    r = g.getrect()
    if r:
        g.select(r)
        g.clear(0)
        g.select([])
    g.setgen('0')
    g.putcells(g.parse(ship[5]))
    g.setrule(ship[1])
    g.setpos('0', '0')
    g.setmag(2)
    status = "Pattern %d of %d, " % (N + 1, Npatts)
    status += "Speed is (%d, %d)/ %d, " % ship[2:5]
    status += "press 'space' for next pattern, 'p' for previous, 'q' to quit"
    g.show(status)
    g.update()
    start = timer()
    frameTime = start
    while True:
        # Wait until next frame
        frameTime += framePeriod
        now = timer()
Ejemplo n.º 8
0
# Output an adjacency matrix for current selection to clipborad in a "Mathematica" list fomart
# Use AdjacencyGraph[] in Mathematica for downstream processing.
# Author: Feng Geng([email protected]), May 2016.

import golly as g
from glife import *
import numpy as np
import hashlib

stepmax = int(g.getstring('steps to advance', '1000'))
sel = g.getselrect()
step = 1
script = g.getstring('script to apply',
                     'clock2.py')  #change here to your desired script
update_interval = 2
xs = 0.25
ys = 1
while step <= stepmax:
    execfile(script)
    g.advance(0, 1)
    step = step + 1
    g.setgen(str(step))
    if step % update_interval:
        g.update()