omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Show all scene child nodes

    Pythonista
    4
    7
    5292
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • imnegan
      imnegan last edited by

      Hi all,

      I am building a model of the solar system using the Scene class. In the model each planet is a child node of the sun, and the moons are child nodes of their respective planets.

      Is there a way to show all child nodes of a selected node on screen without adding them as child node of the Scene itself? For example: Jupiter, when selected, is at the centre of the screen as the parent node. All of its moons (Io, Europa, etc) are Jupiter's child nodes and would be shown also.

      1 Reply Last reply Reply Quote 0
      • ccc
        ccc last edited by ccc

        It is hard to answer these questions without working code. My sense is that a sprite's children need to be inside its frame while the planets orbit around the outside of the sun's frame. I am no good with scene animations but we need some sample code of a rotating planet in an elliptical orbit around a star... (help needed!)

        import scene
        
        '''
        Trying to create a rotating earth in an eliptical orbit around the sun.
        '''
        
        class SolorSystemScene(scene.Scene):
           def setup(self):
               center = self.bounds.center()
               sun = scene.SpriteNode('plc:Star', position=center, parent=self)
               earth = scene.SpriteNode('plc:Tree_Ugly', position=center + (150, 150),
                                        parent=self, speed=0.2)
               earth.run_action(scene.Action.rotate_by(10))
               earth.run_action(scene.Action.move_to(center.x - 150, center.y - 150))
        
        scene.run(SolorSystemScene())
        
        1 Reply Last reply Reply Quote 0
        • abcabc
          abcabc last edited by

          Hope this helps

          
          import scene
          from math import pi
          
          '''
          Trying to create a rotating earth in an eliptical orbit around the sun.
          '''
          
          class SolorSystemScene(scene.Scene):
              def setup(self):
                  center = self.bounds.center()
                  sun = scene.SpriteNode('plc:Star', position=center, parent=self)
                  earth_anchor = scene.Node(position=center, parent=self)
                  earth = scene.SpriteNode('plc:Tree_Ugly', position=(0, 150))
                  earth_anchor.add_child(earth) 
                  self_rotate_action = scene.Action.repeat(scene.Action.sequence(scene.Action.rotate_to(20*pi, 5),
                      scene.Action.rotate_to(0,0), 0),0)      
                  earth.run_action(self_rotate_action)
                  rotate_action = scene.Action.repeat(scene.Action.sequence(scene.Action.rotate_to(20*pi, 20),
                      scene.Action.rotate_to(0,0), 0),0)
                  earth_anchor.run_action(rotate_action)
          
          scene.run(SolorSystemScene())
          
          1 Reply Last reply Reply Quote 0
          • ccc
            ccc last edited by ccc

            Cool... more appropriate icons, clockwise rotation, etc...

            Edit: counter clockwise rotation and orbit in alignment with @JonB comments below...

            import scene
            from math import pi
            
            '''
            Trying to create a rotating earth in an eliptical orbit around the sun.
            '''
            
            
            class SolorSystemScene(scene.Scene):
                def setup(self):
                    center = self.bounds.center()
                    sun = scene.SpriteNode('emj:Sun_1', position=center, parent=self)
                    earth_anchor = scene.Node(position=center, parent=self)
                    earth = scene.SpriteNode('emj:Moon_5', position=(0, 150))
                    earth_anchor.add_child(earth)
                    A = scene.Action
                    self_rotate_action = A.repeat(A.sequence(A.rotate_to(20 * pi, 5),
                                                             A.rotate_to(0, 0), 0), 0)
                    earth.run_action(self_rotate_action)
                    rotate_action = A.repeat(A.sequence(A.rotate_to(20 * pi, 20),
                                                        A.rotate_to(0, 0), 0), 0)
                    earth_anchor.run_action(rotate_action)
            
            scene.run(SolorSystemScene())
            
            JonB 1 Reply Last reply Reply Quote 0
            • JonB
              JonB @ccc last edited by

              In this solar system, all the planets orbit counterclockwise, and most rotate that way too...

              1 Reply Last reply Reply Quote 0
              • ccc
                ccc last edited by

                Thanks @JonB I corrected inline above... Now all is right with the universe ;-). Happy 2017!

                1 Reply Last reply Reply Quote 0
                • ccc
                  ccc last edited by

                  More Planets...

                  import scene
                  from math import pi
                  
                  A = scene.Action
                  
                  '''
                  Trying to create a rotating earth in an eliptical orbit around the sun.
                  '''
                  
                  def make_action(steps, speed):
                      return A.repeat(A.sequence(A.rotate_to(steps * pi, speed),
                                                 A.rotate_to(0, 0), 0), 0)
                  
                  
                  class Planet(scene.Node):
                      def __init__(self, parent, orbit=150, image_name=''):
                          parent.add_child(self)
                          self.position = parent.bounds.center()
                          self.run_action(make_action(20, orbit / 5))
                          image_name = image_name or 'emj:Moon_5'        
                          planet = scene.SpriteNode(image_name, parent=self, position=(0, orbit))
                          planet.run_action(make_action(20, 5))
                          
                          
                  class SolorSystemScene(scene.Scene):
                      def setup(self):
                          center = self.bounds.center()
                          sun = scene.SpriteNode('emj:Sun_1', position=center, parent=self)
                          earth = Planet(self)
                          venus = Planet(self, 75, 'emj:Blue_Circle')
                          mars = Planet(self, 225, 'emj:Moon_2')
                          saturn = Planet(self, 300, 'emj:Moon_4')
                          jupiter = Planet(self, 375, 'emj:Moon_1')
                  
                  scene.run(SolorSystemScene())
                  
                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Powered by NodeBB Forums | Contributors