示例#1
0
 def addBoid(self, x, y):
     self.n += 1
     vx, vy = uniform(-1, 1), uniform(-1, 1)
     #s = self.dist(0, 0, vx, vy)
     #if s>MAX_SPEED or s<MIN_SPEED:
     #    vx, vy = self.unit(vx, vy)
     #    vx *= MAX_SPEED
     #    vy *= MAX_SPEED
     self.boids.append(boid.Boid(x, y, vx, vy))
示例#2
0
    def __init__(self, size):
        self.bocal = 800
        self.size = size
        self.boids = [boid.Boid(self.bocal) for i in range(0, self.size)]

        self.root = tkinter.Tk()
        self.canvas = tkinter.Canvas(self.root,
                                     width=self.bocal,
                                     height=self.bocal,
                                     background='white')
        self.canvas.pack()
示例#3
0
    def __init__(self):
        self.gfx = gfx.Gfx()
        object_collection.ObjectCollection.all_boids = []
        for i in range(100):
            object_collection.ObjectCollection.all_boids.append(boid.Boid())

        object_collection.ObjectCollection.all_predators = []
        for i in range(0):
            object_collection.ObjectCollection.all_predators.append(
                predator.Predator())

        self.run()
示例#4
0
    def initVars(self, startPoint, endPoint, flockSize, **kwargs):
        """
        Parses the file to get the obstacle list. Creates a PRM generator to
        create a global map of the environment. Gets the list of intermediate
        goals.  Also, creates the list of boids used in the simulation
        @param startPoint The starting point for the boids
        @param endPoint The ending point for the boids
        @param flockSize The size of the flock (number of boids)
        @param filename The name of the file that contains the environment map
        """
        ## List of obstacles
        # parse static obstalces
        self.obstacleList = mp.mparse(kwargs.get("map_file", "maps/m1.map"))

        # parse dynamic obstalces
        dynamic_obstacles_fp = kwargs.get("dynamic_obstacles", None)
        self.parseDynamicObstacles(dynamic_obstacles_fp)

        # auto geneate dynamic obstacles
        self.auto_gen_obst = kwargs.get("auto_gen_obst", False)
        self.auto_gen_number = kwargs.get("auto_gen_number", 0)
        if self.auto_gen_obst:
            self.autoGenerateDynamicObstacles(startPoint, endPoint)

        ## Starting point
        self.startPoint = startPoint

        ## Ending point
        self.endPoint = endPoint

        ## Object containing variables and mehtods for the global planner
        self.prmGen = PRMGenerator(startPoint, endPoint, self.obstacleList,
                                   Configuration.xSize, Configuration.ySize,
                                   Configuration.numSamplePoints,
                                   Configuration.screen)

        ## List of intermediate goals derived by the global planner
        self.goalList = self.prmGen.generate(Configuration.goalRadius)

        ## List of boids in the flock
        self.boidList = [
            boid.Boid(startPoint, endPoint, Configuration.boidSpeed,
                      Configuration.xSize, Configuration.ySize,
                      Configuration.numNeighbours, boid.guassianFunc,
                      self.obstacleList, self.goalList, self.prmGen,
                      Configuration.screen, Configuration.colorList[i],
                      Configuration.boid_radius,
                      self.determinePositionInConfig(i, flockSize, startPoint))
            for i in range(flockSize)
        ]
示例#5
0
 def make_babies(self, location):
     for _ in range(
             random.randint(Settings.minimum_number_of_babies,
                            Settings.maximum_number_of_babies)):
         baby_location = pygame.Vector2(
             location.y + random.randint(-Settings.maximum_baby_distance,
                                         Settings.maximum_baby_distance),
             location.x + random.randint(-Settings.maximum_baby_distance,
                                         Settings.maximum_baby_distance),
         )
         self.boids.append(
             boid.Boid(self,
                       location=baby_location,
                       velocity=pygame.Vector2(0, -3),
                       age=0))
