Buffer the rendering for better framerates; create a more useful example

This commit is contained in:
2020-07-24 23:25:16 -07:00
parent 5360d2c6d3
commit 2e92980113
2 changed files with 12 additions and 19 deletions

View File

@@ -1,6 +1,7 @@
use ansi_term::Color::RGB;
use crate::consts;
use crate::SimState;
use std::fmt::Write as _;
pub struct NumericTermRenderer;
@@ -34,17 +35,19 @@ fn norm_color(v: f32) -> u8 {
impl ColorTermRenderer {
pub fn render(&self, state: &SimState) {
let mut buf = String::new();
let square = "";
for y in 0..state.height() {
for x in 0..state.width() {
let cell = state.get(x, y);
let r = norm_color(cell.bz() * consts::C);
//let r = norm_color(cell.bz() * consts::C);
let r = 0;
let g = norm_color(cell.ex());
let b = norm_color(cell.ey());
print!("{}", RGB(r, g, b).paint(square));
write!(&mut buf, "{}", RGB(r, g, b).paint(square));
}
print!("\n");
write!(&mut buf, "\n");
}
print!("\n");
println!("{}", buf);
}
}