src/boids_simpkg/rules

Search:
Group by:

This module defines the rules for the behaviour of the single boids.

Cohesion

Cohesion makes the boids wanting to move together, towards the center of mass of the boids in its field of view. Through cohesion, boids want to get closer together. This - with the help of the other rules - results in the typical flocking behaviour similar to birds and fish.

Separation

Separation is the opposite force to cohesion. It makes sure that the boids don't just fly into each other. This is accomplished by a contrary force which increases as two boids come closer to each other. It only activates if the boids enter each other's protected zone. The protected zone is a subzone of the field of view, in which the boids don't want other boids to be in.

Alignment

Alignment is the last essential force. It makes the boids want to move in the same direction as the other boids. This also activates for all the boids in the field of view.

Avoid edges

Since the simulated boids shouldn't fly off the edges of the screen, they have to avoid edges somehow. I first implemented this by a simple bouncing-off the edges, but since this happends very often, it resulted in very unnatural behaviour of the boids. Now a separate rule in the "AI" of the boids tries to steer away from the screen edges as soon as they enter the field of view.

Procs

proc apply_rules(boids: var seq[Triangle]; ui: Ui; dt: float) {....raises: [],
    tags: [], forbids: [].}
This function applies all rules to each boid in boids. It has been combined into a single function in order to increase performance by only looping over the boids once.