Buffer the rendering for better framerates; create a more useful example
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user