diff --git a/src/fireworks.rs b/src/fireworks.rs index 1d93306..cce2867 100644 --- a/src/fireworks.rs +++ b/src/fireworks.rs @@ -1,6 +1,6 @@ //! `firework` module provides functions to define, create and update fireworks -use std::time::{Duration, SystemTime}; +use std::{collections::VecDeque, time::{Duration, SystemTime}}; use glam::Vec2; use rand::{seq::IteratorRandom, thread_rng}; @@ -373,8 +373,6 @@ pub enum FireworkInstallForm { DynamicInstall, } -fn init_trail(init_pos: Vec2, n: usize) -> Vec { - let mut res = Vec::new(); - (0..n).for_each(|_| res.push(init_pos)); - res +fn init_trail(init_pos: Vec2, n: usize) -> VecDeque { + VecDeque::from(vec![init_pos; n]) } diff --git a/src/particle.rs b/src/particle.rs index d40e2ec..3eef7b4 100644 --- a/src/particle.rs +++ b/src/particle.rs @@ -1,6 +1,6 @@ //! `particle` module provides functions to define, create and update particles -use std::time::Duration; +use std::{collections::VecDeque, time::Duration}; use glam::Vec2; @@ -23,7 +23,7 @@ pub struct Particle { pub pos: Vec2, pub vel: Vec2, /// Records a `trail_length` of previous positions of the `Particle` - pub trail: Vec, + pub trail: VecDeque, pub life_state: LifeState, /// `Duration` since initialization of this `Particle` pub time_elapsed: Duration, @@ -35,7 +35,7 @@ impl Default for Particle { Self { pos: Vec2::ZERO, vel: Vec2::ZERO, - trail: Vec::new(), + trail: VecDeque::new(), life_state: LifeState::Alive, time_elapsed: Duration::ZERO, config: ParticleConfig::default(), @@ -52,8 +52,7 @@ impl Particle { life_time: Duration, color: (u8, u8, u8), ) -> Self { - let mut trail = Vec::with_capacity(trail_length); - (0..trail_length).for_each(|_| trail.push(pos)); + let trail = VecDeque::from(vec![pos; trail_length]); let life_state = LifeState::Alive; Self { pos, @@ -97,8 +96,8 @@ impl Particle { self.pos += TIME_STEP * self.vel; t += TIME_STEP; } - self.trail.remove(0); - self.trail.push(self.pos); + self.trail.pop_front(); + self.trail.push_back(self.pos); } } diff --git a/src/term.rs b/src/term.rs index b665db1..9b764af 100644 --- a/src/term.rs +++ b/src/term.rs @@ -284,13 +284,11 @@ fn get_char_alive(density: f32, cjk: bool) -> char { } else { "oahkbdpqwmZO0QLCJUYXzcvunxrjft*" } - } else { - if cjk { + } else if cjk { "𰻞" // "東京福岡横浜縄" } else { "$@B%8&WM#" - } }; palette .chars() @@ -319,13 +317,11 @@ fn get_char_declining(density: f32, cjk: bool) -> char { } else { "/\\| ()1{}[ ]?" } - } else { - if cjk { + } else if cjk { "繁荣昌盛国泰民安龍龖龠龜耋" // "時間言葉目覚" } else { "xrjft*" - } }; palette .chars() @@ -340,13 +336,11 @@ fn get_char_dying(density: f32, cjk: bool) -> char { } else { ". ,`. ^,' . " } - } else { - if cjk { + } else if cjk { "|¥人 上十入乙小 下" // "イントマトナイフ" } else { " /\\| ( ) 1{} [ ]?i !l I;: ,\"^ " - } }; palette .chars()