Skip to content

rrutt/PascalBoids

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Boids Flocking Simulation in Pascal

Version 1.0.1 20240205 (Version Release Notes)

Boids Flocking Simulation is an open source simulation of a flock of birds.

The original algorithm was developed by Craig Reynolds in 1986, as described in the Boids Wikipedia article.

This Free Pascal

About the Software

The software is a self-contained executable program, written in Free Pascal, that runs on Microsoft Windows or Ubuntu Linux (and presumably other Linux distributions). (No separate run-time environment is required to run the program.)

The Lazarus Integrated Development Environment was used to develop the program. (Both Free Pascal and the Lazarus IDE are free open-source software products.)

The simulation rules logic in this implementation were adapted from Scott W. Harden's C# implementation.

Downloading and Running the Program

Microsoft Windows

You can run the Boids Flocking Simulation program on Microsoft Windows as follows:

  • Download the PascalBoids.exe binary executable file from the bin sub-folder from this GitHub.com page.

  • To uninstall the program, simply delete the PascalBoids.exe file.

Ubuntu Linux

You can run the Boids Flocking Simulation program on Ubuntu Linux (and presumably other Linux distributions) as follows:

  • Download the PascalBoids binary executable file (with no file extension) from the bin sub-folder from this GitHub.com page.

  • Ensure the PascalBoids file has the executable permission. From a Files window, right-click the file, select Properties, and use the Permissions tab to enable the Execute permission. To do this in a Terminal window, use the following command:

    chmod +x PascalBoids

  • To uninstall the program, simply delete the PascalBoids binary executable file.

Running the Program

Double-click the downloaded copy of PascalBoids.exe (on Windows) or PascalBoids (on Linux) to start the simulation.

When the program starts it displays the Boids Flocking Simulation Main Form.

Here is an image of the Main Form paused during a running simulation.

PascalBoids Main Form

The Main Form contains these elements:

  • The # Boids spin-edit control determines the number of Boids generated by the Randomize button. Use the up/down arrows on the control to set the desired number. Alternately, directly enter the desired number into the control.
  • The Randomize button generates a random distribution of Boids.
  • The Start button is activated once the Randomize button has been clicked. Clicking the Start button starts the simulation.
  • The Pause button is activated when the simulation is running and temporarily stops the simulation. The Randomize button becomes active to allow initiation of a new random distribution of asteroids. Clicking the Start button resumes the simulation.
  • The Step button advances the simulation for a single time step. It is active when the simulation is paused, or has not yet been started.
  • The Rules button opens the Boids Rules dialog form. (This form also appears when the program is run.) The rules form disappears when the Start button is clicked. Click the Rules button to re-open the rules form.
  • Displayed next to the Rules button are the current number of Boids and predator Hawks.
  • The majority of the Main Form contains the graphic display area for the simulation space. Boids appear white on a sky blue background. Left-click on the display to add a new Boid at the mouse position. Right-click to add a new predator Hawk, which appears in maroon.

PascalBoids Rules Form

The Rules Form contains these elements:

  • Pairs of Distance and Power values. Each pair works together to control a given rule. The Power value determines the effective weight of a rule in relation to the other rules. Set a Power value to zero to deactivate that given rule.

    • The Flocking rule controls the tendency for Boids or Hawks to approach nearby Boids.
    • The Aligning rule controls the tendency for Boids or Hawks to match the direction and speed of nearby Boids.
    • The Avoid Boid rule helps a Boid avoid getting too close to other Boids.
    • The Avoid Hawk rule helps a Boid avoid getting a predator Hawk. It also helps each Hawk avoid another Hawk.
  • Minimum Speed and Maximum Speed constrain the speed of each Boid or Hawk.

  • Bounce Distance determines how close a Boid or Hawk gets to a boundary edge before changing direction.

  • Check the Wrap Around Edges check-box to allow a Boid or Hawk to continue past a boundary edge and reappear at the opposite edge. The Bounce Distance value is ignored in this case.

  • The Set Defaults button restores the original default values into the Rules Form. (The restored values do not become active until the Apply button is clicked.)

  • The Apply button activates the current Rules Form values.

  • The Hide button dismisses the Rules Form.

Resizing the Main Form

The initial size of the Main Form is designed to fit within an 800 by 600 monitor window.

To enlarge the form, drag its boundary or simply click the maximize icon (small square in the upper right of the title bar).

Then click the Randomize button to enlarge the graphic simulation area to match the enlarged form.

Source code compilation notes

Download the Lazarus IDE, including Free Pascal, from here:

After installing the Lazarus IDE, clone this GitHub repository to your local disk. Then double-click on the src\PascalBoids.lpr project file to open it in Lazarus.

Note: Using the debugger in the Lazarus IDE on Windows 10 might require the following configuration adjustment:

When Lazarus includes debugging information the executable file is relatively large. When ready to create a release executable, the file size can be significantly reduced by selecting the menu item Project | Project Options ... and navigating to the Compile Options | Debugging tab in the resulting dialog window. Clear the check-mark from the Generate info for the debugger option and then click the OK button. Then rebuild the executable using the Run | Build menu item (or using the shortcut key-stroke Shift-F9).

Release Notes

Version 1.0.1

Added the version compiled for Linux.

Version 1.0.0

This is the initial version of the software. It is compiled for Microsoft Windows.

The version compiled for Linux is not yet available.

About

Boids Flocking Simulation in Pascal

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages