pub struct ParticleConfig {
    pub init_pos: Vec2,
    pub init_vel: Vec2,
    pub trail_length: usize,
    pub life_time: Duration,
    pub color: (u8, u8, u8),
}
Expand description

Struct that defines the configuration of Particle

Fields§

§init_pos: Vec2§init_vel: Vec2§trail_length: usize§life_time: Duration

Duration from Particle’s initialization to its Dead

§color: (u8, u8, u8)

Color in RGB (from 0 to 255)

Implementations§

source§

impl ParticleConfig

source

pub fn new( init_pos: Vec2, init_vel: Vec2, trail_length: usize, life_time: Duration, color: (u8, u8, u8) ) -> Self

Create a new ParticleConfig

Examples found in repository?
examples/fountain.rs (lines 83-89)
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
fn gen_fountain_firework(center: Vec2) -> Firework {
    let colors = vec![(226, 196, 136), (255, 245, 253), (208, 58, 99)];
    let mut particles = Vec::new();
    for v in gen_points_fan(
        300.,
        45,
        5 as f32 / 12 as f32 * PI,
        7 as f32 / 12 as f32 * PI,
    )
    .iter()
    {
        particles.push(ParticleConfig::new(
            center,
            *v,
            thread_rng().gen_range(28..38),
            Duration::from_secs_f32(thread_rng().gen_range(2.5..3.8)),
            *colors.iter().choose(&mut thread_rng()).unwrap(),
        ));
    }
    let mut config = FireworkConfig::default()
        .with_ar_scale(0.15)
        .with_gravity_scale(0.5)
        .with_gradient_scale(gradient);
    config.set_enable_gradient(true);
    Firework {
        init_time: SystemTime::now(),
        spawn_after: Duration::ZERO,
        center,
        particles,
        config,
        form: ExplosionForm::Sustained {
            lasts: Duration::from_secs(5),
            time_interval: Duration::from_secs_f32(0.08),
            timer: Duration::ZERO,
        },
        ..Default::default()
    }
}
More examples
Hide additional examples
examples/vortex.rs (lines 81-87)
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
fn gen_vortex_firework(center: Vec2) -> Firework {
    let colors = vec![
        (6, 55, 63),
        (24, 90, 96),
        (47, 123, 119),
        (92, 174, 166),
        (200, 255, 255),
    ];
    let mut particles = Vec::new();
    for p in gen_points_circle(30, 45).iter() {
        particles.push(ParticleConfig::new(
            center + *p,
            Vec2::new((*p).y, -(*p).x).normalize() * 15.,
            thread_rng().gen_range(28..40),
            Duration::from_secs_f32(thread_rng().gen_range(4.5..7.0)),
            *colors.iter().choose(&mut thread_rng()).unwrap(),
        ));
    }
    let mut config = FireworkConfig::default()
        .with_ar_scale(0.05)
        .with_gravity_scale(0.)
        .with_gradient_scale(gradient)
        .with_additional_force(move |particle| {
            (center - particle.pos).normalize() * (1. / center.distance(particle.pos)) * 150.
        });
    config.set_enable_gradient(true);
    Firework {
        init_time: SystemTime::now(),
        spawn_after: Duration::ZERO,
        center,
        particles,
        config,
        form: ExplosionForm::Sustained {
            lasts: Duration::from_secs(10),
            time_interval: Duration::from_secs_f32(0.01),
            timer: Duration::ZERO,
        },
        ..Default::default()
    }
}
examples/heart.rs (lines 84-90)
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
fn gen_heart_firework(center: Vec2) -> Firework {
    let colors = vec![
        (233, 232, 237),
        (254, 142, 130),
        (200, 27, 72),
        (86, 18, 31),
    ];
    let mut particles = Vec::new();
    let trail_length = thread_rng().gen_range(100..105);
    let life_time = Duration::from_secs_f32(thread_rng().gen_range(3.0..3.2));
    let init_pos = center - Vec2::NEG_Y * 15.;
    for v in gen_points_fan(300., 45, 0.2 * PI, 0.3 * PI).iter() {
        particles.push(ParticleConfig::new(
            init_pos,
            *v,
            trail_length,
            life_time,
            *colors.iter().choose(&mut thread_rng()).unwrap(),
        ));
    }
    for v in gen_points_fan(300., 45, 0.7 * PI, 0.8 * PI).iter() {
        particles.push(ParticleConfig::new(
            init_pos,
            *v,
            trail_length,
            life_time,
            *colors.iter().choose(&mut thread_rng()).unwrap(),
        ));
    }
    let mut config = FireworkConfig::default()
        .with_ar_scale(0.1)
        .with_gravity_scale(0.1)
        .with_gradient_scale(gradient)
        .with_additional_force(move |particle| (center - particle.pos) * 2.);
    config.set_enable_gradient(true);
    Firework {
        init_time: SystemTime::now(),
        spawn_after: Duration::ZERO,
        center,
        particles,
        config,
        form: ExplosionForm::Instant { used: false },
        ..Default::default()
    }
}

Trait Implementations§

source§

impl Clone for ParticleConfig

source§

fn clone(&self) -> ParticleConfig

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ParticleConfig

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for ParticleConfig

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl PartialEq for ParticleConfig

source§

fn eq(&self, other: &ParticleConfig) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for ParticleConfig

source§

impl StructuralPartialEq for ParticleConfig

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V