def draw_dna(): # === load DNA pallate pallate = cellPallate() pallate.load() # === let user select DNA 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() 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
def simpleCellTest(): x = randrange(-10000,10000) y = randrange(-10000,10000) c = cell(x,y) assert c.x == x, 'cell x location incorrect' assert c.y == y, 'cell y location incorrect' assert len(c.DNA) >= DNA_MINLEN, 'cell DNA too small' assert len(c.DNA) <= DNA_MAXLEN, 'cell DNA too large' for base in BASES: try: c.DNA.index(base) except: assert False, str(c.DNA)+'\nDNA string does not have each base'+str(BASES) # TODO: any other value errors? return c
assert r<thresh,\ 'direction spread is not equal. bias='+str(float(r)/float(n)) mobileVsImmobile = (up+down+left+right) - none assert mobileVsImmobile > 0, 'too many cells spawn camping! Upper codons need boost?' logging.info( 'movement magnitude histogram: '+str(histogram) ) # for i in range(1,nBins): # if i < nBins/2.0: # assert histogram[i]>=histogram[i-1], 'values biased low' # elif i > nBins/2.0: # assert histogram[i]<=histogram[i-1], 'values biased high' # else: print str(i)+'=?='+str(nBins/2) # assert histogram[i] > 0, 'values not spread well enough' logging.info( ' ==================================== ' ) #Main: n = 5000 #number of cells in histogram tests cellList = list() for i in range(n): cellList.append(cell(1,1)) #timedRuns(cell,[123,345],100) simpleCellDiagnostic(simpleCellTest()) checkColorHistogram(cellList) checkNNweights(cellList) checkMovementHistogram(cellList) #endMain