fade out on lost tracks
This commit is contained in:
parent
2ff2dc45d5
commit
a14f8b135c
4 changed files with 378 additions and 273 deletions
595
Cargo.lock
generated
595
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -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"] }
|
||||
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_json = "1.0.140"
|
||||
zmq = "0.10.0"
|
||||
|
|
|
@ -36,6 +36,7 @@ struct Model {
|
|||
current_lines: RenderableLines, // a copy for the drawing renderer
|
||||
last_update: Instant,
|
||||
// dimming_factor: f32,
|
||||
lost_alpha: f32,
|
||||
}
|
||||
|
||||
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 res: Result<RenderableLines> = serde_json::from_str(&json);
|
||||
model.lost_alpha = 1.;
|
||||
|
||||
lines = match res {
|
||||
Ok(lines) => lines, // if Ok(255), set x to 255
|
||||
|
@ -115,9 +117,18 @@ fn zmq_receive(model: &mut Model) {
|
|||
};
|
||||
} else if model.last_update < Instant::now() - Duration::from_millis(100){
|
||||
// set lines empty, if no new input for > 100ms (10fps)
|
||||
println!("No input, clear lines!!");
|
||||
lines = RenderableLines{
|
||||
lines: Vec::new()
|
||||
if model.lost_alpha > 0.{
|
||||
|
||||
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: Vec::new()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// No new lines, break
|
||||
|
@ -128,9 +139,9 @@ fn zmq_receive(model: &mut Model) {
|
|||
|
||||
for laser_stream in (&model.laser_streams).into_iter() {
|
||||
// let lines = get_laser_lines(version);
|
||||
let lines: RenderableLines = lines.clone();
|
||||
laser_stream.send(|laser| {
|
||||
let laser_lines: RenderableLines = lines;
|
||||
let lines_for_laser: RenderableLines = lines.clone();
|
||||
laser_stream.send(move |laser| {
|
||||
let laser_lines: RenderableLines = lines_for_laser;
|
||||
laser.current_lines = laser_lines;
|
||||
}).unwrap();
|
||||
}
|
||||
|
@ -229,6 +240,7 @@ fn model(app: &App) -> Model {
|
|||
zmq,
|
||||
current_lines: current_lines,
|
||||
last_update: Instant::now(),
|
||||
lost_alpha: 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_MAX: f32 = 1.0;
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -501,11 +514,13 @@ fn view_line_canvas(app: &App, model: &Model, frame: Frame) {
|
|||
let draw = app.draw();
|
||||
|
||||
// set background to blue
|
||||
draw.background().color(BLACK);
|
||||
draw.background().color(DARKGRAY);
|
||||
|
||||
let win = app.window_rect();
|
||||
|
||||
let scale = 25.;
|
||||
let translate_x = -300.;
|
||||
let translate_y = -100.;
|
||||
|
||||
draw_grid(&draw, &win, scale, 1.);
|
||||
// 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 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)
|
||||
});
|
||||
|
||||
|
|
|
@ -52,6 +52,21 @@ pub struct RenderableLine{
|
|||
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)]
|
||||
pub struct RenderableLines{
|
||||
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 {
|
||||
|
|
Loading…
Reference in a new issue