renderer can navigate forward in time (and also in the + or - z direction)

Can't navigate backward yet
This commit is contained in:
2020-11-28 13:49:30 -08:00
parent 58fa41ce87
commit 8f8c42a853
3 changed files with 94 additions and 21 deletions

View File

@@ -1,16 +1,17 @@
use ansi_term::Color::RGB;
use crate::geom::{Index, Meters, Vec2, Vec3, Vec3u};
use crate::{flt::{Flt, Real}, Material as _};
use crate::mat;
use crate::sim::{Cell, GenericSim};
use crate::meas::AbstractMeasurement;
use crossterm::{cursor, ExecutableCommand as _, QueueableCommand as _};
use crossterm::style::{style, Color, PrintStyledContent, StyledContent as _};
use font8x8::{BASIC_FONTS, GREEK_FONTS, UnicodeFonts as _};
use log::{trace, info};
use plotly;
use image::{RgbImage, Rgb};
use imageproc::{pixelops, drawing};
use std::fs::File;
use std::io::BufWriter;
use std::io::{BufWriter, Write as _};
use std::path::PathBuf;
use std::sync::{Mutex, RwLock};
use y4m;
@@ -274,17 +275,25 @@ pub struct ColorTermRenderer;
impl Renderer for ColorTermRenderer {
fn render_with_image(&self, _state: &dyn GenericSim, im: &RgbImage) {
let square = "";
let buf: String = im
.enumerate_rows()
.map(|(_y, row)| {
format!("{}\n", row.map(|(_x, _y, p)| {
format!("{}", RGB(p.0[0], p.0[1], p.0[2]).paint(square))
}).collect::<String>())
})
.collect();
println!("{}", buf);
// TODO: should scale the image to the size of the terminal!
let mut stdout = std::io::stdout();
let (w, h) = crossterm::terminal::size().unwrap();
stdout.queue(cursor::MoveTo(0, 0));
for (y, row) in im.enumerate_rows() {
if y >= h.into() {
break;
}
stdout.queue(cursor::MoveDown(1));
stdout.queue(cursor::MoveToColumn(0));
for (_x, _y, p) in row {
stdout.queue(PrintStyledContent(style(" ").on(Color::Rgb {
r: p.0[0],
g: p.0[1],
b: p.0[2],
})));
}
}
stdout.flush();
}
}