Add blank segments frames to reposition lasers between frames

This commit is contained in:
Leo Le Bouter 2020-10-07 15:36:31 +02:00
parent d63396b78e
commit 95b12fe9d1

View File

@ -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<Point> = last_frames
.first()
.unwrap()
.iter()
.map(|(x, y, color)| Point {
x: *x,
y: *y,
color: *color,
weight: default_weight,
})
.collect();
let b: Vec<Point> = last_frames
.last()
.unwrap()
.iter()
.map(|(x, y, color)| Point {
x: *x,
y: *y,
color: *color,
weight: default_weight,
})
.collect();
let c: Vec<InputArrayEntry> = 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()?;
}