Exemplo n.º 1
0
def initialize_particles(**kwargs):
    """
    Initialize N particles in a circular distribution around a center
    point, where N=number. Keyword arguments include a radius from the
    center, an identifier pattern and other keyword arguments that would
    instantiate a particle.
    """

    # Initialize variables needed to do initialization
    klass  = kwargs.get('type', Particle)
    number = kwargs.get('number', world_parameters.get('team_size'))
    center = kwargs.get('center', (750,750))
    radius = kwargs.get('radius', 100)
    team   = kwargs.get('team', 'ally')
    maxvel = kwargs.get('maximum_velocity', world_parameters.get('maximum_velocity'))
    home   = kwargs.get('home', None)
    params = kwargs.get('params', world_parameters)

    # Generate coordinates and particles
    coords = zip(*circular_distribute(num=number, center=center, r=radius))
    for idx, coord in enumerate(coords):
        position = Vector.arrp(*coord)
        velocity = Vector.rand(maxvel) if maxvel > 0 else Vector.zero()
        name     = team + "%02i" % (idx+1)
        yield klass(position, velocity, name, team=team, home=home, params=params)
Exemplo n.º 2
0
def initialize_particles(**kwargs):
    """
    Initialize N particles in a circular distribution around a center
    point, where N=number. Keyword arguments include a radius from the
    center, an identifier pattern and other keyword arguments that would
    instantiate a particle.
    """

    # Initialize variables needed to do initialization
    klass = kwargs.get('type', Particle)
    number = kwargs.get('number', world_parameters.get('team_size'))
    center = kwargs.get('center', (750, 750))
    radius = kwargs.get('radius', 100)
    team = kwargs.get('team', 'ally')
    maxvel = kwargs.get('maximum_velocity',
                        world_parameters.get('maximum_velocity'))
    home = kwargs.get('home', None)
    params = kwargs.get('params', world_parameters)

    # Generate coordinates and particles
    coords = zip(*circular_distribute(num=number, center=center, r=radius))
    for idx, coord in enumerate(coords):
        position = Vector.arrp(*coord)
        velocity = Vector.rand(maxvel) if maxvel > 0 else Vector.zero()
        name = team + "%02i" % (idx + 1)
        yield klass(position,
                    velocity,
                    name,
                    team=team,
                    home=home,
                    params=params)