示例#6
0
def main():
    world_turtle = turtle.Turtle()
    screen = world_turtle.getscreen()
    screen.setworldcoordinates(0, 0, WIDTH - 1, HEIGHT - 1)
    screen.tracer(NUM_BIRDS)
    world_turtle.hideturtle()

    sky = w.World(WIDTH, HEIGHT)  # create the world
    for index in range(NUM_BIRDS):  # create the boids in myworld=sky
        bird = b.Boid(sky)

    for step in range(ITERATIONS):  # run the simulation
        sky.step_all()

    screen.update()
    screen.exitonclick()
示例#7
0
    def startsim(self):
        '''
        makes objects for the given amount
        as stated in the PARAMETERS file
        '''
        for i in range(BOIDNUMBERS):
            bird = boid.Boid(BOIDSIZE, BOIDMAXSPEED)
            boid.Boid.boidlist.append(bird)

        for i in range(HOIKNUMBERS):
            eagle = boid.Hoik(HOIKSIZE, HOIKMAXSPEED)
            boid.Hoik.hoiklist.append(eagle)

        for i in range(OBJECTNUMBERS):
            object = boid.Hindrance()
            boid.Hindrance.hindrancelist.append(object)
示例#8
0
X_GOAL = 1100
Y_GOAL = 100

#weights for further calibration
WEIGHT_OPTIMAL = 0.8  #temporary, most likely 1 minus the other two weights
WEIGHT_OBSTACLE = 0.1  #this will use the inverse
WEIGHT_BOID = 0.1
#the boids will only take the effort to avoid the boid nearest to it

#coords and dimensions for rectangular obstacle
OB_X = 450
OB_Y = 450
OB_WIDTH = 300
OB_HEIGHT = 300

burd = boid.Boid(X_START, Y_START, X_GOAL, Y_GOAL)
navigateBoid(burd)

#define window height and width
gameWindow = pyglet.window.Window(width=WIDTH, height=HEIGHT)

#this can easily not be a global dude fix it
boidStillFlying = True

#pyglet.resource.path = ['/Users/kai/Documents/SNNProject']
#pyglet.resource.reindex()

#boid_image = ("boid.png")

boidSprite = pyglet.sprite.Sprite(
    img=pyglet.image.load('/Users/kai/Documents/SNNProject/src/boid.png'),
示例#9
0
for i in range(SCREEN_WIDTH // partitionSizeX):
    partitions.append([])
    for j in range(SCREEN_HEIGHT // partitionSizeY):
        partitions[i].append([])

while run:

    delta = clock.tick(30)

    boidSpawnTimer -= delta / 1000

    if len(boids) < max_boids and boidSpawnTimer <= 0:
        boids.append(
            boid.Boid(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2,
                      random.random() * 2 - 1,
                      random.random() * 2 - 1, SCREEN_WIDTH, SCREEN_HEIGHT,
                      (random.randrange(1, 255), random.randrange(
                          1, 255), random.randrange(1, 255))))
        boidSpawnTimer = boidSpawnTimerResetValue
        print(len(boids))

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

    draw()

    update()

    #print(1000 / delta)
示例#10
0
#Groups to hold all sprites
boidGroup = pygame.sprite.Group()

"""
============================= Game Loop ================================
"""
while not quit:
    clock.tick(30)

    # All events (mouse and keyboard)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            quit = True

        if event.type == pygame.MOUSEBUTTONDOWN:
            boidGroup.add(boid.Boid("boid.png", pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1]))

    #Clear the screen
    screen.fill((255,255,255))

    #update sprites
    for eachBoid in range(len(boidGroup.sprites())):
        list = boidGroup.sprites()
        list.pop(eachBoid)
        boidGroup.sprites()[eachBoid].update(screen, list)

    #Draw sprites
    boidGroup.draw(screen)

    #Display the next screen
    pygame.display.flip()