fade out on lost tracks

This commit is contained in:
Ruben van de Ven 2025-05-16 15:30:53 +02:00
parent 2ff2dc45d5
commit a14f8b135c
4 changed files with 378 additions and 273 deletions

595
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -8,7 +8,7 @@ bevy = "0.15.3"
bevy_nannou = { git = "https://github.com/nannou-org/nannou", branch = "bevy-refactor", version = "0.1.0", features = ["wayland"] } bevy_nannou = { git = "https://github.com/nannou-org/nannou", branch = "bevy-refactor", version = "0.1.0", features = ["wayland"] }
iyes_perf_ui = "0.4.0" iyes_perf_ui = "0.4.0"
nannou_laser = { git = "https://github.com/seem-less/nannou", branch = "helios_laser_DAC" } nannou_laser = { git = "https://github.com/rubenvandeven/nannou", branch = "helios_laser_DAC" }
serde = "1.0.219" serde = "1.0.219"
serde_json = "1.0.140" serde_json = "1.0.140"
zmq = "0.10.0" zmq = "0.10.0"

View file

@ -36,6 +36,7 @@ struct Model {
current_lines: RenderableLines, // a copy for the drawing renderer current_lines: RenderableLines, // a copy for the drawing renderer
last_update: Instant, last_update: Instant,
// dimming_factor: f32, // dimming_factor: f32,
lost_alpha: f32,
} }
struct LaserSettings { struct LaserSettings {
@ -101,6 +102,7 @@ fn zmq_receive(model: &mut Model) {
// let msg: Frame = serde_json::from_str(&json[4..]).expect("No valid json?"); // let msg: Frame = serde_json::from_str(&json[4..]).expect("No valid json?");
let res: Result<RenderableLines> = serde_json::from_str(&json); let res: Result<RenderableLines> = serde_json::from_str(&json);
model.lost_alpha = 1.;
lines = match res { lines = match res {
Ok(lines) => lines, // if Ok(255), set x to 255 Ok(lines) => lines, // if Ok(255), set x to 255
@ -115,10 +117,19 @@ fn zmq_receive(model: &mut Model) {
}; };
} else if model.last_update < Instant::now() - Duration::from_millis(100){ } else if model.last_update < Instant::now() - Duration::from_millis(100){
// set lines empty, if no new input for > 100ms (10fps) // set lines empty, if no new input for > 100ms (10fps)
if model.lost_alpha > 0.{
println!("No input, clear lines!!"); println!("No input, clear lines!!");
model.lost_alpha *= 0.80;
if model.lost_alpha < 0.1{
model.lost_alpha = 0.;
}
lines = model.current_lines.with_alpha(model.lost_alpha);
} else {
lines = RenderableLines{ lines = RenderableLines{
lines: Vec::new() lines: Vec::new()
} }
}
} else { } else {
// No new lines, break // No new lines, break
return return
@ -128,9 +139,9 @@ fn zmq_receive(model: &mut Model) {
for laser_stream in (&model.laser_streams).into_iter() { for laser_stream in (&model.laser_streams).into_iter() {
// let lines = get_laser_lines(version); // let lines = get_laser_lines(version);
let lines: RenderableLines = lines.clone(); let lines_for_laser: RenderableLines = lines.clone();
laser_stream.send(|laser| { laser_stream.send(move |laser| {
let laser_lines: RenderableLines = lines; let laser_lines: RenderableLines = lines_for_laser;
laser.current_lines = laser_lines; laser.current_lines = laser_lines;
}).unwrap(); }).unwrap();
} }
@ -229,6 +240,7 @@ fn model(app: &App) -> Model {
zmq, zmq,
current_lines: current_lines, current_lines: current_lines,
last_update: Instant::now(), last_update: Instant::now(),
lost_alpha: 1.,
// dimming_factor: 1., // dimming_factor: 1.,
} }
} }
@ -270,6 +282,7 @@ fn laser_frame_producer(model: &mut LaserModel, frame: &mut laser::Frame){
const LASER_MIN: f32 = -1.0; const LASER_MIN: f32 = -1.0;
const LASER_MAX: f32 = 1.0; const LASER_MAX: f32 = 1.0;
if position[0] < LASER_MIN || position[0] > LASER_MAX || position[1] < LASER_MIN || position[1] > LASER_MAX{ if position[0] < LASER_MIN || position[0] > LASER_MAX || position[1] < LASER_MIN || position[1] > LASER_MAX{
// TODO apply previous point, as blanked (or formally, lerp to edge)
continue; continue;
} }
@ -501,11 +514,13 @@ fn view_line_canvas(app: &App, model: &Model, frame: Frame) {
let draw = app.draw(); let draw = app.draw();
// set background to blue // set background to blue
draw.background().color(BLACK); draw.background().color(DARKGRAY);
let win = app.window_rect(); let win = app.window_rect();
let scale = 25.; let scale = 25.;
let translate_x = -300.;
let translate_y = -100.;
draw_grid(&draw, &win, scale, 1.); draw_grid(&draw, &win, scale, 1.);
// let t = app.time; // let t = app.time;
@ -519,7 +534,7 @@ fn view_line_canvas(app: &App, model: &Model, frame: Frame) {
let vertices = line.points.iter().map(|p| { let vertices = line.points.iter().map(|p| {
let color = srgba(p.color.red, p.color.green, p.color.blue, p.color.alpha); let color = srgba(p.color.red, p.color.green, p.color.blue, p.color.alpha);
let pos = [p.position[0] * scale, p.position[1] * -scale]; let pos = [p.position[0] * scale + translate_x, p.position[1] * -scale + translate_y];
(pos, color) (pos, color)
}); });

View file

@ -52,6 +52,21 @@ pub struct RenderableLine{
pub points: Vec<RenderablePoint> pub points: Vec<RenderablePoint>
} }
impl RenderableLine {
pub fn with_alpha(&self, alpha: f32) -> Self {
if alpha == 1. {
self.clone();
}
Self { points: self.points.iter().map(|p| {
RenderablePoint{
position: p.position,
color: p.color.with_alpha(alpha),
}
}).collect()}
}
}
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct RenderableLines{ pub struct RenderableLines{
pub lines: Vec<RenderableLine> pub lines: Vec<RenderableLine>
@ -73,6 +88,14 @@ impl RenderableLines{
} }
pub fn with_alpha(&self, alpha: f32) -> Self {
if alpha == 1. {
return self.clone();
}
Self { lines: self.lines.iter().map(|l| { l.with_alpha(alpha)}).collect() }
}
} }
impl From<&RenderablePoint> for laser::Point { impl From<&RenderablePoint> for laser::Point {