diff --git a/src/main.rs b/src/main.rs index 80fa01d..6597ff5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,9 +4,9 @@ use anyhow::Result; use clap::{app_from_crate, crate_authors, crate_description, crate_name, crate_version, Arg}; use io::Write; use lasy::{ - euler_graph_to_euler_circuit, interpolate_euler_circuit, point_graph_to_euler_graph, - points_to_segments, segments_to_point_graph, Blanked, InterpolationConfig, IsBlank, Lerp, - Position, Weight, + blank_segment_points, euler_graph_to_euler_circuit, interpolate_euler_circuit, + point_graph_to_euler_graph, points_to_segments, segments_to_point_graph, Blanked, + InterpolationConfig, IsBlank, Lerp, Position, Weight, }; type InputArrayEntry = (f32, f32, u32); @@ -172,14 +172,55 @@ fn main() -> Result<()> { .expect("radians-per-point must be a float") } + let mut last_frames = vec![]; + loop { let mut line = String::new(); io::stdin().read_line(&mut line)?; - serde_json::to_writer( - io::stdout(), - &optimize_line(default_weight, &line, &config)?, - )?; + last_frames.push(optimize_line(default_weight, &line, &config)?); + + if last_frames.len() == 2 { + let a: Vec = last_frames + .first() + .unwrap() + .iter() + .map(|(x, y, color)| Point { + x: *x, + y: *y, + color: *color, + weight: default_weight, + }) + .collect(); + + let b: Vec = last_frames + .last() + .unwrap() + .iter() + .map(|(x, y, color)| Point { + x: *x, + y: *y, + color: *color, + weight: default_weight, + }) + .collect(); + + let c: Vec = a + .into_iter() + .zip(b.into_iter()) + .map(|(a, b)| blank_segment_points(a, b, config.blank_delay_points)) + .flatten() + .map(|p| (p.x, p.y, p.color)) + .collect(); + + serde_json::to_writer(io::stdout(), &c)?; + io::stdout().write(b"\n")?; + io::stdout().flush()?; + + last_frames.remove(0); + } + + serde_json::to_writer(io::stdout(), &last_frames.last())?; io::stdout().write(b"\n")?; io::stdout().flush()?; }