예제 #1
0
    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)
예제 #2
0
파일: rules.py 프로젝트: msarch/py
 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)
예제 #3
0
파일: rules.py 프로젝트: msarch/py
 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)
예제 #4
0
파일: field.py 프로젝트: msarch/py
    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)
예제 #5
0
파일: __main__.py 프로젝트: msarch/py
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()
예제 #6
0
파일: __main__.py 프로젝트: msarch/py
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()
예제 #7
0
파일: __main__.py 프로젝트: msarch/py
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()
예제 #8
0
파일: animate.py 프로젝트: msarch/py
 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()
예제 #9
0
 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()
예제 #10
0
파일: field.py 프로젝트: msarch/py
 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()
예제 #11
0
 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()
예제 #12
0
파일: field.py 프로젝트: msarch/py
 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'
예제 #13
0
 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'
예제 #14
0
파일: engine.py 프로젝트: msarch/py
    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()
예제 #15
0
파일: actor.py 프로젝트: msarch/py
 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)
예제 #16
0
파일: actor.py 프로젝트: msarch/py
 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'
예제 #17
0
파일: engine.py 프로젝트: msarch/py
    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
예제 #18
0
파일: actor.py 프로젝트: msarch/py
 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'
예제 #19
0
파일: rules.py 프로젝트: msarch/py
 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')
예제 #20
0
파일: rules.py 프로젝트: msarch/py
 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')
예제 #21
0
파일: __main__.py 프로젝트: msarch/py
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)
예제 #22
0
파일: __main__.py 프로젝트: msarch/py
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)
예제 #23
0
파일: scene.py 프로젝트: msarch/py
    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())
예제 #24
0
파일: scene.py 프로젝트: msarch/py
    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())
예제 #25
0
파일: rules.py 프로젝트: msarch/py
 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
예제 #26
0
 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
예제 #27
0
파일: field.py 프로젝트: msarch/py
 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)
예제 #28
0
 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)
예제 #29
0
파일: creature2.py 프로젝트: msarch/py
def tick(actor, dt):
    db_print('tick Ghost 2')
    actor.anchorx += 0.5
예제 #30
0
파일: engine.py 프로젝트: msarch/py
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)
예제 #31
0
파일: rules.py 프로젝트: msarch/py
 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])
예제 #32
0
파일: engine.py 프로젝트: msarch/py
def toggle_fps_display():
    db_print('toggle_fps')
    Field.show_fps = (True,False)[Field.show_fps]
예제 #33
0
파일: actor.py 프로젝트: msarch/py
 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)
예제 #34
0
파일: scene.py 프로젝트: msarch/py
 def paint(self):
     db_print ('SCENE PAINT')
     for actor in self.actor_registry:
         actor.paint()
예제 #35
0
파일: engine.py 프로젝트: msarch/py
def toggle_fps_display():
    db_print('toggle_fps')
    Field.show_fps = (True, False)[Field.show_fps]
예제 #36
0
파일: field.py 프로젝트: msarch/py
 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)
예제 #37
0
파일: animate.py 프로젝트: msarch/py
 def toggle_pause(self):
     global paused
     db_print('toggle_pause')
     self.paused = (True,False)[self.paused]
예제 #38
0
파일: engine.py 프로젝트: msarch/py
def toggle_debug():
    db_print('toggle_debug')
    debug.DEBUG = (True, False)[debug.DEBUG]
예제 #39
0
파일: rules.py 프로젝트: msarch/py
def rule1(actor,dt):
    db_print ('applying rule1 for actor #',actor.nume)
    actor.angle +=1
예제 #40
0
파일: rules.py 프로젝트: msarch/py
def rule2(actor,dt):
    db_print ('applying rule2 for actor #',actor.nume)
    actor.anchorx+=0.5
예제 #41
0
파일: engine.py 프로젝트: msarch/py
def toggle_pause():
    db_print('toggle_pause')
    Field.paused = (True,False)[Field.paused]
예제 #42
0
파일: field.py 프로젝트: msarch/py
 def init():
     Field.registry=[]
     scene_folder=Field.get_scene_folder()
     Field.parse_folder(scene_folder)
     db_print(records.SIZE)
예제 #43
0
def bind(rule, cell):
    Field.rule_stack.append(rule)
    Field.cell_stack.append(cell)
    db_print('rule/cell', rule, cell, 'added to Field')
예제 #44
0
 def __init__(self, **kwargs):
     self.cells = []
     db_print(kwargs)
     for i in kwargs:
         setattr(self, i, kwargs[i])
예제 #45
0
파일: scene.py 프로젝트: msarch/py
 def tick(self, dt):
     db_print ('SCENE TICK')
     for actor in self.actor_registry:
         actor.tick(actor, dt)
예제 #46
0
 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])
예제 #47
0
 def toggle_pause(self):
     global paused
     db_print('toggle_pause')
     self.paused = (True, False)[self.paused]
예제 #48
0
 def eval(self, rule):
     self.rules.append(rule)
     db_print(rule, 'added to', self, 'rules')
     db_print('rules cells =', rule.cells)
예제 #49
0
 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
예제 #50
0
파일: engine.py 프로젝트: msarch/py
def toggle_debug():
    db_print('toggle_debug')
    debug.DEBUG = (True,False)[debug.DEBUG]
예제 #51
0
파일: field.py 프로젝트: msarch/py
 def display(self,cell):
     self.cells.append(cell)
     db_print(cell, 'added to', self, 'cells')
예제 #52
0
파일: field.py 프로젝트: msarch/py
 def eval(self,rule):
     self.rules.append(rule)
     db_print(rule, 'added to', self, 'rules')
     db_print('rules cells =', rule.cells)
예제 #53
0
 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
예제 #54
0
파일: field.py 프로젝트: msarch/py
 def __init__(self,**kwargs):
     self.cells = []
     db_print(kwargs)
     for i in kwargs:
         setattr(self,i,kwargs[i])
예제 #55
0
 def display(self, cell):
     self.cells.append(cell)
     db_print(cell, 'added to', self, 'cells')
예제 #56
0
파일: field.py 프로젝트: msarch/py
 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
예제 #57
0
파일: rules.py 프로젝트: msarch/py
 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
예제 #58
0
파일: engine.py 프로젝트: msarch/py
def toggle_pause():
    db_print('toggle_pause')
    Field.paused = (True, False)[Field.paused]