Example #1
0
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')
Example #2
0
def testkey():
    if results and g.getevent().startswith("key x"):
        g.setlayer(results_layer)
        g.select(g.getrect())
        g.copy()
        g.select([])
        g.setlayer(work_layer)
Example #3
0
def trygliders(ginfo):
    gdistance = ginfo / 4
    phase = ginfo % 4
    bstatus = boxstatus
    pstatus = popstatus
    for num in xrange(8):
        tlist = form(celllist, num)
        rect = boxform(fullrect, num)
        g.new('')
        g.putcells(tlist)
        gx = rect[0] - 3 - gdistance
        gy = rect[1] - 3 - gdistance
        for w in xrange(rect[2] + 5):
            g.new('')
            g.putcells(tlist)
            g.putcells(glider[phase], gx + w, gy)
            g.fit()
            g.update()
            for gen in xrange(1000):
                g.run(1)
                if int(g.getpop()) <= 2:
                    g.new('')
                    g.show("Found clean glider destruction.")
                    status = 0, num, phase, [gx + w, gy]
                    putcells_and_fit(result(celllist, status))
                    g.exit()
            box = g.getrect()[2:]
            # Checking the bounding box size and population against the current lowest found.
            if reduce(mul, box) < reduce(mul, bstatus[0]):
                bstatus = (box, num, phase, [gx + w, gy])
            pop = int(g.getpop())
            if pop < pstatus[0]:
                pstatus = (pop, num, phase, [gx + w, gy])
            # Show results if the user presses certain keys
            event = g.getevent()
            if event.startswith("key x"):
                g.new('')
                put_result_pair(celllist, bstatus, pstatus)
                g.select(g.getrect())
                g.copy()
                g.select([])
                g.note(
                    "Minimum bounding box and population collisions copied to clipboard."
                )
            if event.startswith("key q"):
                g.new('')
                g.show("Search stopped.")
                put_result_pair(celllist, bstatus, pstatus)
                g.fit()
                g.exit()
            g.show(
                "Searching for a 1-glider destruction... press <x> to copy minimum bounding box and population results to clipboard; press <q> to quit. Stats: minimum bounding box %dx%d, minimum population %d"
                % (bstatus[0][0], bstatus[0][1], pstatus[0]))
    return bstatus, pstatus
	def Main(self):
		
		g.show("left click on a pattern to change, 'h' for help")
		gollyMode = False
		
		while True:
		
			event = g.getevent()
			
			if ("key" in event and "return" in event) or (gollyMode and " a " in event):
				gollyMode = not gollyMode
				
				if gollyMode:
					g.show("In golly mode")
					g.update()

				else: 
					g.show("left click on a pattern, right click to finish")
					g.setrule("B3/S23")
					g.setalgo("HashLife")
					g.reset()
				
					g.update()
				
				continue 
				
			if gollyMode:
				
				if " delete " in event: 
					g.clear(0)
					
				if "click" in event and "ctrl" in event and g.getxy() != "":
					
					x, y = g.getxy().split()
					
					cell = g.getcell(int(x), int(y))
					
					if cell >= 0 and cell <= 1:
						g.setcell(int(x), int(y), 1 - cell)
					
					g.update()
				
				if " c " in event and "ctrl" in event and g.getselrect() != []:	
					g.copy()
				
				if " v " in event and "ctrl" in event and g.getxy() != "":
				
					x, y = g.getxy().split()
					
					g.paste(int(x), int(y), "or")
				
				if " space " in event:	
					if "ctrl" in event:
						g.run(10)
					else:
						g.run(1)
						
				g.doevent(event)
				continue 
				
			
			if "click" in event:
				
				if "left" in event:
					
					if self.ExistinCircuitHandler() == None:
						if self.SignalClickHandler(event) == None:
							g.show("left click on a pattern, h for help")
		
		
			elif "key" in event:
				if " space " in event:
					for i in xrange(0, 30):
						g.run(60)
						g.update()
						
					g.reset()
					g.update()		
					
				if " a " in event:
					
					if g.getrule() == "Perrier":
						g.setrule("B3/S23")
						g.setalgo("HashLife")
						g.update()
						
						
					else:
						g.setrule("Perrier")
						
						for key in self.smarCells:
							x, y = key.split(":")
							g.setcell(int(x), int(y),  self.smarCells[key] + 2)
						
						gollyMode = True
						g.show("In golly mode")
						g.update()
				
				if " s " in event:
					fname = os.path.join(g.getdir("data"), "MetadataManager.json")
					#self.Save(fname)
				
				if " h " in event:
					noteMessage = "Viewing and Selecting\n\n"
					noteMessage += "'left click' to chose gun or glider\n"
					noteMessage += "'a' to see in colors, a to go back \n"
					noteMessage += "'space' see ahead 1800 generations \n"
					noteMessage += "'enter' gollyMode, stays in the script \n"
					
					noteMessage += "\n Editing Gun \n\n"
					noteMessage += "'left click' to place\n"
					noteMessage += "'right click' to switch gun/orientation \n"
					noteMessage += "'delete' to delete the gun \n"
					noteMessage += "'left-right arrow' - one step adjustment\n"
					
					noteMessage += "\n In Golly Mode \n\n"
					noteMessage += "'delete' to clear selection\n"
					noteMessage += "'ctrl' + 'click' to draw \n"
					noteMessage += "'ctrl' + 'c' to copy selection \n"
					noteMessage += "'ctrl' + 'v' to paste in mouse location \n"
					noteMessage += "'space' + to run 1 generation \n"
					noteMessage += "'ctrl' +'space' to run 10 generations \n"
				
					g.note(noteMessage)
