def __init__(self, shape=None, defined_name=None, posx=0.0, posy=0.0, angle=0.0, vx=0.0, vy=0.0, va=0.0, drawable=True): self.shape = shape self.defined_name = defined_name self.posx = posx * 1.0 self.posy = posy * 1.0 self.angle = angle * 1.0 self.vx = vx * 1.0 self.vy = vy * 1.0 self.va = va * 1.0 # angular velocity self.drawable = drawable if self.drawable: Field.display_list.append(self) # hack to retrieve name if self.defined_name == None: (filename, line_number, function_name, text) = extract_stack()[-2] self.defined_name = text[:text.find('=')].strip() db_print('Cell added to Field : ', self)
def __init__(self,minx,miny,maxx,maxy): self.minx = minx self.miny = miny self.maxx = maxx self.maxy = maxy db_print('created Bounce rule, limits are : ', self.minx, self.miny ,self.maxx, self.maxy)
def __init__(self, minx, miny, maxx, maxy): self.minx = minx self.miny = miny self.maxx = maxx self.maxy = maxy db_print('created Bounce rule, limits are : ', self.minx, self.miny, self.maxx, self.maxy)
def __init__(self, shape=None, defined_name=None, posx=0.0, posy=0.0, angle=0.0, vx=0.0, vy=0.0, va=0.0, drawable=True): self.shape=shape self.defined_name=defined_name self.posx = posx*1.0 self.posy = posy*1.0 self.angle = angle*1.0 self.vx=vx*1.0 self.vy=vy*1.0 self.va=va*1.0 # angular velocity self.drawable=drawable if self.drawable: Field.display_list.append(self) # hack to retrieve name if self.defined_name == None: (filename,line_number,function_name,text)=extract_stack()[-2] self.defined_name = text[:text.find('=')].strip() db_print('Cell added to Field : ', self)
def main(): fn = sys.argv[1] db_print('user folder is :', fn) if os.path.exists(fn): db_print(os.path.basename(fn), 'exists') # file exists s = Scene(fn) e = Engine(s, duration=70) e.run()
def main(): fn = sys.argv[1] # TODO : use getopt? db_print('user folder is :', fn) if os.path.exists(fn): db_print(os.path.basename(fn), 'exists') # file exists parse_folder(fn) e = Engine(actors=Actor.registry) e.run()
def main(): fn = sys.argv[1] # TODO : use getopt? db_print ('user folder is :',fn) if os.path.exists(fn): db_print (os.path.basename(fn),'exists') # file exists parse_folder(fn) e = Engine(actors=Actor.registry) e.run()
def paint_a_frame(self, dt): """Clear the current OpenGL context, calls cell's paint_all method """ if not self.paused: self.gl_clear() db_print(self.field.cells) for cell in self.field.cells: cell.paint() if self.show_fps: self.clock_display.draw()
def get_scene_folder(): ''' returns the folder specified by the user ''' fn = sys.argv[1] # TODO : use getopt? db_print ('user folder is :',fn) if os.path.exists(fn): db_print (os.path.basename(fn),'exists') # file exists return(fn) else: exit()
def get_scene_folder(): ''' returns the folder specified by the user ''' fn = sys.argv[1] # TODO : use getopt? db_print('user folder is :', fn) if os.path.exists(fn): db_print(os.path.basename(fn), 'exists') # file exists return (fn) else: exit()
def paint(self): if self.drawable: glPushMatrix() glTranslatef(self.posx, self.posy, 0) glRotatef(self.angle, 0, 0, 1) batch = self.shape.get_batch() batch.draw() glPopMatrix() db_print(self, 'drawn') else: print 'cell', self, 'is not drawable'
def frame_paint(self,dt): """Clear the current OpenGL context, reset the model/view matrix and invoke the `()` methods of the zulus """ if not self.paused: self.gl_clear() self.scene.paint() db_print ('ENGINE PAINT',self.chrono) if self.show_fps: self.pcd.draw()
def __init__(self, shape=None, ruleset=[], anchorx=0.0, anchory=0.0, angle=0.0, drawable=True, layer=0, **kwargs): self.shape = shape self.anchorx = anchorx self.anchory = anchory self.angle = angle self.drawable = drawable self.layer = layer self.ruleset = ruleset Actor.count+=1 self.nume = Actor.count Actor.registry.append(self) db_print( 'actor #',self.nume,'added to scene', self) db_print('ruleset is :', self.ruleset,'shape is:', self.shape)
def paint(self): if self.shape: if self.drawable: pyglet.gl.glPushMatrix() pyglet.gl.glTranslatef(self.anchorx, self.anchory, 0) pyglet.gl.glRotatef(self.angle, 0, 0, 1) batch = self.shape.get_batch() batch.draw() pyglet.gl.glPopMatrix() db_print(self.nume, 'drawn') else: print 'actor', self.nume, 'not drawn' else: print 'actor', self.nume, 'has no shape'
def tick(self,dt): """Updates the scene until time out by invoquind the tick methods of the scene """ if not self.paused: self.chrono += dt db_print ('ENGINE TICK',self.chrono) if self.chrono > self.duration: exit() self.scene.tick(dt) else: pass
def paint(self): if self.shape: if self.drawable: pyglet.gl.glPushMatrix() pyglet.gl.glTranslatef(self.anchorx, self.anchory, 0) pyglet.gl.glRotatef(self.angle, 0, 0, 1) batch = self.shape.get_batch() batch.draw() pyglet.gl.glPopMatrix() db_print (self.nume, 'drawn') else: print 'actor', self.nume, 'not drawn' else: print 'actor', self.nume, 'has no shape'
def tick(self, dt, cell): db_print('checking Bounce for actor #', cell) if (cell.minx + cell.posx < self.minx or \ cell.maxx + cell.posx > self.maxx): # if bounce, cell.vx *= -1 cell.posx += dt * cell.vx cell.posy += dt * cell.vy db_print(cell.minx, cell.posx, self.minx) db_print('reverse x dir') # cell.color = choice(kapla_colors) # change clr if (cell.miny + cell.posy < self.miny or \ cell.maxy + cell.posy > self.maxy): # if bounce, cell.vy *= -1 cell.posx += dt * cell.vx cell.posy += dt * cell.vy db_print(cell.minx, cell.posx, self.minx) db_print('reverse x dir')
def tick(self,dt,cell): db_print ('checking Bounce for actor #',cell) if (cell.minx + cell.posx < self.minx or \ cell.maxx + cell.posx > self.maxx): # if bounce, cell.vx *=-1 cell.posx += dt*cell.vx cell.posy += dt*cell.vy db_print (cell.minx,cell.posx,self.minx) db_print ('reverse x dir') # cell.color = choice(kapla_colors) # change clr if (cell.miny + cell.posy < self.miny or \ cell.maxy + cell.posy > self.maxy): # if bounce, cell.vy *=-1 cell.posx += dt*cell.vx cell.posy += dt*cell.vy db_print (cell.minx,cell.posx,self.minx) db_print ('reverse x dir')
def parse_folder(scene_folder): db_print('getting modules from :',scene_folder) sys.path.insert(0,scene_folder) # include scene folder for path in glob(scene_folder+'/[!_]*.py'): db_print('trying to load :',path) name, ext = os.path.splitext(os.path.basename(path)) mdl = load_source(name, path) db_print (name, 'is loaded') db_print (mdl)
def parse_folder(scene_folder): db_print('getting modules from :', scene_folder) sys.path.insert(0, scene_folder) # include scene folder for path in glob(scene_folder + '/[!_]*.py'): db_print('trying to load :', path) name, ext = os.path.splitext(os.path.basename(path)) mdl = load_source(name, path) db_print(name, 'is loaded') db_print(mdl)
def get_actors(self): db_print('getting modules from :', self.folder) for path in glob(self.folder + '/[!_]*.py'): db_print('trying to load :', path) name, ext = os.path.splitext(os.path.basename(path)) mdl = load_source(name, path) db_print(mdl, 'is loaded') if hasattr(mdl, 'register'): self.actor_registry.extend(mdl.register())
def get_actors(self): db_print('getting modules from :',self.folder) for path in glob(self.folder+'/[!_]*.py'): db_print('trying to load :',path) name, ext = os.path.splitext(os.path.basename(path)) mdl = load_source(name, path) db_print (mdl, 'is loaded') if hasattr(mdl, 'register'): self.actor_registry.extend(mdl.register())
def tick(self,dt): for cell in self.cells: db_print ('checking Bounce for actor #',cell) if (cell.minx + cell.anchorx < self.minx or \ cell.maxx + cell.anchorx > self.maxx): # if bounce, cell.vx *=-1 db_print (cell.minx,cell.anchorx,self.minx) db_print ('reverse x dir') # cell.color = choice(kapla_colors) # change clr if (cell.miny + cell.anchory < self.miny or \ cell.maxy + cell.anchory > self.maxy): # if bounce, cell.vy *=-1
def tick(self, dt): for cell in self.cells: db_print('checking Bounce for actor #', cell) if (cell.minx + cell.anchorx < self.minx or \ cell.maxx + cell.anchorx > self.maxx): # if bounce, cell.vx *= -1 db_print(cell.minx, cell.anchorx, self.minx) db_print('reverse x dir') # cell.color = choice(kapla_colors) # change clr if (cell.miny + cell.anchory < self.miny or \ cell.maxy + cell.anchory > self.maxy): # if bounce, cell.vy *= -1
def get_scene_folder(): ''' returns the folder specified by the user ''' if len(sys.argv) == 2: fn = sys.argv[1] # TODO : use getopt? db_print ('user folder is :',fn) if os.path.exists(fn): db_print (os.path.basename(fn),'exists') # file exists return(fn) else: exit() else: # default scene folder in main folder fn = os.path.abspath(os.path.join(os.path.dirname( __file__ ),'..', DEFAULT_SCENE_FOLDER )) db_print ('user folder is :',fn) return(fn)
def get_scene_folder(): ''' returns the folder specified by the user ''' if len(sys.argv) == 2: fn = sys.argv[1] # TODO : use getopt? db_print('user folder is :', fn) if os.path.exists(fn): db_print(os.path.basename(fn), 'exists') # file exists return (fn) else: exit() else: # default scene folder in main folder fn = os.path.abspath( os.path.join(os.path.dirname(__file__), '..', DEFAULT_SCENE_FOLDER)) db_print('user folder is :', fn) return (fn)
def tick(actor, dt): db_print('tick Ghost 2') actor.anchorx += 0.5
def tick(dt): db_print( '************************** Begin Tick dt = ', dt) if Field.paused: pass else: for rule, cell in izip(Field.rule_stack, Field.cell_stack): db_print('*** calling rule :') db_print(' * rule : ', rule) db_print(' * cell : ', cell) db_print(' * dt : ', dt) if rule.active: rule.tick(dt, cell) else: pass db_print( '**************************** End Tick dt = ', dt)
def __init__(self,**kwargs): ''' a kw for delta angle, dx & dy for displacement ''' db_print(kwargs) for i in kwargs: setattr(self,i,kwargs[i])
def toggle_fps_display(): db_print('toggle_fps') Field.show_fps = (True,False)[Field.show_fps]
def tick(self, dt): # TODO for rules in self.rules for rule in self.ruleset: rule(self,dt) db_print('rules for actor number:', self.nume, self.ruleset)
def paint(self): db_print ('SCENE PAINT') for actor in self.actor_registry: actor.paint()
def toggle_fps_display(): db_print('toggle_fps') Field.show_fps = (True, False)[Field.show_fps]
def add_actor(actor): Field.registry.append(actor) db_print( 'actor #',actor,'added to Field') db_print('ruleset is :', actor.ruleset,'shape is:', actor.shape)
def toggle_pause(self): global paused db_print('toggle_pause') self.paused = (True,False)[self.paused]
def toggle_debug(): db_print('toggle_debug') debug.DEBUG = (True, False)[debug.DEBUG]
def rule1(actor,dt): db_print ('applying rule1 for actor #',actor.nume) actor.angle +=1
def rule2(actor,dt): db_print ('applying rule2 for actor #',actor.nume) actor.anchorx+=0.5
def toggle_pause(): db_print('toggle_pause') Field.paused = (True,False)[Field.paused]
def init(): Field.registry=[] scene_folder=Field.get_scene_folder() Field.parse_folder(scene_folder) db_print(records.SIZE)
def bind(rule, cell): Field.rule_stack.append(rule) Field.cell_stack.append(cell) db_print('rule/cell', rule, cell, 'added to Field')
def __init__(self, **kwargs): self.cells = [] db_print(kwargs) for i in kwargs: setattr(self, i, kwargs[i])
def tick(self, dt): db_print ('SCENE TICK') for actor in self.actor_registry: actor.tick(actor, dt)
def __init__(self, **kwargs): ''' a kw for delta angle, dx & dy for displacement ''' self.cells = [] db_print(kwargs) for i in kwargs: setattr(self, i, kwargs[i])
def toggle_pause(self): global paused db_print('toggle_pause') self.paused = (True, False)[self.paused]
def eval(self, rule): self.rules.append(rule) db_print(rule, 'added to', self, 'rules') db_print('rules cells =', rule.cells)
def tick(self, dt): for cell in self.cells: db_print('applying std_move for actor #', cell) cell.angle += self.a cell.anchorx += self.dx cell.anchory += self.dy
def toggle_debug(): db_print('toggle_debug') debug.DEBUG = (True,False)[debug.DEBUG]
def display(self,cell): self.cells.append(cell) db_print(cell, 'added to', self, 'cells')
def eval(self,rule): self.rules.append(rule) db_print(rule, 'added to', self, 'rules') db_print('rules cells =', rule.cells)
def tick(self, dt): for cell in self.cells: db_print('applying std_move for actor #', cell) cell.angle += cell.va * dt cell.anchorx += cell.vx * dt cell.anchory += cell.vy * dt
def __init__(self,**kwargs): self.cells = [] db_print(kwargs) for i in kwargs: setattr(self,i,kwargs[i])
def display(self, cell): self.cells.append(cell) db_print(cell, 'added to', self, 'cells')
def tick(self,dt): for cell in self.cells: db_print ('applying std_move for actor #',cell) cell.angle +=self.a cell.anchorx+=self.dx cell.anchory+=self.dy
def tick(self,dt,cell): db_print ('applying std_move for actor #',cell) cell.angle +=cell.va*dt cell.posx+=cell.vx*dt cell.posy+=cell.vy*dt
def toggle_pause(): db_print('toggle_pause') Field.paused = (True, False)[Field.paused]