diff --git a/examples/ribbon.rs b/examples/ribbon.rs index fbc7c734..a6aa374c 100644 --- a/examples/ribbon.rs +++ b/examples/ribbon.rs @@ -1,4 +1,5 @@ -//! Draws a trail and connects the trails using a ribbon. +//! Uses with_ribbons to draw a "tracer" or a "trail" following an Entity. +//! The movement of the head particle is achieved by linking the particle position to a CPU position using a [Property] in [move_head]. use bevy::math::vec4; use bevy::prelude::*; @@ -16,15 +17,15 @@ use utils::*; const K: f32 = 0.64; const L: f32 = 0.384; -const TIME_SCALE: f32 = 10.0; +const TIME_SCALE: f32 = 6.5; const SHAPE_SCALE: f32 = 25.0; -const LIFETIME: f32 = 2.5; +const LIFETIME: f32 = 1.5; const TRAIL_SPAWN_RATE: f32 = 256.0; fn main() -> Result<(), Box> { let app_exit = utils::make_test_app("ribbon") .add_systems(Startup, setup) - .add_systems(Update, move_particle_effect) + .add_systems(Update, move_head) .run(); app_exit.into_result() } @@ -71,18 +72,12 @@ fn setup(mut commands: Commands, mut effects: ResMut>) { value: writer.lit(0.5).expr(), }; - let time = writer.time().mul(writer.lit(TIME_SCALE)); + let pos = writer.add_property("head_pos", Vec3::ZERO.into()); + let pos = writer.prop(pos); let move_modifier = SetAttributeModifier { attribute: Attribute::POSITION, - value: (WriterExpr::vec3( - writer.lit(1.0 - K).mul(time.clone().cos()) - + writer.lit(L * K) * (writer.lit((1.0 - K) / K) * time.clone()).cos(), - writer.lit(1.0 - K).mul(time.clone().sin()) - - writer.lit(L * K) * (writer.lit((1.0 - K) / K) * time.clone()).sin(), - writer.lit(0.0), - ) * writer.lit(SHAPE_SCALE)) - .expr(), + value: pos.expr(), }; let render_color = ColorOverLifetimeModifier { @@ -98,6 +93,10 @@ fn setup(mut commands: Commands, mut effects: ResMut>) { .init_groups(init_lifetime_attr, ParticleGroupSet::single(0)) .init_groups(init_size_attr, ParticleGroupSet::single(0)) .update_groups(move_modifier, ParticleGroupSet::single(0)) + .render(SizeOverLifetimeModifier { + gradient: Gradient::linear(Vec2::ONE, Vec2::ZERO), + ..default() + }) .render_groups(render_color, ParticleGroupSet::single(1)); let effect = effects.add(effect); @@ -111,9 +110,23 @@ fn setup(mut commands: Commands, mut effects: ResMut>) { .insert(Name::new("ribbon")); } -fn move_particle_effect(mut query: Query<&mut Transform, With>, timer: Res