minor cleanup

This commit is contained in:
Joe Ardent 2022-10-29 15:53:49 -07:00
parent 4957f3f30b
commit ec3f36779c
2 changed files with 8 additions and 6 deletions

View file

@ -9,15 +9,16 @@ use eframe::{
use super::{state::*, Timer}; use super::{state::*, Timer};
use crate::{MAX_REPAINT, MIN_REPAINT}; use crate::{MAX_REPAINT, MIN_REPAINT};
const STARTING_COLOR: &[f32; 3] = &[10.0, 4.0, 4.0]; const STARTING_COLOR: &[f32; 3] = &[10.0, 4.0, 14.0];
const UNIT_COLOR: &[f32; 3] = &[0.986, 0.154, 0.055]; const UNIT_COLOR: &[f32; 3] = &[0.986, 0.154, 0.055]; // [160, 125, 9].normalize()
impl eframe::App for Timer { impl eframe::App for Timer {
fn update(&mut self, ctx: &egui::Context, frame: &mut EFrame) { fn update(&mut self, ctx: &egui::Context, frame: &mut EFrame) {
ctx.request_repaint_after(MAX_REPAINT); ctx.request_repaint_after(MAX_REPAINT);
let height = ctx.input().screen_rect().height(); let height = ctx.input().screen_rect().height();
let color = get_color(self.done); let t = self.done.powi(3);
let color = get_color(t);
egui::CentralPanel::default() egui::CentralPanel::default()
.frame(Frame::none().fill(color)) .frame(Frame::none().fill(color))
@ -51,5 +52,6 @@ fn get_color(t: f32) -> Color32 {
(sg + (mag * ug).round()) as u8, (sg + (mag * ug).round()) as u8,
(sb + (mag * ub).round()) as u8, (sb + (mag * ub).round()) as u8,
); );
// when t is 1.0, then the final color is roughly 170, 29, 23.
Color32::from_rgb(r, g, b) Color32::from_rgb(r, g, b)
} }

View file

@ -17,7 +17,7 @@ pub enum CountDirection {
Down, Down,
} }
#[derive(Debug, Clone)] #[derive(Clone)]
pub struct Timer { pub struct Timer {
direction: CountDirection, direction: CountDirection,
duration: Duration, duration: Duration,
@ -84,6 +84,7 @@ impl Timer {
timer.state = TimerState::Running(cs); timer.state = TimerState::Running(cs);
} }
timer timer
} }
@ -125,8 +126,7 @@ impl Timer {
return; return;
} }
self.done = self.done = 1.0 - (remaining.as_secs_f32() / self.duration.as_secs_f32());
(1.0 - (remaining.as_millis() as f32 / self.duration.as_millis() as f32)).powi(3);
let (sender, rx) = channel(); let (sender, rx) = channel();
{ {