boids4R provides deterministic Reynolds-style boids and swarm simulations for
R. It owns simulation semantics only: agents, rules, obstacles, attractors,
predators, species, and frame export. Rendering packages consume the exported
frames through optional adapters.
The package is intended to pair cleanly with browser-native renderers such as
ggWebGL, without putting camera, shader, widget, or scene fields into the core
simulation objects.
library(boids4R)
sim <- boids_scenario("murmuration_3d", n = 400, steps = 240, seed = 1)
frames <- as.data.frame(sim)
head(frames)
if (requireNamespace("ggWebGL", quietly = TRUE) &&
utils::packageVersion("ggWebGL") >= "0.4.0") {
spec <- as_ggwebgl_spec(sim, trail_length = 30)
ggWebGL::ggWebGL(spec, height = 520)
}
The WebGL adapter emphasizes current boids, keeps recent history as faint trails, colours species and explicit prey/predator roles distinctly, and draws velocity arrows in species colours by default.
The model follows the standard boids lineage introduced by Craig Reynolds: separation, alignment, and cohesion rules produce flocking behavior through local agent interactions.