This is a Rust implementation of a boid flocking simulation using the ggez graphics crate.

Overview

Boidflock

This is a Rust implementation of a boid flocking simulation using the ggez graphics crate.

The CLI for this program is built using the structopt crate.

Examples

cargo run --release

cargo run --release -- --zoom-scale 0.7 --visual-range 150 --avoid-range 30 --sight-angle 1. --coherence .7

cargo run --release -- --boid-count 12000 --zoom-scale .35 --visual-range 120 --sight-angle 1.5 --avoid-range 30 --alignment .95 --coherence .45

Configuration

There are lots of options to change the simulation from its default settings. Here's an example configuration for zooming out with many boids: cargo run --release -- --boid-count 15000 --zoom-scale .3 --visual-range 120 --sight-angle 1.5 --avoid-range 25.

Running cargo run --release -- --help yields a screen with the options shown below:

Boid Flocking Simulation
Andrew Lee
A flocking simulation built in Rust with ggez

USAGE:
    boidflock.exe [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
        --seed 
            Seed to determine initial positions and random rotations applied to boids. This make the simulation
            deterministic. If set to default 0, the seed will be randomly generated : u64 [default: 0]
        --boid-count                             Count of boids to simulate : [0, INF) [default: 2000]
        --coherence 
            Coefficient for boid aiming for center of local neighbor mass : [0, 1] [default: 0.035]

        --separation 
            Coefficient for boid avoidance within AVOID_RANGE : [0, 1] [default: 0.25]

        --alignment 
            Coefficient for boid alignment of velocity within SIGHT_RANGE : [0, 1] [default: 0.75]

        --avoid-range 
            Pixel distance for a boid to avoid others in line of sight : [0, INF) [default: 21.]

        --visual-range 
            Pixel sight distance for each boid : [0, INF) [default: 80.]

        --sight-angle 
            Sight pie-slice angle for each boid in radians : [0, 2*PI] [default: 2.3]

        --sight-samples 
            Samples to take get cells within sight angle range : [1, INF) [default: 3]

        --max-rand-rotate 
            Max random velocity rotation angle for boids : [0, 2*PI] [default: 0.3]

        --min-veloc 
            Minimum boid velocity in pixels : [0, MAX_VELOC] [default: 3.]

        --max-veloc 
            Maximum boid velocity in pixels : [MIN_VELOC, INF) [default: 5.]

        --cur-cell-neighbors 
            Maximum number of boid neighbors within current sight range cell to consider for calculations : [0,
            BOID_COUNT] [default: 30]
        --forward-cell-neighbors 
            Number of boids in sight range in sight range cell ahead to consider : [0, BOID_COUNT] [default: 10]

        --edge-turn-margin 
            Pixel distance from screen edge for boids to turn away from to stay on screen : [0, INF) [default: 25.]

        --edge-turn-factor 
            Coefficient to turn away from screen edges : [0, 1] [default: 0.2]

        --img-scale                               Scale for boid image : [0, INF) [default: 0.32]
        --zoom-scale 
            Scale to zoom. Above 1 zooms in, below 1 down to 0 zooms out : [0, INF) [default: 0.8]

Information

This has been awesome project for me for studying complex behavior generated out of simple rules.

I learned lots about practical applications of algorithmic complexity and optimization tradeoffs, and how to use a graphics library.

Enjoy the show!

You might also like...
Render farm simulator & plotting for optimisation written in Rust.
Render farm simulator & plotting for optimisation written in Rust.

Farm Usage Simulator Given a few basic charasteristics of a render farm and render jobs this app runs a few randomized farm usage scenarios and plots

A Rust API for Vega-Lite V4 to build chart with a rusty API.
A Rust API for Vega-Lite V4 to build chart with a rusty API.

Vega-Lite V4 for Rust A Rust API for Vega-Lite V4 to build chart with a rusty API. Similar to the Altair project in python, this crate build upon Vega

Externalize easily the plotting process from Rust to gnuplot.
Externalize easily the plotting process from Rust to gnuplot.

preexplorer Easy plotter and saver of simple data. Handy tool for development stage or small computational projects. Save data, have a quick view and

A pure Rust visualization library inspired by D3.js

charts A pure Rust visualization library inspired by D3.js. See gallery and examples for code and more charts. Install You can add this as a dependenc

A library to generate syntax diagrams for Rust macros.

Live demo (code) A browser add-on for Firefox, Chrome and Edge A library to generate syntax ("railroad") diagrams for Rust's macro_rules!(). Diagrams

Graphical Rust program that uses a fractal algorithm to draw a tree of sorts

rusty-vegetation Graphical Rust program that uses a fractal algorithm to draw a "tree" of sorts. To Build and Run On Linux: Install build-essentials o

A Rust program for visualizing how sections get packed into your Game Boy ROM

GB Packing Visualizer A Rust program for visualizing how sections get packed into your Game Boy ROM. rhythm_land.mp4 Each column represents a ROM bank

Lightweight graphs (sparklines) for use with Embedded Rust
Lightweight graphs (sparklines) for use with Embedded Rust

Sparklines for Rust's Embedded-graphics Sparklines are small, high resolution graphics embedded in a context of words, numbers or images". Edward Tuft

An alternative ggez implementation on top of miniquad.
An alternative ggez implementation on top of miniquad.

Good Web Game good-web-game is a wasm32-unknown-unknown implementation of a ggez subset on top of miniquad. Originally built to run Zemeroth on the we

2-player game made with Rust and
2-player game made with Rust and "ggez" engine, based on "Conway's Game of Life"

fight-for-your-life A 2-player game based on the "Conway's Game of Life", made with Rust and the game engine "ggez". Create shapes on the grid that wi

A graphics engine that I made in rust for my high school graphics course.

A graphics engine that I made in rust for my high school graphics course.

Standard Graphics is a command-line tool for printing 2D graphics from any language to any screen.
Standard Graphics is a command-line tool for printing 2D graphics from any language to any screen.

2D graphics in any programming language with just print statements!

A text renderer for Rust's embedded-graphics crate, based on U8g2
A text renderer for Rust's embedded-graphics crate, based on U8g2

u8g2-fonts This crate is a pure Rust reimplementation of the font subsystem of U8g2. It is intended for the embedded-graphics ecosystem. Licensing Whi

Prisma2D - Fast, API agnostic, software only 2D graphics crate in pure Rust.

Prisma2D: Ultra-fast CPU 2D graphics Prisma2D is a blazingly fast, efficient yet minimal crate for basic 2D graphics on the CPU. for Rust. With Prisma

Simulation of sand falling down in a cave built using nannou (Rust)
Simulation of sand falling down in a cave built using nannou (Rust)

nannou-sand-simulation Learning nannou, an open-source creative-coding toolkit for Rust, by implementing a visualization for a simulation of sand fall

Rust boids simulation using Reynolds model running with Bevy engine.

example.mp4 About Rust boids simulation using Reynolds model running with Bevy engine. The following parameters can be updated while the simulation is

Wheeled vehicle simulation using Bevy engine with Rapier's joints
Wheeled vehicle simulation using Bevy engine with Rapier's joints

⚠️ Legacy branch! ⚠️ 'master' branch is currently broken due to migration to newer rapier and bevy_rapier so unless you want to compare old and new ve

Prototype risk modeling simulation for Portfolio using Arbiter.

proto-sim Prototype simulation using Arbiter as the simulation & agent engine. Build & Run build.sh cargo run Arbiter config The arbiter.toml config

A networked (p2p), cross-platform physics simulation example using rollback netcode

bevy_gaff (work in progress) bevy_gaff is an attempt at making a networked (p2p), cross-platform physics simulation using rollback netcode. It synchro

Owner
Andrew Lee
Andrew Lee
Rust crate for creating beautiful interactive Chord Diagrams

Chord PRO Released Chord PRO is the full-featured chord visualization API, producing beautiful interactive visualizations, e.g. those featured on the

Dr. Shahin Rostami 25 Sep 10, 2022
A small charting/visualization tool and partial vega implementation for Rust

Gust A charting library for rust! Disclaimer This is still very much a work in progress! APIs are very unstable and subject to change. Contributions a

Samuel Resendez 128 Dec 24, 2022
🔵🟠 Portal Explorer — web visualization of mind-blowing portals using ray-tracing.

In Portal Explorer you can view how interesting portals are constructed, and visually explore their properties by moving and rotating them. This program doesn't work well on mobile, better opened from PC.

ilya sheprut 99 Dec 7, 2022
A simple 2D plotting library that outputs graphs to SVG that can be styled using CSS.

Poloto graphs can be stylized using css either directly in the SVG, or from inside of html with an embedded svg. The latter allows the user to dynamically match the svg to their website's theme.

Ken Reed 119 Dec 13, 2022
This is an implementation of an Iced backend for Plotters, for both native and wasm applications.

plotters-iced This is an implementation of an Iced backend for Plotters, for both native and wasm applications. This backend has been optimized as for

joylei 54 Dec 14, 2022
Data plotting library for Rust

plotlib plotlib is a generic data visualisation and plotting library for Rust. It is currently in the very early stages of development. It can current

Matt Williams 417 Dec 31, 2022
Plotly for Rust

Plotly.rs Plotly for Rust Getting Started | Recipes | API Docs | Changelog | | | A plotting library for Rust powered by Plotly.js. Usage Add this to y

Ioannis Giagkiozis 671 Jan 8, 2023
A rust drawing library for high quality data plotting for both WASM and native, statically and realtimely 🦀 📈🚀

Plotters - A Rust drawing library focus on data plotting for both WASM and native applications ?? ?? ?? Plotters is drawing library designed for rende

Hao Hou 2.7k Jan 4, 2023
A Rust library for drawing plots, powered by Gnuplot.

RustGnuplot A Gnuplot controller written in Rust. Documentation See here Examples A simple example: let mut fg = Figure::new(); fg.axes2d() .set_titl

null 353 Dec 26, 2022