Пример #1
0
    def ExtractTruthPhysics(self):
        self.Tree.SetBranchStatus("Hit_x", 1)
        self.Tree.SetBranchStatus("Hit_y", 1)
        self.Tree.SetBranchStatus("Hit_z", 1)
        self.Tree.SetBranchStatus("Hit_particlePdgId", 1)
        self.Tree.SetBranchStatus("Hit_G4ParentTrackId", 1)
        self.Tree.SetBranchStatus("Hit_G4TrackId", 1)
        self.Tree.SetBranchStatus("Hit_particlePx", 1)
        self.Tree.SetBranchStatus("Hit_particlePy", 1)
        self.Tree.SetBranchStatus("Hit_particlePz", 1)
        self.Tree.SetBranchStatus("Hit_particleEnergy", 1)
        self.Tree.SetBranchStatus("Track_NumHits")

        self.Tree.GetEntry(self.EventNumber)

        particleSet = set()

        for hitn in range(int(self.Tree.NumHits)):
            if self.Tree.Hit_particleEnergy[
                    hitn] > self.TRUTH_PARTICLE_E_THRESHOLD:
                particleSet.add(
                    physics.Particle(int(self.Tree.Hit_G4TrackId[hitn]),
                                     int(self.Tree.Hit_particlePdgId[hitn]),
                                     int(self.Tree.Hit_G4ParentTrackId[hitn])))

        #print(particleSet)
        for particle in particleSet:
            currentTrack = physics.Track(particle)
            for hitn in range(int(self.Tree.NumHits)):
                if (int(self.Tree.Hit_G4TrackId[hitn]) == particle.trackID):
                    time = self.Tree.Hit_time[hitn]
                    location = physics.Vector(self.Tree.Hit_x[hitn],
                                              self.Tree.Hit_y[hitn],
                                              self.Tree.Hit_z[hitn])
                    energy = self.Tree.Hit_particleEnergy[hitn]
                    momentum = physics.Vector(self.Tree.Hit_particlePx[hitn],
                                              self.Tree.Hit_particlePy[hitn],
                                              self.Tree.Hit_particlePz[hitn])
                    point = physics.TrackPoint(time, location, energy,
                                               momentum)
                    currentTrack.AddPoint(point)

            if (len(currentTrack.pointList)) <= 2:
                continue

            if currentTrack.TimeRange() < self.timeRangeCut:
                continue

            currentTrack.pointList.sort()

            self.truthTrackList.append(currentTrack)

        self.ResetTracks()
        self.truthTrackList.sort()
        self.t0 = min(
            [track.pointList[0].time for track in self.truthTrackList])
        self.tm = max([
            track.pointList[len(track.pointList) - 1].time
            for track in self.truthTrackList
        ])
Пример #2
0
 def __init__(self, center, radius):
     super().__init__()
     self.center = center
     self.size = 2 * float(radius)
     self.speed = float(0)
     self.direction = p.Vector(0, 0, 0)
     self.color = p.Vector(1, 1, 1)
Пример #3
0
 def __init__(self, center, size):
     super().__init__()
     self.center = center
     self.size = float(size)
     self.orientation = p.Vector(0, 0, 0)
     self.speed = float(0)
     self.direction = p.Vector(0, 0, 0)
     self.color = p.Vector(1, 1, 1)
Пример #4
0
 def __init__(self, config, universe, radius=100, mass=1000):
     self.thrustVectors = {}
     self.location = physics.Vector(0, 0, 0)
     self.rotation = physics.Vector(0, 0, 0, 1)
     self.velocity = physics.Vector(0, 0, 0)
     self.universe = universe
     self.radius = radius
     self.mass = mass
     self.color = (random.randint(0, 255), random.randint(0, 255),
                   random.randint(0, 255))
     self.events = []
Пример #5
0
def sim_spawn_random_entity(command):
    cube = e.Cube(p.Vector(0, 0, 0), 1)
    cube.speed = p.random.uniform(-3, 3)
    cube.direction = p.Vector.random(-0.5, 0.5).normalize()
    cube.color = p.Vector.random(0, 1)
    with lock:
        world.add_entity(cube)
    logger.info(f'sim_spawn_random_entity entity={cube}')
Пример #6
0
def move(event):
    'Simulate movement of screen.'
    global x, y
    if not lock:
        diff = physics.Vector(x - event.x, y - event.y)
        screen.move('animate', diff.x, diff.y)
        floor_height = SCREEN_HEIGHT - FLOOR_SPACE - BALL_RADIUS
        for ball in balls:
            ball.pos += diff
            if ball.pos.y >= floor_height:
                ball.vel.y += diff.y * FPS
                floor(ball)
        x, y = event.x, event.y