Example #5
0
patts = open("rles.txt", "r", newline="\r\n")
cols = open("colseqs.txt", "r", newline="\r\n")

sols = 0
count = 0
popseq = ""
for i in range(0, GEN_CHECK):
    popseq += str(chr(33 + (int(g.getpop()) % 64)))
    g.run(1)
g.new("Solutions")
curr_patt = patts.readline()
while curr_patt != "":
    curr_col = cols.readline()
    g.show(
        str(sols) + " solutions found, " + str(count) +
        " collisions tried. Press <x> to copy current results to clipboard. Press <esc> to quit."
    )
    if popseq in curr_col:
        g.putcells(g.parse(curr_patt), offset, 0)
        offset += 75
        sols += 1
    event = g.getevent()
    if event.startswith("key x"):
        g.select(g.getrect())
        g.copy()
        g.select([])
    count += 1
    curr_patt = patts.readline()
patts.close()
cols.close()
Example #6
0
if g.getrule() != 'LifeHistory':
    g.exit('The rule should be in LifeHistory.')

# Get catalyst in various positions
if g.getselrect() != []:
    g.shrink()
pattern = g.getcells(r)
patrlelist = []
translist =[(1,0,0,1), (1,0,0,-1), (-1,0,0,1), (-1,0,0,-1),
            (0,1,1,0), (0,-1,1,0), (0,1,-1,0), (0,-1,-1,0)]
# Get unique transformed patterns
for trans in translist:
    g.new('')
    g.putcells(g.transform(pattern, 0, 0, *trans))
    g.select(g.getrect())
    g.copy()
    patrle = ''.join(g.getclipstr().split('\n')[1:])
    if patrle not in patrlelist:
        patrlelist.append(patrle)
patrles = '\n'.join(patrlelist)

# Save data to file
catpath = g.savedialog('Catalyst File', 'all files(*.*)|*', catdir)
try:
    with open(catpath, 'w') as catfile:
        catfile.write(patrles)
    g.exit('Catalyst file successfully generated at {}'.format(catpath))
except:
    if catpath == '':
        g.setclipstr(patrles)
        g.exit('No filename specified, saved it to clipboard instead.')
Example #7
0
    def Main(self):

        g.show("left click on a pattern to change, 'h' for help")
        gollyMode = False

        while True:

            event = g.getevent()

            if ("key" in event and "return" in event) or (gollyMode
                                                          and " a " in event):
                gollyMode = not gollyMode

                if gollyMode:
                    g.show("In golly mode")
                    g.update()

                else:
                    g.show("left click on a pattern, right click to finish")
                    g.setrule("B3/S23")
                    g.setalgo("HashLife")
                    g.reset()

                    g.update()

                continue

            if gollyMode:

                if " delete " in event:
                    g.clear(0)

                if "click" in event and "ctrl" in event and g.getxy() != "":

                    x, y = g.getxy().split()

                    cell = g.getcell(int(x), int(y))

                    if cell >= 0 and cell <= 1:
                        g.setcell(int(x), int(y), 1 - cell)

                    g.update()

                if " c " in event and "ctrl" in event and g.getselrect() != []:
                    g.copy()

                if " v " in event and "ctrl" in event and g.getxy() != "":

                    x, y = g.getxy().split()

                    g.paste(int(x), int(y), "or")

                if " space " in event:
                    if "ctrl" in event:
                        g.run(10)
                    else:
                        g.run(1)

                g.doevent(event)
                continue

            if "click" in event:

                if "left" in event:

                    if self.ExistinCircuitHandler() == None:
                        if self.SignalClickHandler(event) == None:
                            g.show("left click on a pattern, h for help")

            elif "key" in event:
                if " space " in event:
                    for i in xrange(0, 30):
                        g.run(60)
                        g.update()

                    g.reset()
                    g.update()

                if " a " in event:

                    if g.getrule() == "Perrier":
                        g.setrule("B3/S23")
                        g.setalgo("HashLife")
                        g.update()

                    else:
                        g.setrule("Perrier")

                        for key in self.smarCells:
                            x, y = key.split(":")
                            g.setcell(int(x), int(y), self.smarCells[key] + 2)

                        gollyMode = True
                        g.show("In golly mode")
                        g.update()

                if " s " in event:
                    fname = os.path.join(g.getdir("data"),
                                         "MetadataManager.json")
                    #self.Save(fname)

                if " h " in event:
                    noteMessage = "Viewing and Selecting\n\n"
                    noteMessage += "'left click' to chose gun or glider\n"
                    noteMessage += "'a' to see in colors, a to go back \n"
                    noteMessage += "'space' see ahead 1800 generations \n"
                    noteMessage += "'enter' gollyMode, stays in the script \n"

                    noteMessage += "\n Editing Gun \n\n"
                    noteMessage += "'left click' to place\n"
                    noteMessage += "'right click' to switch gun/orientation \n"
                    noteMessage += "'delete' to delete the gun \n"
                    noteMessage += "'left-right arrow' - one step adjustment\n"

                    noteMessage += "\n In Golly Mode \n\n"
                    noteMessage += "'delete' to clear selection\n"
                    noteMessage += "'ctrl' + 'click' to draw \n"
                    noteMessage += "'ctrl' + 'c' to copy selection \n"
                    noteMessage += "'ctrl' + 'v' to paste in mouse location \n"
                    noteMessage += "'space' + to run 1 generation \n"
                    noteMessage += "'ctrl' +'space' to run 10 generations \n"

                    g.note(noteMessage)