Beispiel #1
0
    def up(self, pos):
        if not self.enabled:
            return

        for e in self.elements.itervalues():
            e.state = "inactive"

            if (pos[0] > e.x and pos[0] < e.x + e.w and pos[1] > e.y and pos[1] < e.y + e.h) and e.event:
                event.pub(e.event, None)

        centered = False
        for b in self.uni.bodies.itervalues():
            sp = util.toScreen(b.position, self.camera)

            if (sp[0] - pos[0])**2 + (sp[1] - pos[1])**2 < (b.r*self.camera.zoom)**2:
                self.camera.center(b)
                centered = True

        if not centered:
            self.camera.release()
Beispiel #2
0
    def update (self, dt):
        """Pushes the uni 'dt' seconds forward in time."""

        for i in range(1, 5, 1):
            self.RK4(dt, i)

        for b in self.bodies.itervalues():
            rd = b.rk4data

            b.position.x = b.rk4data.px[0] + dt * (rd.vx[0] + 2*rd.vx[1] + 2*rd.vx[2] + rd.vx[3]) / 6.0
            b.position.y = b.rk4data.py[0] + dt * (rd.vy[0] + 2*rd.vy[1] + 2*rd.vy[2] + rd.vy[3]) / 6.0
            b.position.z = b.rk4data.pz[0] + dt * (rd.vz[0] + 2*rd.vz[1] + 2*rd.vz[2] + rd.vz[3]) / 6.0

            b.velocity.x = b.rk4data.vx[0] + dt * (rd.ax[0] + 2*rd.ax[1] + 2*rd.ax[2] + rd.ax[3]) / 6.0
            b.velocity.y = b.rk4data.vy[0] + dt * (rd.ay[0] + 2*rd.ay[1] + 2*rd.ay[2] + rd.ay[3]) / 6.0
            b.velocity.z = b.rk4data.vz[0] + dt * (rd.az[0] + 2*rd.az[1] + 2*rd.az[2] + rd.az[3]) / 6.0

        #Finish the update:
        self.time       += dt
        self.nupdates   += 1
        event.pub("update_done", self)
Beispiel #3
0
    gevent.sub("interrupt", user.interrupt_handler)
#</events>










#<setup>
print "Starting the simulation."
print
gevent.pub("report", None)
#</setup>












#<main>
while run: