Ejemplo n.º 1
0
def draw_agent():
    for i in xrange(0, len(agent_array)):
        agent = agent_array[i]
        make_agent_inbound()
        pointlist = utils.boid_pointlist(TRI_BASE, TRI_HEIGHT)
        surface = pyg.Surface((TRI_BASE, TRI_HEIGHT),
                              pyg.SRCALPHA).convert_alpha()
        pyg.draw.polygon(surface, AGENT_COLOR[i % 2], pointlist, 0)
        rotate = pyg.transform.rotate(surface, -agent_degree_rotation(agent))
        center = v_sub(agent.pos, (TRI_BASE / 2, TRI_HEIGHT / 2))
        screen.blit(rotate, center)
Ejemplo n.º 2
0
def draw_agent():
    agent_array_size = len(shared.agent_array)

    for i in range(agent_array_size):
        agent = shared.agent_array[i]
        make_agent_inbound()
        pointlist = boid_pointlist(TRI_BASE[i % 2], TRI_HEIGHT[i % 2])
        surface = pyg.Surface((TRI_BASE[i % 2], TRI_HEIGHT[i % 2]),
                              pyg.SRCALPHA).convert_alpha()
        pyg.draw.polygon(surface, AGENT_COLOR[i % 2], pointlist, 0)
        rotate = pyg.transform.rotate(surface, -agent_degree_rotation(agent))
        center = v_sub(agent.pos, (TRI_BASE[i % 2] / 2, TRI_HEIGHT[i % 2] / 2))
        screen.blit(rotate, center)
Ejemplo n.º 3
0
def compute_obstacle_dodge(myAgent):
    compute_vel = (0, 0)
    neighbors_cnt = 0

    for obs in shared.obstacle_array:
        if obs.distance_from(myAgent) < OBSTACLE_DOGDGE_RADIUS:
            temp_vel = v_sub(myAgent.pos, obs.pos)
            temp_vel = convert_to_unit_vector(temp_vel)
            compute_vel = v_add(compute_vel,
                                v_div(temp_vel, myAgent.distance_from(obs)))
            neighbors_cnt += 1

    if neighbors_cnt == 0:
        return compute_vel

    return v_div(compute_vel, neighbors_cnt)
Ejemplo n.º 4
0
def computeObscatleDodge(myAgent):
    compute_vel = (0, 0)
    neighbors_cnt = 0

    for obs in obstacle_array:
        if obs.distanceFrom(myAgent) < OBSTACLE_DOGDGE_RADIUS:
            temp_vel = v_sub(myAgent.pos, obs.pos)
            temp_vel = utils.getUnitVector(temp_vel)
            compute_vel = v_add(compute_vel,
                                v_div(temp_vel, myAgent.distanceFrom(obs)))
            neighbors_cnt += 1

    if neighbors_cnt == 0:
        return compute_vel

    return v_div(compute_vel, neighbors_cnt)
Ejemplo n.º 5
0
def compute_cohesion(myAgent, t):
    compute_vel = (0, 0)
    neighbors_cnt = 0

    for i in range(len(shared.agent_array)):
        agent = shared.agent_array[i]
        if agent != myAgent and myAgent.distance_from(
                agent) < COHESION_RADIUS and t == i % 2:
            compute_vel = v_sub(agent.pos, myAgent.pos)
            neighbors_cnt += 1

    if neighbors_cnt == 0:
        return compute_vel

    compute_vel = v_div(compute_vel, neighbors_cnt)

    return limit(compute_vel, 0.05)
Ejemplo n.º 6
0
def computeCohesion(myAgent, t):
    compute_vel = (0, 0)
    neighbors_cnt = 0

    for i in xrange(0, len(agent_array)):
        agent = agent_array[i]
        if agent != myAgent and myAgent.distanceFrom(
                agent) < COHESION_RADIUS and t == i % 2:
            compute_vel = v_sub(agent.pos, myAgent.pos)
            neighbors_cnt += 1

    if neighbors_cnt == 0:
        return compute_vel

    compute_vel = v_div(compute_vel, neighbors_cnt)

    return utils.limit(compute_vel, 0.05)
Ejemplo n.º 7
0
def compute_seperation(myAgent, t):
    compute_vel = (0, 0)
    neighbors_cnt = 0

    for i in range(len(shared.agent_array)):
        agent = shared.agent_array[i]
        if agent != myAgent and myAgent.distance_from(
                agent) < SEPERATION_RADIUS and t == i % 2:
            temp_vel = v_sub(myAgent.pos, agent.pos)
            temp_vel = convert_to_unit_vector(temp_vel)
            compute_vel = v_add(compute_vel,
                                v_div(temp_vel, myAgent.distance_from(agent)))
            neighbors_cnt += 1

    if neighbors_cnt == 0:
        return compute_vel

    return v_div(compute_vel, neighbors_cnt)
Ejemplo n.º 8
0
def computeSeperation(myAgent, t):
    compute_vel = (0, 0)
    neighbors_cnt = 0

    for i in xrange(0, len(agent_array)):
        agent = agent_array[i]
        if agent != myAgent and myAgent.distanceFrom(
                agent) < SEPERATION_RADIUS and t == i % 2:
            temp_vel = v_sub(myAgent.pos, agent.pos)
            temp_vel = utils.getUnitVector(temp_vel)
            compute_vel = v_add(compute_vel,
                                v_div(temp_vel, myAgent.distanceFrom(agent)))
            neighbors_cnt += 1

    if neighbors_cnt == 0:
        return compute_vel

    return v_div(compute_vel, neighbors_cnt)