Monster commit: native version
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use crate::theme::sparkle;
|
||||
use rand::Rng;
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::layout::Rect;
|
||||
@@ -5,13 +6,6 @@ use ratatui::style::{Color, Style};
|
||||
use ratatui::widgets::Widget;
|
||||
|
||||
const CHARS: &[char] = &['·', '✦', '✧', '°', '•', '+', '⋆', '*'];
|
||||
const COLORS: &[(u8, u8, u8)] = &[
|
||||
(200, 220, 255),
|
||||
(255, 200, 150),
|
||||
(150, 255, 200),
|
||||
(255, 150, 200),
|
||||
(200, 150, 255),
|
||||
];
|
||||
|
||||
struct Sparkle {
|
||||
x: u16,
|
||||
@@ -47,17 +41,17 @@ impl Sparkles {
|
||||
|
||||
impl Widget for &Sparkles {
|
||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||
for sparkle in &self.sparkles {
|
||||
let color = COLORS[sparkle.char_idx % COLORS.len()];
|
||||
let intensity = (sparkle.life as f32 / 30.0).min(1.0);
|
||||
for sp in &self.sparkles {
|
||||
let color = sparkle::COLORS[sp.char_idx % sparkle::COLORS.len()];
|
||||
let intensity = (sp.life as f32 / 30.0).min(1.0);
|
||||
let r = (color.0 as f32 * intensity) as u8;
|
||||
let g = (color.1 as f32 * intensity) as u8;
|
||||
let b = (color.2 as f32 * intensity) as u8;
|
||||
|
||||
if sparkle.x < area.width && sparkle.y < area.height {
|
||||
let x = area.x + sparkle.x;
|
||||
let y = area.y + sparkle.y;
|
||||
let ch = CHARS[sparkle.char_idx];
|
||||
if sp.x < area.width && sp.y < area.height {
|
||||
let x = area.x + sp.x;
|
||||
let y = area.y + sp.y;
|
||||
let ch = CHARS[sp.char_idx];
|
||||
buf[(x, y)].set_char(ch).set_style(Style::new().fg(Color::Rgb(r, g, b)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user