from breve import Control, Mobile, Cube, PushInterpreter, PushProgram from breve import createInstances, vector class Controller(Control): def __init__(self): Control.__init__(self) self.agents = [Agent()] class Agent(Mobile): def __init__(self): Mobile.__init__(self) self.inter = PushInterpreter() self.inter.clearStacks() self.inter.addInstruction(self, 'callback', 'PRNTSTCKS') self.inter.addInstruction(self, 'setVel', 'SVEL') self.code = PushProgram() #self.inter.pushVector(vector(-1,1,1)) #self.code.parse('''( SVEL )''') self.code.parse('''( -1:-1:-1 SVEL )''') self.setShape(Cube().initWith(vector(1,1,1))) self.max_velocity = 1.0 self.max_accel = self.max_velocity/10 def callback(self): print self.inter.printStacks() def getVel(self): self.inter.pushVector(self.getVelocity()) def setVel(self): # get acceleration a = self.inter.getVectorStackTop() #self.inter.popVectorStack() self.setVelocity(a) def iterate(self): self.inter.run(self.code) #c.endSimulation() # instantiate the controller to initialize the simulation c = Controller()