示例#1
0
文件: main.py 项目: antoinevg/phail
def main(*argv):

  try:   # Import Psyco if available
    import psyco
    psyco.full()
  except ImportError:
    print "psyco not available"

  mainwindow = gtk.Window()
  mainwindow.connect("delete_event", delete_event)  

  mainwindow.set_default_size(WIDTH, HEIGHT)
  mainwindow.add(TheWorld)
  mainwindow.show()

  TheWorld.create_width = WIDTH
  TheWorld.create_height = HEIGHT
  TheWorld.show()  
  TheEden.populate()

  # choose one
  TheSpaceTime.timer_id = gobject.idle_add(TheSpaceTime.tick)
  #TheSpaceTime.start()

  gtk.gdk.threads_enter()        
  gtk.main()
  gtk.gdk.threads_leave()        
示例#2
0
  def do_button_press_event(self, event):
    if self.target.__name__ == "Plant":
      print "PLANT"
      TheWorld.add(Plant())
      return

    # change class definition as opposed to instance definition
    print self.target.myfn
    self.target.myfn = ClassEditor.foo_fn    
    print self.target.myfn
    print "Changed: ", self.target.__name__
示例#3
0
文件: eden.py 项目: antoinevg/phail
  def populate(self):

    # set up display ###########################################################
    TheWorld.display_fps = False
    #TheWorld.xoffset += 35.0
    #TheWorld.yoffset -= 20.0
    TheWorld.scale = 1.0
    TheWorld.show_grid = False
    show_toolbox = True
    
    # Cellular Automaton Reactor ##############################################
    #careactor_1 = CAReactor(0.0, 50.0)
    #TheWorld.add(careactor_1)
    
    if False:    
      # whack some resources into the world
      for i in range(NUM_PLANTS):
        TheWorld.add(Plant())      
      # and some people
      for i in range(NUM_HUMANS):
        TheWorld.add(Human())
      # and some creatures
      for i in range(NUM_ANIMALS):
        TheWorld.add(Animal())
    

    if True: # set to True for particle reactor, False for fluid reactor
      # type i ##################################################################
      yscale = 250 # scale for y-axis of graph    
      reactor_1 = SimpleReactor(-50, 0, num_particles = [yscale], do_reaction = True)
      TheWorld.add(reactor_1)
      reactor_1.rotor = reactor_1.create_rotor(0, 0, 5, 150)
      graph_particletypes = Graph(-50.0, -50)
      graph_particletypes.attachprobe(reactor_1, 'particlecount_by_type', 0.0, yscale)
      TheWorld.add(graph_particletypes)

      # type ii #################################################################
      reactor_2 = SimpleReactor(50.0, 0, num_particles = [yscale], do_reaction = True)#, yscale/2])
      reactor_2.rotor = reactor_2.create_rotor(0, 0, 5, 150)
      TheWorld.add(reactor_2)
      pump = Pump(0, 0, 8)
      TheWorld.add(pump)
      reactor_2.connect_input(pump)
      graph_particletypes = Graph(50.0, -50)
      graph_particletypes.attachprobe(reactor_2, 'particlecount_by_type', 0.0, yscale)
      TheWorld.add(graph_particletypes)
      sink = Sink(100.0, 0)
      sink.connect_input(reactor_2)
      TheWorld.add(sink)

      #reactor_2 = SimpleReactor(50.0, 90.0, num_particles = [yscale], do_reaction = True)#, yscale/2])
      #reactor_2.rotor = reactor_2.create_rotor(0, 0, 5, 150)
      #TheWorld.add(reactor_2)
      #pump = Pump(0, 90.0, 10)
      #TheWorld.add(pump)
      #reactor_2.connect_input(pump)
      #graph_particletypes = Graph(50.0, 50)
      #graph_particletypes.attachprobe(reactor_2, 'particlecount_by_type', 0.0, yscale)
      #TheWorld.add(graph_particletypes)
      #sink = Sink(100.0, 90.0)
      #sink.connect_input(reactor_2)
      #TheWorld.add(sink)
      
      #TheWorld.add(SimpleReactor(0, 0))
      #TheWorld.add(SimpleReactor(0, -50))
      
      # type iii ################################################################
      #reactor_3 = PlugReactor(0.0, 50.0)
      #TheWorld.add(reactor_3)
      
    else:
      show_toolbox = False
      # 2D Fluid Reactor
      fluidreactor_1 = FluidReactor(0.0, 0.0)
      TheWorld.add(fluidreactor_1)
                 
    # set up toolbox ###########################################################
    if show_toolbox:
      toolbox = ToolBox(133.5, -10.0, 40.0, 120.0)
      TheWorld.add(toolbox)

      # a source
      pump = Pump(0, -80)
      toolbox.swallow(pump)

      # a reactor 
      reactor = SimpleReactor(0, -50)
      toolbox.swallow(reactor)

      # a rotor
      rotor = Rotor(0.0, -10.0)
      toolbox.swallow(rotor)
      print rotor.top, rotor.bottom

      # a graph 
      graph = Graph(0.0, 30.0)
      toolbox.swallow(graph)

      # a pulse button
      pulse = Pulse(0.0, 70.0, "Pulse", None, 10)
      toolbox.swallow(pulse)

      # a sink
      sink = Sink(0, 90)
      toolbox.swallow(sink)
