예제 #1
0
def main():
    #Vertical distance between pixels. Maybe get this from user. minimum = 16
    pdy = 16

    #Generate & display a dot matrix printer from current selection
    dmprinter(pdy, copies=1)

    golly.setcursor("Zoom In")
    golly.setalgo("HashLife")
    golly.setbase(2)
    golly.setstep(6)
예제 #2
0
def draw_dna():
    logging.debug('loading cell pallate')
    pallate = cellPallate()
    pallate.load()

    logging.debug('getting default pallate selection')
    chosenCell = pallate.getUserChoice()
    chosenName = pallate.getSelectedCellName()
    g.show('now drawing with DNA from '+chosenName)
    logging.debug('now drawing with DNA from '+chosenName+'='+str(chosenCell))

    # prepare environment
    env = environment()
    logging.debug('turning on golly even script access')
    event = g.getevent(True)  # turn on golly event script access
    # === let user draw
    g.setcursor("Draw")
    try:    #this try statement is just to ensure the 'finally' block is run
        while True:    # loop until stop button is pressed
            event = g.getevent() # event is a string like "click 10 20 left none"
            if len(event) < 1: # do not try to split empty string
                continue
            else:
                logging.debug('event recieved: "'+event+'"')
                evt, xstr, ystr, butt, mods = event.split()
                if evt=="click" and butt=="left" and mods=="none": # left click
#                    logging.debug('left click detected at '+xstr+','+ystr)
                    x = int(xstr)
                    y = int(ystr)
                    env.cellList.setCell(x,y,cell=cell(x,y,chosenCell.DNA))    #add cell to list
                    g.setcell(x,y,1)    #fill in functional cell
                    env.drawColor()    #update color layer to match
                    g.update()        #update golly display
                    logging.info('cell ('+xstr+','+ystr+') painted with "'+chosenName+'"')
                    g.show('cell painted. press "Esc" to stop drawing')
                else:
                    logging.info('event "'+event+'" not recognized')
    except:    # re-raise any errors encountered
        logging.error('unexpected error: '+sys.exc_info()[0])
        raise
    finally:
        g.getevent(False) # return event handling to golly
        g.show('done drawing '+chosenName+' cells.')
        logging.debug('done drawing '+chosenName+' cells.')
        # === teardown
        env.teardown()
        return
예제 #3
0
currcursor = g.getcursor()
currcolors = g.getcolors()
currstates = g.numstates()
deads, deadr, deadg, deadb = g.getcolors(0)

# create histogram in separate layer
g.setoption("stacklayers", 0)
g.setoption("tilelayers", 0)
g.setoption("showlayerbar", 1)
if histlayer == -1:
    histlayer = g.addlayer()
else:
    g.setlayer(histlayer)

g.new(histname)
g.setcursor(currcursor)

# use a Generations rule so we can append extra state for drawing text & lines
g.setrule("//" + str(currstates + 1))
extrastate = currstates
currcolors.append(extrastate)
if (deadr + deadg + deadb) / 3 > 128:
    # use black if light background
    currcolors.append(0)
    currcolors.append(0)
    currcolors.append(0)
else:
    # use white if dark background
    currcolors.append(255)
    currcolors.append(255)
    currcolors.append(255)
예제 #4
0
            if started and len(mousepos) == 0:
                # erase old line if mouse is not over grid
                if len(oldline) > 0:
                    eraseline(oldline)
                    oldline = []
                    g.update()
            elif started and len(mousepos) > 0 and mousepos != oldmouse:
                # mouse has moved, so erase old line (if any) and draw new line
                if len(oldline) > 0: eraseline(oldline)
                x, y = mousepos.split()
                oldline = drawline(startx, starty, int(x), int(y))
                oldmouse = mousepos

# ------------------------------------------------------------------------------

g.show("Click where to start line...")
oldcursor = g.getcursor()
g.setcursor("Draw")
drawstate = g.getoption("drawingstate")
oldline = []
firstcell = []    # pos and state of the 1st cell clicked

try:
    drawlines()
finally:
    g.setcursor(oldcursor)
    if len(oldline) > 0: eraseline(oldline)
    if len(firstcell) > 0:
        x, y, s = firstcell
        g.setcell(x, y, s)
