confetty-tui 0.1.2

Confetti and fireworks in your terminal
Documentation
use crate::array;
use crate::simulation::{Particle, Point, Vector};
use rand::Rng;
use ratatui::style::Color;

const FRAMES_PER_SECOND: f64 = 30.0;
const NUM_PARTICLES: usize = 75;

const COLORS: &[&str] = &["#a864fd", "#29cdff", "#78ff44", "#ff718d", "#fdff6a"];
const CHARACTERS: &[&str] = &["", "", "", "", "", ""];

fn parse_color(hex: &str) -> Color {
    if hex.starts_with('#') && hex.len() == 7 {
        let r = u8::from_str_radix(&hex[1..3], 16).unwrap_or(255);
        let g = u8::from_str_radix(&hex[3..5], 16).unwrap_or(255);
        let b = u8::from_str_radix(&hex[5..7], 16).unwrap_or(255);
        Color::Rgb(r, g, b)
    } else {
        Color::White
    }
}

pub fn spawn(width: i32, _height: i32) -> Vec<Particle> {
    let mut rng = rand::thread_rng();
    let mut particles = Vec::new();
    
    for _ in 0..NUM_PARTICLES {
        let x = width as f64 / 2.0;
        let y = 0.0;
        
        let color_str = array::sample(COLORS);
        let color = parse_color(color_str);
        let character = array::sample(CHARACTERS);
        
        let position = Point {
            x: x + (width as f64 / 4.0) * (rng.gen::<f64>() - 0.5),
            y,
            z: 0.0,
        };
        
        let velocity = Vector {
            x: (rng.gen::<f64>() - 0.5) * 100.0,
            y: rng.gen::<f64>() * 50.0,
            z: 0.0,
        };
        
        let particle = Particle::new(
            character.to_string(),
            color,
            position,
            velocity,
            FRAMES_PER_SECOND,
        );
        
        particles.push(particle);
    }
    
    particles
}