https://github.com/sheraff/boids
Boids behavior in Rust w/ Web Workers & OffscreenCanvas
https://github.com/sheraff/boids
offscreencanvas rust wasm webassembly webworker
Last synced: 3 months ago
JSON representation
Boids behavior in Rust w/ Web Workers & OffscreenCanvas
- Host: GitHub
- URL: https://github.com/sheraff/boids
- Owner: Sheraff
- Created: 2020-08-01T22:47:37.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-20T22:43:54.000Z (over 3 years ago)
- Last Synced: 2025-11-20T03:28:35.472Z (7 months ago)
- Topics: offscreencanvas, rust, wasm, webassembly, webworker
- Language: Rust
- Homepage: https://sheraff.github.io/boids/
- Size: 306 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Implementation of [Boids](https://en.wikipedia.org/wiki/Boids)

Boids is an example of emergent behavior; that is, the complexity of Boids arises from the interaction of individual agents (the boids, in this case) adhering to a set of simple rules. The rules applied in the simplest Boids world are as follows:
- separation: steer to avoid crowding local flockmates
- alignment: steer towards the average heading of local flockmates
- cohesion: steer to move towards the average position (center of mass) of local flockmates
## JS version
Uses basic web worker for computation, w/ [`OffscreenCanvas`](https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas) to draw on the canvas off of the main thread.
Requires no transpilation and can be served directly. Entry point (to be set in index.html) is /js/script.js
## Rust version
Uses [Web Assembly](https://developer.mozilla.org/en-US/docs/WebAssembly) for computation, written in Rust. Also uses a [`Broadcast Channel`](https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API) for basic interop between JS worker and WASM thread. And imports the [web-sys](https://rustwasm.github.io/wasm-bindgen/api/web_sys/) crate to call canvas methods efficiently.
Needs to be compiled
```
wasm-pack build --target web
```
Entry point (to be set in index.html) is /js/wasm.js