Пример #7
0
 def fire(self, tube):
     print("Starting to fire missile")
     self.location = tube.ship.location + (
         (tube.position *
          (tube.ship.radius + self.radius)) / tube.position.magnitude())
     print("Missile start loc:", self.location)
     print("Ship fire loc:", tube.ship.location)
     print("Ship radius:", tube.ship.radius)
     print("Tube location:", tube.position)
     #  self.rotation = physics.rotate(tube.ship.rotation + tube.orientation, center=tube.ship.center)
     self.rotation = physics.Vector(
         1, 1, 1) * (tube.position / tube.position.magnitude())
     self.velocity = self.rotation * 20
     self.instantiate()
     print("Fired Missile!")
Пример #8
0
    def test01():
        msg = bytearray()
        w_byte(msg, 3)
        w_short(msg, 6)
        w_int(msg, 4)
        w_float(msg, 5)
        w_vector(msg, p.Vector(1337, 31337, 42))

        b = r_byte(msg)
        s = r_short(msg)
        i = r_int(msg)
        f = r_float(msg)
        v = r_vector(msg)
        assert b == 3 and s == 6 and i == 4 and f == 5
        assert v.x == 1337 and v.y == 31337 and v.z == 42
Пример #9
0
def r_vector(msg):
    x, y, z = r_float(msg), r_float(msg), r_float(msg)
    return p.Vector(x, y, z)
Пример #10
0
    def __init__(self):
        self.boundaries = e.Cube(p.Vector(0, 0, 0), 3)
        self.ids = 0
        self.entities = dict()

        self.paused = False
Пример #11
0
            elif update_type == World.DIFF:
                diff = n.r_blob(msg, n.r_byte(msg))
                self.entities[entity_id].update(diff)
            else:
                raise NotImplementedError
        return self


if __name__ == '__main__':
    p.random.seed(1337)

    from_world = World()
    to_world = World()
    to_world.boundaries.color = p.Vector.random()
    colors = [
        p.Vector(0x00 / 0xFF, 0x99 / 0xFF, 0xCC / 0xFF),
        p.Vector(0xCC / 0xFF, 0xFF / 0xFF, 0xCC / 0xFF)
    ]
    for i in range(2):
        cube = e.Cube(p.Vector(0, 0, 0), 1)
        cube.speed = p.random.uniform(-3, 3)
        cube.direction = p.Vector.random(-0.5, 0.5).normalize()
        cube.color = colors[i]
        to_world.add_entity(cube)
    colors = [
        p.Vector(0x66 / 0xFF, 0xCC / 0xFF, 0xFF / 0xFF),
        p.Vector(0x00 / 0xFF, 0x33 / 0xFF, 0x99 / 0xFF)
    ]
    for i in range(2):
        sphere = e.Sphere(p.Vector(0, 0, 0), p.random.uniform(0.4, 0.8))
        sphere.speed = p.random.uniform(-3, 3)
