def setup(): world = PolygonWorld(20, 20, 30, 200) sim = simcx.PyafaiSimulator(world) vis = simcx.PyafaiVisual(sim) display = simcx.Display() display.add_simulator(sim) display.add_visual(vis, 0, 0)
def setup(equal_threshold): world = PolygonWorld(20, 20, 30, equal_threshold=equal_threshold) sim = simcx.PyafaiSimulator(world) vis = simcx.PyafaiVisual(sim) display = simcx.Display() display.add_simulator(sim) display.add_visual(vis, 0, 200) display.add_visual(SegregationPlot(sim, width=600, height=200))
def setup(n, width=800, height=600): world = pyafai.World2D(width, height) sim = simcx.PyafaiSimulator(world) vis = simcx.PyafaiVisual(sim) display = simcx.Display(width, height, caption="Random Walkers") display.add_simulator(sim) display.add_visual(vis) # Create agents x = np.random.randint(10, width - 10, n) y = np.random.randint(10, height - 10, n) speed = np.random.randint(50, 100, n) angle = np.random.randint(0, 359, n) for i in range(n): ag = RandomWalker(x[i], y[i], speed[i], angle[i], ('c3B', (random.randint(0, 255), random.randint( 0, 255), random.randint(0, 255))), 5) world.add_agent(ag)
# generate initial positions self.x = np.random.normal(0, 1, self.n) self.y = np.random.normal(0, 1, self.n) class PointsVisual(simcx.MplVisual): def __init__(self, sim: RandomParticles): super(PointsVisual, self).__init__(sim) # create initial plot self.ax = self.figure.add_subplot(111) self.ax.set_xlim(-4, 4) self.ax.set_ylim(-4, 4) self.l, = self.ax.plot(self.sim.x, self.sim.y, '.') def draw(self): self.l.set_data(self.sim.x, self.sim.y) if __name__ == '__main__': sim = RandomParticles() vis = PointsVisual(sim) display = simcx.Display() display.add_simulator(sim) display.add_visual(vis) # record the simulation on video display.start_recording('random.mp4') simcx.run()
# # elif self.freq == 1 and self.sim.values[x][y].freq == 0: # self._grid[y][x].colors[:] = self.QUAD_WHITE # elif self.pheromone == 0 and self.trail == 0 and self.freq == 0: # self._grid[y][x].colors[:] = self.QUAD_WHITE if __name__ == '__main__': move_type = "von" pick_type = "moore" map_x = 45 map_y = 45 initial_ants = 50 initial_sticks = 50 backwards = 1 # 1-> can go backwards || 0 -> cannot go backwards warp = 1 # 1-> map warps || 0 -> map does not warp zones = None #zones = [[0, 0, 0, 00, 100, 0, 0, 0, 0], [0, 0, 0, 0, 50, 0, 0, 0, 0]] pheromone = 0 # -> 0 no pheromone | 1 -> pheromone allways | 2 -> pheromone only when carrying aas = AntsAndSticks(move_type, pick_type, map_x, map_y, initial_ants, initial_sticks, backwards, warp, zones, pheromone) vis = Grid2D(aas, 5, trail=1, pheromone=0, freq=0) display = simcx.Display(interval=0.05) display.add_simulator(aas) display.add_visual(vis) simcx.run()
self._batch.draw() def update_graphics(self): y = self.size // 2 - self.sim.cur_step + 1 for x in range(self.size): if self.sim.values[x] == 1: self._batch.add( 4, pyglet.gl.GL_QUADS, None, ('v2i', (x * self._cell, y * self._cell, x * self._cell + self._cell, y * self._cell, x * self._cell + self._cell, y * self._cell + self._cell, x * self._cell, y * self._cell + self._cell)), ('c3B', self.QUAD_BLACK)) if __name__ == '__main__': display = simcx.Display(interval=0.2, visible=False) ca126 = CA(126, 101) ca126.init_fixed() display.add_simulator(ca126) vis = CAVisual(ca126, 10) display.add_visual(vis) display.set_visible(True) simcx.run()