use rand::Rng;
use rdpe::prelude::*;
#[derive(Particle, Clone)]
struct Agent {
position: Vec3,
velocity: Vec3,
#[color]
color: Vec3,
}
fn main() {
let mut rng = rand::thread_rng();
let positions: Vec<Vec3> = (0..5_000)
.map(|_| {
Vec3::new(
rng.gen_range(-0.5..0.5),
rng.gen_range(-0.5..0.5),
rng.gen_range(-0.5..0.5),
)
})
.collect();
Simulation::<Agent>::new()
.with_particle_count(5_000)
.with_bounds(1.0)
.with_particle_size(0.008)
.with_spawner(move |ctx| Agent {
position: positions[ctx.index as usize],
velocity: Vec3::ZERO,
color: Vec3::new(1.0, 1.0, 1.0), })
.with_field(
"density",
FieldConfig::new(64)
.with_extent(1.0)
.with_decay(0.95) .with_blur(0.2) .with_blur_iterations(2),
)
.with_volume_render(
VolumeConfig::new()
.with_field(0) .with_steps(64) .with_density_scale(8.0) .with_palette(Palette::Inferno)
.with_threshold(0.005) .with_additive(true), )
.with_rule(Rule::Vortex {
center: Vec3::ZERO,
axis: Vec3::Y,
strength: 0.5,
})
.with_rule(Rule::Wander { strength: 0.3, frequency: 100.0 })
.with_rule(Rule::AttractTo {
point: Vec3::ZERO,
strength: 0.2,
})
.with_rule(Rule::SpeedLimit { min: 0.0, max: 1.0 })
.with_rule(Rule::Custom(
r#"
// Deposit particle presence into the field
field_write(0u, p.position, 0.3);
"#
.into(),
))
.with_rule(Rule::BounceWalls { restitution: 1.0 })
.with_visuals(|v| {
v.background(Vec3::new(0.02, 0.02, 0.05)); })
.run().expect("Simulation failed");
}