示例#4
0
  def populate(self):
    
    # add class editors to world
    #editor_animal = ClassEditor(Animal)
    #TheWorld.add(editor_animal)
    #editor_plant = ClassEditor(Plant)
    #TheWorld.add(editor_plant)
    #editor_world = ClassEditor(TheWorld.__class__)
    #TheWorld.add(editor_world)
    
    # whack some resources into the world
    for i in range(NUM_PLANTS):
      TheWorld.add(Plant())
      
    # and some people
    for i in range(NUM_HUMANS):
      TheWorld.add(Human())
    
    # and some creatures
    for i in range(NUM_ANIMALS):
      TheWorld.add(Animal())
    
    # a creature & a plant to monitor
    #monitored_animal = Animal()
    #TheWorld.add(monitored_animal)
    #monitored_plant = Plant()
    #TheWorld.add(monitored_plant)
    
    # Some Object Viewers    
    #viewer_animal = ObjectViewer(monitored_animal)
    #TheWorld.add(viewer_animal)
    #viewer_plant = ObjectViewer(monitored_plant)
    #TheWorld.add(viewer_plant)
    
    #node1 = NodeThing("node 1")
    #node2 = NodeThing("node 2")
    #node3 = NodeThing("node 3")
    #node4 = NodeThing("node 4")
    #node5 = NodeThing("node 5")
    #node6 = NodeThing("node 6")
    #node7 = NodeThing("node 7")
    #node8 = NodeThing("node 8")
    #node1.encapsulate(node2)
    #node1.encapsulate(node3)
    #node2.encapsulate(node4)
    #node2.encapsulate(node5)
    #node3.encapsulate(node6)
    #node3.encapsulate(node7)
    #node3.encapsulate(node8)
    #node_tree1 = NodeTree(node1)
    #TheWorld.add(node_tree1)
    
    #test_class = TestClass()
    #test_class = Proto()
    #test_class = node_tree1
    #src_file = inspect.getsourcefile(test_class.__class__)
    #ast = compiler.parse(open(src_file).read())
    #node_tree2 = SubClasser.node_tree(test_class)
    #TheWorld.add(node_tree2)

    
    #TheWorld.add(node1)
    
    # toss in a graph
    #graph = Graph()
    #graph.attachprobe(monitored_animal, "rotation")
    #graph.attachprobe(TheWorld, "framerate", 0.0, 60.0)
    #TheWorld.add(graph)
    
    # add a console
    #console = Console()
    #TheWorld.add(console)
    
    
    
    TheWorld.scale = 0.8