예제 #5
0
def collect_dna():
	# prepare environment
	env = environment()

	# ask user to select cell of interest
	g.setcursor("Pick")
	g.show('select cell to sample')
	event = g.getevent(True) #turn on golly event script access
	while not event.startswith("click"):
		event = g.getevent() # return event handling to golly
		# event is a string like "click 10 20 left none"
	g.getevent(False) # return event handling to golly
	evt, xstr, ystr, butt, mods = event.split()
	x = int(xstr)
	y = int(ystr)
	logging.info('cell ('+xstr+','+ystr+') selected')
	try:
		# retrieve selected cell
		selectedCell = env.cellList.findCell(x,y)
	except AttributeError:
		g.show('cannot find cell!')
		logging.error('cell not found. len(cellList)='+str(len(cellList.cells)))
		env.teardown()
		return

	# prompt user for name 
	import Tkinter as tk
	root = tk.Tk()
	class selectorDisplay:
		def __init__(self, master, selectedCell):
			self.pallate = cellPallate() # cell pallate instance for saving cell info

			self.frame = tk.Frame(master)
			self.frame.pack()
			self.cell = selectedCell
			
			instructions = tk.Label(root, text='Please enter a name for this cell.\n\
			                        NOTE: names should only consist of letters, numbers, "_", and "-"')
			instructions.pack()
			
			self.entry = tk.Entry(master)
			self.entry.pack()
			self.entry.focus_set()

			button_save = tk.Button(master, text="save", width=10, 
			                        command=self.submitEntry)
			button_save.pack()
			
			button_cancel = tk.Button(master, text="cancel", width=10,
			                          command=self.frame.quit)
			button_cancel.pack()
			
		def submitEntry(self):
			# save the cell
			name = self.entry.get()

			g.show('saving ' + name + ' to ' + CELL_COLLECTION_DIR)
			self.pallate.saveCell(self.cell,name)

			self.frame.quit() # close dialog			
			g.show('DNA sample saved to collection')

	app = selectorDisplay(root,selectedCell)
	root.mainloop()
	import _tkinter
	try:
		root.destroy() # optional...ish
	except _tkinter.TclError:
		pass # ignore failed destroy due to already being destroyed.

	env.teardown()
	return
         oldmouse = mousepos
         g.update()

# ------------------------------------------------------------------------------

selrect = g.getselrect()
if len(selrect) == 0: g.exit("There is no selection.")
selpatt = g.getcells(selrect)

# remember initial selection in case user aborts script
firstrect = g.getselrect()
firstpatt = g.getcells(selrect)

g.show("Click anywhere in selection, move mouse and click again..." + helpmsg)
oldcursor = g.getcursor()
g.setcursor("Move")
oldcells = []

try:
   aborted = True
   moveselection()
   aborted = False
finally:
   g.setcursor(oldcursor)
   if aborted:
      g.clear(0)
      if len(oldcells) > 0: g.putcells(oldcells)
      g.putcells(firstpatt)
      g.select(firstrect)
   else:
      g.show(" ")
예제 #7
0
            oldmouse = mousepos
            g.update()

# ------------------------------------------------------------------------------

selrect = g.getselrect()
if len(selrect) == 0: g.exit("There is no selection.")
selpatt = g.getcells(selrect)

# remember initial selection in case user aborts script
firstrect = g.getselrect()
firstpatt = g.getcells(selrect)

g.show("Click anywhere in selection, move mouse and click again..." + helpmsg)
oldcursor = g.getcursor()
g.setcursor("Move")
oldcells = []

try:
    aborted = True
    moveselection()
    aborted = False
finally:
    g.setcursor(oldcursor)
    if aborted:
        g.clear(0)
        if len(oldcells) > 0: g.putcells(oldcells)
        g.putcells(firstpatt)
        g.select(firstrect)
    else:
        g.show(" ")
예제 #8
0
            if started and len(mousepos) == 0:
                # erase old line if mouse is not over grid
                if len(oldline) > 0:
                    eraseline(oldline)
                    oldline = []
                    g.update()
            elif started and len(mousepos) > 0 and mousepos != oldmouse:
                # mouse has moved, so erase old line (if any) and draw new line
                if len(oldline) > 0: eraseline(oldline)
                x, y = mousepos.split()
                oldline = drawline(startx, starty, int(x), int(y))
                oldmouse = mousepos

# ------------------------------------------------------------------------------

g.show("Click where to start line...")
oldcursor = g.getcursor()
g.setcursor("Draw")
drawstate = g.getoption("drawingstate")
oldline = []
firstcell = []    # pos and state of the 1st cell clicked

try:
    drawlines()
finally:
    g.setcursor(oldcursor)
    if len(oldline) > 0: eraseline(oldline)
    if len(firstcell) > 0:
        x, y, s = firstcell
        g.setcell(x, y, s)
예제 #9
0
# Creates Subfolder specific to Rule Set to hold Generation Patterns
fileLoc += rule.replace("/", "_") + "/"
if (os.path.isdir(fileLoc) is not True):
    os.mkdir(fileLoc)

# Prepare File Names for each Genereration's Pattern File
fileNamePrefix = fileLoc + rule.replace("/", "_") + "_"

# Loop and Save Patterns
for i in range(int(numGenerations) + 1):
    # Stop Loop if Universe is Empty
    if (g.empty()):
        break

    # Determine File Names
    fileNameRLE = fileNamePrefix + str(i) + ".rle"
    # Determine Previous File Names
    fileNamePrevRLE = fileNamePrefix + str(i - 1) + ".rle"

    g.save(fileNameRLE, "rle")
    # Compare Previous Generation to Determine Class I Systems
    if (i > 0 and compare_rle(fileNameRLE, fileNamePrevRLE)):
        break

    g.run(1)

# Prepare for Viewing
g.fit()
g.setcursor("Select")
예제 #10
0
 def display(self, title = "untitled", x = 0, y = 0, A = identity):
    """Paste pattern into new universe and display it all."""
    golly.new(title)
    golly.putcells(self, x, y, *A)
    golly.fit()
    golly.setcursor(zoomin)
예제 #11
0
 def display(self, title = "untitled", x = 0, y = 0, A = identity):
     """Paste pattern into new universe and display it all."""
     golly.new(title)
     golly.putcells(self, x, y, *A)
     golly.fit()
     golly.setcursor(zoomin)