def setpos(self, x, y):
     """
     Sets the position of the screen in golly to center in on the location
     :param x: x position to zoom to
     :param y: y position to zoom to
     """
     g.setpos(x, y)
Esempio n. 2
0
	def draw(self, addstr = ""):
		
		xy = [] 
		xz = [] 
		yz = [] 
		proj = []
		
		for (k, v) in self.cur_state.items():
			x, y, z = k
			
			xy.append(x)
			xy.append(y)
			
			xz.append(x + 128)
			xz.append(z)
			
			yz.append(y)
			yz.append(z + 128)
		
			proj.append(x + y + z + 128)
			proj.append(- x + y + z + 128)
			
		if len(g.getrect()) > 0:
			g.select(g.getrect())
			g.clear(0)
			g.select([])
		
		g.putcells(xy)
		g.putcells(xz)
		g.putcells(yz)
		g.putcells(proj)
		g.setpos("64", "64")
		g.setmag(1)
		g.show("Size: {0}, (w, d, h): {1}".format(self.get_pop(), str(self.get_wdh())) + addstr)
		g.update()
Esempio n. 3
0
    def draw(self):

        xy = []
        xz = []
        yz = []
        proj = []

        for (k, v) in self.cur_state.items():
            x, y, z = k

            xy.append(x)
            xy.append(y)

            xz.append(x + 128)
            xz.append(z)

            yz.append(y)
            yz.append(z + 128)

            proj.append(x + y + z + 128)
            proj.append(-x + y + z + 128)

        if len(g.getrect()) > 0:
            g.select(g.getrect())
            g.clear(0)
            g.select([])

        g.putcells(xy)
        g.putcells(xz)
        g.putcells(yz)
        g.putcells(proj)
        g.setpos("64", "64")
        g.setmag(1)
        g.update()
Esempio n. 4
0
def checkFit():
    r = g.getrect()
    if not r:
        return
    if not g.visrect(r):
        g.setpos(str(r[0] + r[2] / 2), str(r[1] + r[3] / 2))
        if not g.visrect(r):
            g.setmag(g.getmag() - 1)
Esempio n. 5
0
def goto(newgen):
    currgen = int(g.getgen())
    
    if newgen < currgen:
        # try to go back to starting gen (not necessarily 0) and
        # then forwards to newgen; note that reset() also restores
        # algorithm and/or rule, so too bad if user changed those
        # after the starting info was saved;
        # first save current location and scale
        midx, midy = g.getpos()
        mag = g.getmag()
        g.reset()
        # restore location and scale
        g.setpos(midx, midy)
        g.setmag(mag)
        # current gen might be > 0 if user loaded a pattern file
        # that set the gen count
        currgen = int(g.getgen())
        if newgen < currgen:
            g.error("Can't go back any further; pattern was saved " +
                    "at generation " + str(currgen) + ".")
            return
    if newgen == currgen: return

    oldsecs = time()

    # before stepping we advance by 1 generation, for two reasons:
    # 1. if we're at the starting gen then the *current* step size
    #    will be saved (and restored upon Reset/Undo) rather than a
    #    possibly very large step size
    # 2. it increases the chances the user will see updates and so
    #    get some idea of how long the script will take to finish
    #    (otherwise if the base is 10 and a gen like 1,000,000,000
    #    is given then only a single step() of 10^9 would be done)
    g.run(1)
    currgen += 1

    # use fast stepping (thanks to PM 2Ring)
    oldstep = g.getstep()
    for i, d in enumerate(intbase(newgen - currgen, g.getbase())):
        if d > 0:
            g.setstep(i)
            for j in xrange(d):
                if g.empty():
                    g.show("Pattern is empty.")
                    return
                g.step()
                newsecs = time()
                if newsecs - oldsecs >= 1.0:  # do an update every sec
                    oldsecs = newsecs
                    g.update()
    g.setstep(oldstep)
Esempio n. 6
0
def goto(newgen):
    currgen = int(g.getgen())

    if newgen < currgen:
        # try to go back to starting gen (not necessarily 0) and
        # then forwards to newgen; note that reset() also restores
        # algorithm and/or rule, so too bad if user changed those
        # after the starting info was saved;
        # first save current location and scale
        midx, midy = g.getpos()
        mag = g.getmag()
        g.reset()
        # restore location and scale
        g.setpos(midx, midy)
        g.setmag(mag)
        # current gen might be > 0 if user loaded a pattern file
        # that set the gen count
        currgen = int(g.getgen())
        if newgen < currgen:
            g.error("Can't go back any further; pattern was saved " +
                    "at generation " + str(currgen) + ".")
            return
    if newgen == currgen: return

    oldsecs = time()

    # before stepping we advance by 1 generation, for two reasons:
    # 1. if we're at the starting gen then the *current* step size
    #    will be saved (and restored upon Reset/Undo) rather than a
    #    possibly very large step size
    # 2. it increases the chances the user will see updates and so
    #    get some idea of how long the script will take to finish
    #    (otherwise if the base is 10 and a gen like 1,000,000,000
    #    is given then only a single step() of 10^9 would be done)
    g.run(1)
    currgen += 1

    # use fast stepping (thanks to PM 2Ring)
    oldstep = g.getstep()
    for i, d in enumerate(intbase(newgen - currgen, g.getbase())):
        if d > 0:
            g.setstep(i)
            for j in xrange(d):
                if g.empty():
                    g.show("Pattern is empty.")
                    return
                g.step()
                newsecs = time()
                if newsecs - oldsecs >= 1.0:  # do an update every sec
                    oldsecs = newsecs
                    g.update()
    g.setstep(oldstep)
