Sheraff / boids

Boids behavior in Rust w/ Web Workers & OffscreenCanvas

Home Page:https://sheraff.github.io/boids/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implementation of Boids

Screen Shot 2022-06-18 at 19 40 31

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 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 for computation, written in Rust. Also uses a Broadcast Channel for basic interop between JS worker and WASM thread. And imports the 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

About

Boids behavior in Rust w/ Web Workers & OffscreenCanvas

https://sheraff.github.io/boids/


Languages

Language:Rust 52.4%Language:JavaScript 44.3%Language:HTML 1.7%Language:CSS 0.9%Language:SCSS 0.8%