本文整理汇总了Python中Graph.Graph.plotCircle方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.plotCircle方法的具体用法?Python Graph.plotCircle怎么用?Python Graph.plotCircle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph.Graph
的用法示例。
在下文中一共展示了Graph.plotCircle方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import plotCircle [as 别名]
#.........这里部分代码省略.........
# 1. The program needs to get the new states produced by the Simulation Engine since the last screen refresh.
static, states = self.simEngine.getNewStates() #the Simulation Engine passes back new states and the static world
self.simHistory.update(states) #updates the GUI's simulation history with the new states
# 2. The program needs to figure out what time to display based on the selected speed and what has been recorded.
systime = time.clock() #gets the system time
elapsed_time = systime - self.lastTime #calculates the elapsed time from the last time the loop was run
self.lastTime = systime #records new system time for the next loop
if not self.paused and self.dis_t <= self.buff_t: #advances the displayed time, as long as it's not ahead of the simulation and is not paused
self.dis_t += self.calculate_dis_dt(elapsed_time)
dis_t_int = int(np.floor(self.dis_t/self.writeInterval) * self.writeInterval) #finds the displayed time based on the write interval: I.E., requests closest written time to the time that should be displayed
# 3. If able to find the displayed time in recorded simulation history, the program needs to store and display the corresponding World graphically
if dis_t_int in self.simHistory.keys():
# 3.a. loads ands stores the World
static.loadDynamicState(self.simHistory[dis_t_int]) #loads the dynamic state at the displayed time into the static World object
self.world = static #sets this loaded world as the GUI's world for other menus, etc
# 3.b. displays the World on two Graph objects and draws them
#plot the world: the Animat and food, for now
for animat in self.world.animats:
self.worldGraph.plotCircle((animat.radius*2,animat.radius*2), (animat.pos[0], animat.pos[1]), self.colorGrey)
headPos = animat.pos[0]+(animat.radius)*np.cos(animat.direc), animat.pos[1]+(animat.radius)*np.sin(animat.direc)
self.worldGraph.plotCircle((.2,.2), headPos, self.colorBlack)
self.worldGraph.plotText(("Purisa", 6) , (animat.pos[0], animat.pos[1]), animat.id)
if not (animat.id in self.neuron_graphs.iterkeys()):
neuronGraph = Graph(self.root, self.neuron_box.content_bounds, [-1.3, 1.3, -1.3, 1.3])
self.neuron_graphs[animat.id] = neuronGraph
self.neuron_box.add(neuronGraph, animat.id)
neuronGraph = self.neuron_graphs[animat.id]
neuronGraph.plotCircle((2, 2), (0, 0), self.colorWhite)
neurons = animat.net.getNeurons()
for neuron in neurons:
neuronGraph.plotCircle((.05, .05), (neuron.X, neuron.Y), neuron.firing_color if neuron.isFiring() else neuron.color)
neuronGraph.draw(self.canvas)
for food in self.world.foods:
#foodImage = self.worldGraph.size_up(Image.open(food.image), (1,1), 0)
if food.amt > 0.0:
self.worldGraph.plotCircle((1,1), food.getPos(), self.colorGreen)
self.worldGraph.plotText(("Purisa", 6) , (food.getPos()[0], food.getPos()[1]), food.getType())
#self.worldGraph.plotCircle((1,1), food.pos, self.colorGreen)
self.worldGraph.draw(self.canvas)
for type in self.tracked_types:
if type == self.TRACK_ENERGY:
for t in sorted(states.keys()):
static.loadDynamicState(states[t])
for animat in static.animats:
self.tracked_data[animat.id][type][t] = animat.Energy
elif type == self.TRACK_NEURAL_FIRINGS:
for t in sorted(states.keys()):
示例2: DevelopmentWindow
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import plotCircle [as 别名]
class DevelopmentWindow():
def __init__(self):
self.worlds = []
## Set up worlds
fLocs1 = [(2,0),(-2,0),(0,2),(0,-2),(0,3),(0,-3),(3,0),(-3,0),(4,0),(-4,0),(0,4),(0,-4),(0,7),(7,0),(-7,0)]
fLocs2 = [(1,1),(2,2),(3,3),(4,4),(3,5),(2,6),(1,7),(0,8),(-2,6),(-4,4),(-6,2),(-8,0),(-5,0),(-2,-3),(-5,-5)]
fLocs3 = [(-2,2),(-1,0),(1,0),(-1,0),(2,-2),(3,5),(-5,5),(-8,8),(10,10),(-10,10),(10,-10),(0,-1),(0,-2),(0,-3),(0,-4)]
fLocs4 = [(random.random()*20 - 20.0/2., random.random()*20 - 20.0/2.) for i in xrange(20)]
fLocs5 = [(random.random()*20 - 20.0/2., random.random()*20 - 20.0/2.) for i in xrange(20)]
self.worlds.append([1,15,20,fLocs1])
self.worlds.append([1,15,20,fLocs2])
self.worlds.append([1,15,20,fLocs3])
self.worlds.append([1,20,20,fLocs4])
self.worlds.append([1,20,20,fLocs5])
#parameters
self.sP = SimParam.SimParam()
self.sP.setWorld(1,self.worlds[0][0],self.worlds[0][1],self.worlds[0][2],self.worlds[0][3]) #change first index to change default world
self.sP.setWorld(2,self.worlds[1][0],self.worlds[1][1],self.worlds[1][2],self.worlds[1][3])
self.sP.setWorld(3,self.worlds[2][0],self.worlds[2][1],self.worlds[2][2],self.worlds[2][3])
self.sP.setWorld(4,self.worlds[3][0],self.worlds[3][1],self.worlds[3][2],self.worlds[3][3])
self.sP.setWorld(5,self.worlds[4][0],self.worlds[4][1],self.worlds[4][2],self.worlds[4][3])
self.sP.setAnimParams(1,1,(0,0))
self.paused = True #paused?
self.lastTime = 0
self.sim_msps = 0
self.dis_t = 1 #the t being displayed
self.buff_t = 0
self.writeInterval = 100
self.simHistory = {} #this will fill with produced worlds from the simulations
self.simEngine = SimulationEngine.SimulationEngine()
self.developmentHistory = {}
self.layoutHist = 300 #y value holder for new aniimat config button placement
self.layoutList = [] # holds config/delete animat buttons and labels for any animats other than default
#intialize TK
self.root = tk.Tk()
self.root.title("Development Simulation")
self.canvas = tk.Canvas(self.root, width=1080, height=720)
self.canvas.pack()
#some general-purpose colors
self.colorWhite = "#ffffff"
self.colorGrey = "#dddddd"
self.colorBlack = "#000000"
self.colorLightBlue = "#ADD8E6"
self.colorBlue = "#0000ff"
self.colorRed = "#ff0000"
#file options
self.file_opt = options = {}
options['defaultextension'] = '.netsim'
options['filetypes'] = [('all files', '.*'), ('text files', '.txt'), ('Simulation Files', '.netsim')]
#options['initialdir'] = 'C:\\'
options['initialfile'] = '.netsim'
options['parent'] = self.root
options['title'] = 'Save Simulation As...'
#set up menu bar
menubar = tk.Menu(self.root)
filemenu = tk.Menu(menubar, tearoff=0)
filemenu.add_command(label="Start Simulation", command=self.startSimulation)
filemenu.add_command(label="Save Current Development Simulation", command=self.saveCurrentSimulation)
filemenu.add_command(label="Load Development from File", command=self.loadSimulationFromFile)
filemenu.add_separator()
filemenu.add_command(label="Load Results from Evolutionary Algorithm",command=self.loadEvo)
filemenu.add_separator()
filemenu.add_command(label="Exit",command=self.root.destroy)
menubar.add_cascade(label="File", menu=filemenu)
speedmenu = tk.Menu(menubar, tearoff=0)
speedmenu.add_command(label="1ms", command=lambda:self.setWriteInterval(1))
speedmenu.add_command(label="25ms", command=lambda:self.setWriteInterval(25))
speedmenu.add_command(label="50ms", command=lambda:self.setWriteInterval(50))
speedmenu.add_command(label="100ms", command=lambda:self.setWriteInterval(100))
speedmenu.add_command(label="1s", command=lambda:self.setWriteInterval(1000))
speedmenu.add_command(label="Do not write")
speedmenu.invoke(3) #default write interval is 100
editmenu = tk.Menu(menubar, tearoff=0)
editmenu.add_command(label="Parameters",command = self.editParameters)
editmenu.add_cascade(label="Write Interval", menu=speedmenu)
menubar.add_cascade(label="Edit", menu=editmenu)
self.root.config(menu=menubar)
#Set up neuron graph and text log box and control bar
self.neuronGraph = Graph(self.root, [75, 75, 475, 475], [-1.1, 1.1, -1.1, 1.1])
self.neuronGraph.plotCircle((2, 2), (0, 0), self.colorWhite)
self.neuronGraph.title("Development")
self.neuronGraph.xlabel("XAXIS")
self.neuronGraph.ylabel("YAXIS")
self.neuronGraph.draw(self.canvas)
#Set up World Parameter Options
self.animNum_sv = tk.StringVar()
self.animNum_sv.set(str(self.sP.getAnimNum(1)))
self.foodNum_sv = tk.StringVar()
self.foodNum_sv.set(str(self.sP.getFoodNum(1)))
self.arenaSize_sv = tk.StringVar()
self.arenaSize_sv.set(str(self.sP.getWorldSize(1)))
title = tk.Label(self.root, text="Parameter Settings",font="bold",relief="ridge",padx=5,pady=5)
#.........这里部分代码省略.........
示例3: refreshScreen
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import plotCircle [as 别名]
def refreshScreen(self):
# 1. The program needs to get the new states produced by the Simulation Engine since the last screen refresh.
static, states = self.simEngine.getNewStates() #the Simulation Engine passes back new states and the static world
self.simHistory.update(states) #updates the GUI's simulation history with the new states
# 2. The program needs to figure out what time to display based on the selected speed and what has been recorded.
systime = time.clock() #gets the system time
elapsed_time = systime - self.lastTime #calculates the elapsed time from the last time the loop was run
self.lastTime = systime #records new system time for the next loop
if not self.paused and self.dis_t <= self.buff_t: #advances the displayed time, as long as it's not ahead of the simulation and is not paused
self.dis_t += self.calculate_dis_dt(elapsed_time)
dis_t_int = int(np.floor(self.dis_t/self.writeInterval) * self.writeInterval) #finds the displayed time based on the write interval: I.E., requests closest written time to the time that should be displayed
# 3. If able to find the displayed time in recorded simulation history, the program needs to store and display the corresponding World graphically
if dis_t_int in self.simHistory.keys():
# 3.a. loads ands stores the World
static.loadDynamicState(self.simHistory[dis_t_int]) #loads the dynamic state at the displayed time into the static World object
self.world = static #sets this loaded world as the GUI's world for other menus, etc
# 3.b. displays the World on two Graph objects and draws them
#plot the world: the Animat and food, for now
for animat in self.world.animats:
self.worldGraph.plotCircle((animat.radius*2,animat.radius*2), (animat.pos[0], animat.pos[1]), self.colorGrey)
headPos = animat.pos[0]+(animat.radius)*np.cos(animat.direc), animat.pos[1]+(animat.radius)*np.sin(animat.direc)
self.worldGraph.plotCircle((.2,.2), headPos, self.colorBlack)
self.worldGraph.plotText(("Purisa", 6) , (animat.pos[0], animat.pos[1]), animat.id)
if not (animat.id in self.neuron_graphs.iterkeys()):
neuronGraph = Graph(self.root, self.neuron_box.content_bounds, [-1.3, 1.3, -1.3, 1.3])
self.neuron_graphs[animat.id] = neuronGraph
self.neuron_box.add(neuronGraph, animat.id)
neuronGraph = self.neuron_graphs[animat.id]
neuronGraph.plotCircle((2, 2), (0, 0), self.colorWhite)
neurons = animat.net.getNeurons()
for neuron in neurons:
neuronGraph.plotCircle((.05, .05), (neuron.X, neuron.Y), neuron.firing_color if neuron.isFiring() else neuron.color)
neuronGraph.draw(self.canvas)
for food in self.world.foods:
#foodImage = self.worldGraph.size_up(Image.open(food.image), (1,1), 0)
if food.amt > 0.0:
self.worldGraph.plotCircle((1,1), food.getPos(), self.colorGreen)
self.worldGraph.plotText(("Purisa", 6) , (food.getPos()[0], food.getPos()[1]), food.getType())
#self.worldGraph.plotCircle((1,1), food.pos, self.colorGreen)
self.worldGraph.draw(self.canvas)
for type in self.tracked_types:
if type == self.TRACK_ENERGY:
for t in sorted(states.keys()):
static.loadDynamicState(states[t])
for animat in static.animats:
self.tracked_data[animat.id][type][t] = animat.Energy
elif type == self.TRACK_NEURAL_FIRINGS:
for t in sorted(states.keys()):
static.loadDynamicState(states[t])
for animat in static.animats:
self.tracked_data[animat.id][type][t] = animat.net.get_neurons_firing()
elif type == self.TRACK_POS:
for t in sorted(states.keys()):
static.loadDynamicState(states[t])
for animat in static.animats:
self.tracked_data[animat.id][type][t] = animat.pos
elif type == self.TRACK_LFP:
continue
for t in sorted(states.keys()):
static.loadDynamicState(states[t])
for animat in static.animats:
self.tracked_data[animat.id][type][t] = np.mean(animat.net.v.as_numpy_array()[animat.net.excitatoryNeurons])
# 4. Regardless of displaying a World, the program needs to make sure that the display time is reasonable and update the video control bar
self.buff_t = sorted(self.simHistory.keys())[len(self.simHistory.keys())-1] #set the buffered time to the latest time in history
if (self.dis_t > self.buff_t): self.dis_t = self.buff_t #sets the display time to the buffered time, if ahead
if (self.dis_t < 0): self.dis_t = 0 #sets the display time to 0, if below 0
self.videoBar.update(dis_t_int, self.buff_t) #updates the video bar with the displayed time and the buffered time
self.videoBar.draw()
# 5. Reschedule another refresh!
self.root.after(1 if int(np.floor(1000/10)) < 1 else int(np.floor(1000/10)), self.refreshScreen) #tells Tkinter to refresh the display again in 1/20 seconds