Esempio n. 7
0
def gt_setup(gen):
   currgen = int(g.getgen())
   # Remove leading '+' or '-' if any, and convert rest to int or long
   if gen[0] == '+':
      n = int(gen[1:])
      newgen = currgen + n
   elif gen[0] == '-':
      n = int(gen[1:])
      if currgen > n:
         newgen = currgen - n
      else:
         newgen = 0
   else:
      newgen = int(gen)
   
   if newgen < currgen:
      # try to go back to starting gen (not necessarily 0) and
      # then forwards to newgen; note that reset() also restores
      # algorithm and/or rule, so too bad if user changed those
      # after the starting info was saved;
      # first save current location and scale
      midx, midy = g.getpos()
      mag = g.getmag()
      g.reset()
      # restore location and scale
      g.setpos(midx, midy)
      g.setmag(mag)
      # current gen might be > 0 if user loaded a pattern file
      # that set the gen count
      currgen = int(g.getgen())
      if newgen < currgen:
         g.error("Can't go back any further; pattern was saved " +
                 "at generation " + str(currgen) + ".")
         return 0
      return newgen - currgen
   elif newgen > currgen:
      return newgen - currgen
   else:
     return 0
Esempio n. 8
0
def gt_setup(gen):
    currgen = int(g.getgen())
    # Remove leading '+' or '-' if any, and convert rest to int or long
    if gen[0] == '+':
        n = int(gen[1:])
        newgen = currgen + n
    elif gen[0] == '-':
        n = int(gen[1:])
        if currgen > n:
            newgen = currgen - n
        else:
            newgen = 0
    else:
        newgen = int(gen)

    if newgen < currgen:
        # try to go back to starting gen (not necessarily 0) and
        # then forwards to newgen; note that reset() also restores
        # algorithm and/or rule, so too bad if user changed those
        # after the starting info was saved;
        # first save current location and scale
        midx, midy = g.getpos()
        mag = g.getmag()
        g.reset()
        # restore location and scale
        g.setpos(midx, midy)
        g.setmag(mag)
        # current gen might be > 0 if user loaded a pattern file
        # that set the gen count
        currgen = int(g.getgen())
        if newgen < currgen:
            g.error("Can't go back any further; pattern was saved " +
                    "at generation " + str(currgen) + ".")
            return 0
        return newgen - currgen
    elif newgen > currgen:
        return newgen - currgen
    else:
        return 0
