use rdpe::prelude::*;
#[derive(rdpe::Particle, Clone)]
struct CubeParticle {
position: Vec3,
velocity: Vec3,
#[color]
color: Vec3,
}
fn main() {
Simulation::<CubeParticle>::new()
.with_particle_count(200)
.with_bounds(1.5)
.with_particle_size(0.01) .with_spawner(|ctx| {
let pos = ctx.grid_position(10, 10, 2);
CubeParticle {
position: pos,
velocity: ctx.random_direction() * 0.1,
color: ctx.hsv((pos.x + 1.0) / 2.0, 0.8, 1.0),
}
})
.with_visuals(|v| {
v.wireframe(WireframeMesh::cube(), 0.001);
v.blend_mode(BlendMode::Additive); })
.with_rule(Rule::AttractTo {
point: Vec3::ZERO,
strength: 0.2,
})
.with_rule(Rule::Custom(
r#"
let r = length(p.position.xz);
let swirl = 0.2 / (r + 0.2);
p.velocity += vec3<f32>(-p.position.z, 0.0, p.position.x) * swirl * uniforms.delta_time;
"#
.into(),
))
.with_rule(Rule::Drag(0.5))
.with_rule(Rule::SpeedLimit { min: 0.0, max: 0.8 })
.with_rule(Rule::BounceWalls { restitution: 1.0 })
.run().expect("Simulation failed");
}