2020-07-13 06:00:54 +00:00
|
|
|
use ansi_term::Color::RGB;
|
2020-08-27 19:51:12 +00:00
|
|
|
use crate::{consts, Material as _, SimState};
|
2020-07-25 06:25:16 +00:00
|
|
|
use std::fmt::Write as _;
|
2020-07-13 04:16:42 +00:00
|
|
|
|
|
|
|
pub struct NumericTermRenderer;
|
|
|
|
|
|
|
|
impl NumericTermRenderer {
|
|
|
|
pub fn render(&self, state: &SimState) {
|
2020-07-15 06:26:27 +00:00
|
|
|
for y in 0..state.height() {
|
|
|
|
for x in 0..state.width() {
|
|
|
|
let cell = state.get(x, y);
|
|
|
|
print!(" {:>10.1e}", cell.ex());
|
|
|
|
}
|
|
|
|
print!("\n");
|
|
|
|
for x in 0..state.width() {
|
|
|
|
let cell = state.get(x, y);
|
|
|
|
print!("{:>10.1e} {:>10.1e}", cell.ey(), cell.bz());
|
|
|
|
}
|
|
|
|
print!("\n");
|
2020-07-13 04:16:42 +00:00
|
|
|
}
|
|
|
|
print!("\n");
|
|
|
|
}
|
|
|
|
}
|
2020-07-13 06:00:54 +00:00
|
|
|
|
|
|
|
pub struct ColorTermRenderer;
|
|
|
|
|
|
|
|
fn clamp(v: f32, range: f32) -> f32 {
|
|
|
|
v.min(range).max(-range)
|
|
|
|
}
|
|
|
|
|
2020-08-01 01:46:19 +00:00
|
|
|
fn norm_color(v: f64) -> u8 {
|
|
|
|
(v * 64.0 + 128.0).max(0.0).min(255.0) as u8
|
2020-07-16 07:31:20 +00:00
|
|
|
}
|
|
|
|
|
2020-08-27 19:51:12 +00:00
|
|
|
fn curl(x: f64, y: f64) -> f64 {
|
2020-07-25 06:39:07 +00:00
|
|
|
let c = x * y;
|
2020-08-27 19:51:12 +00:00
|
|
|
if c >= 0.0 {
|
2020-07-25 06:39:07 +00:00
|
|
|
c.sqrt()
|
|
|
|
} else {
|
|
|
|
-(-c).sqrt()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-13 06:00:54 +00:00
|
|
|
impl ColorTermRenderer {
|
|
|
|
pub fn render(&self, state: &SimState) {
|
2020-07-25 06:25:16 +00:00
|
|
|
let mut buf = String::new();
|
2020-07-16 07:31:20 +00:00
|
|
|
let square = "█";
|
|
|
|
for y in 0..state.height() {
|
|
|
|
for x in 0..state.width() {
|
|
|
|
let cell = state.get(x, y);
|
2020-07-25 06:25:16 +00:00
|
|
|
//let r = norm_color(cell.bz() * consts::C);
|
2020-08-23 04:55:27 +00:00
|
|
|
//let r = 0;
|
2020-08-28 06:41:57 +00:00
|
|
|
let r = norm_color(cell.mat().mz()*1.0e-2);
|
2020-08-27 19:51:12 +00:00
|
|
|
let b = (55.0*cell.mat().conductivity()).min(255.0) as u8;
|
2020-08-17 03:14:46 +00:00
|
|
|
//let b = 0;
|
2020-07-25 06:39:07 +00:00
|
|
|
//let b = norm_color(cell.ey());
|
2020-08-27 22:23:52 +00:00
|
|
|
//let g = 0;
|
|
|
|
//let g = norm_color(cell.ex());
|
2020-07-25 06:39:07 +00:00
|
|
|
//let g = norm_color(curl(cell.ex(), cell.ey()));
|
2020-08-28 06:41:57 +00:00
|
|
|
let g = norm_color((cell.bz() * 1.0e4).into());
|
2020-08-27 19:51:12 +00:00
|
|
|
//let g = norm_color(cell.ey().into());
|
2020-07-25 06:25:16 +00:00
|
|
|
write!(&mut buf, "{}", RGB(r, g, b).paint(square));
|
2020-07-16 07:31:20 +00:00
|
|
|
}
|
2020-07-25 06:25:16 +00:00
|
|
|
write!(&mut buf, "\n");
|
2020-07-16 07:31:20 +00:00
|
|
|
}
|
2020-08-01 02:01:00 +00:00
|
|
|
println!("{}\ntime: {:.3e}", buf, state.time());
|
2020-07-13 06:00:54 +00:00
|
|
|
}
|
|
|
|
}
|