Esempio n. 9
0
def dmprinter(pdy, copies=1):
    ''' Generate & display a dot matrix printer for named bitmap pattern '''
    #Horizontal pixel separation between LineMakers. minimum = 5
    LMsx = 5

    #Horizontal distance between bitmap pixels. Constant, due to LineMaker period
    pdx = 15

    #Distance between LineMakers
    LMdx, LMdy = -LMsx * pdx, pdy

    #Get bitmap pattern from current selection.
    bm = get_bitmap()

    #Make printer in a new layer
    golly.duplicate()
    golly.setoption("syncviews", False)

    #Build new window title from old
    title = golly.getname().split('.')[0]
    title = '%s_Printer [%d] v0.10' % (title, pdy)
    golly.new(title)

    #Make sure we're using the standard Life generation rule
    golly.setrule("B3/S23")

    #Bitmap dimensions. Width MUST be of form 4m, for m >=1
    bmheight = len(bm)
    bmwidth = len(bm[0])
    mid = (bmheight + 1) // 2

    loopw = (bmwidth - 8) // 4
    loopm = pdx * loopw

    #Gliders, heading north-east
    g0 = pattern('2bo$2o$b2o!')
    g1 = pattern('obo$2o$bo!')
    gliders = [
        g0, g1,
        g1(0, 2, rccw),
        g0(0, 2, rccw),
        g0(2, 2, flip),
        g1(2, 2, flip),
        g1(2, 0, rcw),
        g0(2, 0, rcw)
    ]

    #Create full Glider loop.
    gg = []
    ox, oy = 35, 23
    for j in xrange(loopw + 1):
        dd = pdx * j
        gg += [
            gliders[0](ox + dd, oy - dd), gliders[1](ox + 8 + dd, oy - 7 - dd)
        ]
    dd = loopm
    gg += [gliders[2](45 + dd, 4 - dd), gliders[3](37 + dd, -3 - dd)]

    ox, oy = 26 + loopm, -4 - loopm
    for j in xrange(loopw + 1):
        dd = pdx * j
        gg += [
            gliders[4](ox - dd, oy + dd), gliders[5](ox - 8 - dd, oy + 7 + dd)
        ]
    dd = loopm
    gg += [gliders[6](16, 15), gliders[7](24, 22)]
    parity = 2 * ((loopw + 1) * (0, 0) + (1, 1))

    def buildLM():
        ''' Build a complete LineMaker '''
        #Populate glider loop. (jj, ii) are bitmap coords
        gloop = pattern()
        for j in xrange(bmwidth):
            jj = (j - delta + bmwidth - 1) % bmwidth

            #Is there a pixel at this location?
            if bm[ii][jj] == parity[j]:
                gloop += gg[j]  #Add glider to the loop

        #Only put LineMaker if glider loop isn't empty
        if len(gloop) > 0:
            (LMBlank + gloop).put(Lx, Ly, trans)

    #Assemble blank LineMaker
    LMBlank = linemaker(loopm)

    #Do upper LineMakers
    trans = identity
    for i in xrange(mid):
        ii = mid - (i + 1)
        io = mid + (i + 1)
        Lx, Ly = io * LMdx, ii * LMdy
        delta = LMsx * io
        buildLM()

    #Do lower LineMakers
    trans = flip_y
    for i in xrange(mid, bmheight):
        ii = i
        io = i + 2
        Lx, Ly = io * LMdx + pdx, ii * LMdy + 128
        delta = LMsx * io - 1
        buildLM()

    #Eaters facing south-east & north-east
    eaterSE = pattern('2o$bo$bobo$2b2o!')
    eaterNE = eaterSE(0, 10, flip_y)
    eY = 59
    eaters = (eaterNE(0, eY), eaterSE(0, eY))

    #Eater horizontal displacement. Must be odd
    #bmwidth muliplier determines number of copies visible 'outside' printer.
    eX = (bmheight + 1) * LMdx - (copies * bmwidth - 1) * pdx
    eX = 1 + eX // 2 * 2  #Adjust parity
    all = pattern()
    for i in xrange(bmheight):
        all += eaters[i % (1 + LMsx % 2)](eX, i * LMdy)
    all.put()

    #Centre view over bitmap output area
    golly.setpos(str(-pdx * bmwidth // 2 + (bmheight - 1) * LMdx),
                 str(Ly // 2))
    #golly.setmag(-2)    #Aliasing effects happen at smaller scales than -2 :(
    golly.fit()
Esempio n. 10
0
# 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()
        if now > frameTime:
            frameTime = now
        else:
g.show("searching box for known gun...")
g.update()

dbValue =  GunArea(guns[curGunPeriod - 14], curGunPeriod)

if dbValue[0] > valueGun[0]:
	
	g.show("Success! Placing the gun array with your gun")
	g.update()

	g.new("")
	g.putcells(valueGun[1])
	rect = g.getrect()
	
	g.new("")
	g.putcells(cells, -rect[0], -rect[1] + 650 * (curGunPeriod - 14))
	cells = g.getcells(g.getrect())
	guns[curGunPeriod - 14] = cells
	
	GunPlacer(guns)
	g.setpos("0", str(650 * (curGunPeriod - 14)))
	g.setmag(-1)
	g.note("Congrats! You've found a better gun! \n  You gun value = {0}, The best known value = {1}".format(valueGun[0], dbValue[0]))
	g.exit("Please save the file, and post it as attachemnt on the forum")
else:
	g.new("")
	g.putcells(valueGun[1])
	g.note("This is not a better gun :( \n You gun value = {0}, The best value = {1}".format(valueGun[0], dbValue[0]))
	g.exit("Here is your gun")
	
Esempio n. 12
0
def setposint(x,y):
   # convert integer coords to strings and set viewport position
   golly.setpos(str(x), str(y))
Esempio n. 13
0
def setposint(x,y):
    # convert integer coords to strings and set viewport position
    golly.setpos(str(x), str(y))
Esempio n. 14
0
# Slow glider page, for Mozilla CA presentation

import golly as g
from glife.base import glider, flip_x
import time

# Conway's Life
g.setrule("B3/S23")

glider.display("Slow Glider", x=-20, y=20, A = flip_x)
g.setpos('0', '0')
g.setoption('fullscreen', True)
g.setstep(0)

while True:
    time.sleep(.5)
    g.step()
    g.update()