Пример #12
0
def main():
    pygame.init()

    window_width = 400
    window_height = 300
    screen = pygame.display.set_mode((window_width, window_height))
    pygame.display.set_caption("Gobcoin-Coincidence - By Zyzzyva038")
    white = (255, 255, 255)
    light_blue = (32, 171, 255)
    pink = (255, 90, 195)

    coin1 = physics.Coin(10, 100, 170, light_blue)
    coin2 = physics.Coin(15, 300, 150, pink)
    friction_constant = 0.15

    elastic_constant = 10

    fps_clock = pygame.time.Clock()
    fps = 60
    time_constant = 60

    move = False

    direction = 0
    direction_original_surf = pygame.transform.scale(
        pygame.image.load("images/direction.png"), (100, 100))
    rotation_speed = 5
    direction_x = 60
    direction_y = 220
    left_key_down = False
    right_key_down = False
    direction_original_vector = physics.Vector(0, 1)

    space_down = False
    finger = 0
    finger_speed = 24
    finger_surfs = tuple(
        (pygame.image.load("images/fingers/%d.png" % x) for x in range(0, 8)))
    finger_rect = finger_surfs[0].get_rect()
    finger_rect.topleft = (0, 0)
    initial_speed_constant = 10
    fire = False

    turn = Turn()

    while True:
        # draw screen
        screen.fill(white)
        direction_surf = pygame.transform.rotate(direction_original_surf,
                                                 direction)
        direction_rect = direction_surf.get_rect()
        direction_rect.center = (direction_x, direction_y)
        screen.blit(direction_surf, direction_rect)
        screen.blit(finger_surfs[int(finger)], finger_rect)
        coin1.draw(screen)
        coin2.draw(screen)
        pygame.display.update()

        # get events
        for event in pygame.event.get():
            if event.type == QUIT:
                terminate()
            elif event.type == KEYDOWN:
                if event.key in (K_LEFT, K_a):
                    left_key_down = True
                elif event.key in (K_RIGHT, K_d):
                    right_key_down = True
                elif event.key == K_SPACE:
                    space_down = True

            elif event.type == KEYUP:
                if event.key in (K_LEFT, K_a):
                    left_key_down = False
                elif event.key in (K_RIGHT, K_d):
                    right_key_down = False
                elif event.key == K_SPACE:
                    space_down = False
                    fire = True

        # update game state
        if coin1.velocity.length < 0.01 and coin2.velocity.length < 0.01:
            if move:
                print("Stop\n")
                turn.next()
                move = False
        elif not move:
            print("Start\n")
            move = True

        if left_key_down:
            direction += rotation_speed * time_constant / fps
        elif right_key_down:
            direction -= rotation_speed * time_constant / fps
        direction_radian = direction / 180 * math.pi
        direction_vector = direction_original_vector.rotate(direction_radian)
        screen_direction_vector = physics.Vector(direction_vector.x,
                                                 -direction_vector.y)

        elastic1, elastic2 = physics.get_elastic(coin1, coin2,
                                                 elastic_constant)
        coin1.apply_force(elastic1)
        coin2.apply_force(elastic2)

        coin1.apply_friction(friction_constant)
        coin2.apply_friction(friction_constant)

        coin1.update(time_constant / fps)
        coin2.update(time_constant / fps)

        if space_down:
            finger += finger_speed / fps
            if finger >= 7:
                finger = 0
        else:
            finger = 0

        if fire and not move:
            if turn.turn == 1:
                coin1.velocity = screen_direction_vector * finger * initial_speed_constant
            elif turn.turn == 2:
                coin2.velocity = screen_direction_vector * finger * initial_speed_constant

        if (coin1.position.x <= -coin1.mass
                or coin1.position.x >= window_width + coin1.mass
                or coin1.position.y <= -coin1.mass
                or coin1.position.y >= window_height + coin1.mass):
            win_state = 2
            return win_state
        elif (coin2.position.x <= -coin2.mass
              or coin2.position.x >= window_width + coin1.mass
              or coin2.position.y <= -coin2.mass
              or coin2.position.y >= window_height + coin1.mass):
            win_state = 1
            return win_state

        # tick FPS
        fps_clock.tick(fps)
Пример #13
0
 def dummy():
     return Cube(p.Vector(1337, 1338, 1339), 13310)
Пример #14
0
 def dummy():
     return Sphere(p.Vector(1337, 1338, 1339), 13310)
Пример #15
0
        pyglet.gl.gluQuadricNormals(quadric, pyglet.gl.GLU_SMOOTH)
        pyglet.gl.gluSphere(quadric, self.size / 2, 10, 10)

        pyglet.gl.glPopMatrix()

    def tick(self, dt):
        self.center.move(dt * self.speed, self.direction)


class EntityType(enum.Enum):
    CUBE = 0x1
    SPHERE = 0x2


if __name__ == '__main__':
    to_entity = Cube(p.Vector(4, 5, 6), 42)
    assert Entity.new(EntityType.CUBE, Entity.diff(Cube.dummy(),
                                                   to_entity)) == to_entity

    to_entity = Sphere(p.Vector(4, 5, 6), 42)
    assert Entity.new(EntityType.SPHERE, Entity.diff(Sphere.dummy(),
                                                     to_entity)) == to_entity

    from_entity = Cube(p.Vector(1, 2, 3), 1337)
    to_entity = Cube(p.Vector(4, 5, 6), 42)
    to_entity.orientation = p.Vector.random()
    to_entity.direction = p.Vector.random()
    to_entity.color = p.Vector.random()
    from_entity.update(Entity.diff(from_entity, to_entity))
    assert from_entity == to_entity
Пример #16
0
api.register(Component.Component)
api.register(Component.Drive)
api.register(Component.WeaponsStation)
api.register(Component.ShieldGenerator)
api.register(SharedClientDataStore.SharedClientDataStore)
api.register(Client.ClientUpdater)

print(api.getTable())

network.start(api)

ship1 = Ship.Ship(shipConf, universe)
ship1.name = "Aggressor"
ship2 = Ship.Ship(shipConf, universe)
ship2.name = "Victim"
ship1.location = physics.Vector(5000, 1000, 0)
ship2.location = physics.Vector(1000, 1000, 0)
ship2.rotation = physics.Vector(0, 0, 0)
universe.add(ship1)
universe.add(ship2)

missile = Missile.Missile(missileConf, universe)

for i in ship1.components.values():
    if i.type == "WeaponsStation":
        i.energy = 1
        i.load(missile)

if "-v" in sys.argv:
    screen.fill((255, 255, 255))