use super::random_color;
use crate::gui::effect::PresetEffectOptions;
use crate::gui::effect::particle::Particle;
use rand::Rng;
pub fn spawn(_pos: f32, options: &PresetEffectOptions, width: f32, height: f32) -> Particle {
let cx = width / 2.0;
let circle_radius = width.min(height) / 2.0;
let x = rand::rng().random_range(0.0..width);
let y = -rand::rng().random_range(10.0..50.0);
let dx = x - cx;
let in_circle_x = dx.abs() < circle_radius * 0.8;
let final_x = if in_circle_x {
if dx < 0.0 {
cx - circle_radius - rand::rng().random_range(10.0..40.0)
} else {
cx + circle_radius + rand::rng().random_range(10.0..40.0)
}
} else {
x
};
let speed = rand::rng().random_range(100.0..200.0) * options.speed;
let wind = rand::rng().random_range(-20.0..20.0) * options.speed;
let color = if options.particle_colors.is_empty() {
let blue = rand::rng().random_range(0.5..0.8);
[0.4, 0.6, blue, 1.0]
} else {
random_color(options)
};
let (size_min, size_max) = options.particle_size;
let size = rand::rng().random_range(size_min * 0.3..size_max * 0.5).max(2.0);
let lifetime = rand::rng().random_range(1.0..2.0) / options.speed;
let mut particle = Particle::new(final_x, y)
.with_size(size)
.with_color(color)
.with_velocity(wind, speed)
.with_lifetime(lifetime);
particle.custom = rand::rng().random_range(8.0..20.0);
particle
}
pub fn update(
particle: &mut Particle,
dt: f32,
_time: f32,
_options: &PresetEffectOptions,
width: f32,
height: f32,
) {
let cx = width / 2.0;
let cy = height / 2.0;
let circle_radius = width.min(height) / 2.0;
particle.update(dt);
let px = particle.position.0 - cx;
let py = particle.position.1 - cy;
let dist = (px * px + py * py).sqrt();
if dist < circle_radius + 5.0 {
particle.lifetime = 0.0;
}
if particle.position.1 > height + 20.0 {
particle.lifetime = 0.0;
}
particle.alpha = 0.8;
}