add transparency to vector fields
This commit is contained in:
@@ -9,20 +9,6 @@ use std::fs::File;
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use y4m;
|
use y4m;
|
||||||
|
|
||||||
// fn clamp(v: f32, range: f32) -> f32 {
|
|
||||||
// v.min(range).max(-range)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn curl(x: f64, y: f64) -> f64 {
|
|
||||||
// let c = x * y;
|
|
||||||
// if c >= 0.0 {
|
|
||||||
// c.sqrt()
|
|
||||||
// } else {
|
|
||||||
// -(-c).sqrt()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
|
|
||||||
/// Accept a value from (-\inf, \inf) and return a value in (-1, 1).
|
/// Accept a value from (-\inf, \inf) and return a value in (-1, 1).
|
||||||
/// If the input is equal to `typical`, it will be mapped to 0.5.
|
/// If the input is equal to `typical`, it will be mapped to 0.5.
|
||||||
/// If the input is equal to -`typical`, it will be mapped to -0.5.
|
/// If the input is equal to -`typical`, it will be mapped to -0.5.
|
||||||
@@ -77,16 +63,8 @@ impl SimStateRenderExt for SimState {
|
|||||||
for y in 0..h {
|
for y in 0..h {
|
||||||
for x in 0..w {
|
for x in 0..w {
|
||||||
let cell = self.get(x as usize, y as usize);
|
let cell = self.get(x as usize, y as usize);
|
||||||
//let r = norm_color(cell.bz() * consts::C);
|
|
||||||
//let r = 0;
|
|
||||||
let r = scale_signed_to_u8(cell.mat().mz(), 100.0);
|
let r = scale_signed_to_u8(cell.mat().mz(), 100.0);
|
||||||
let b = scale_unsigned_to_u8(cell.mat().conductivity(), 10.0);
|
let b = scale_unsigned_to_u8(cell.mat().conductivity(), 10.0);
|
||||||
//let b = 0;
|
|
||||||
//let b = norm_color(cell.ey());
|
|
||||||
//let g = 0;
|
|
||||||
//let g = norm_color(cell.ex());
|
|
||||||
//let g = norm_color(curl(cell.ex(), cell.ey()));
|
|
||||||
//let g = norm_color((cell.bz() * 1.0e4).into());
|
|
||||||
let g = scale_signed_to_u8(cell.bz(), 1.0e-4);
|
let g = scale_signed_to_u8(cell.bz(), 1.0e-4);
|
||||||
image.put_pixel(x, y, Rgb([r, g, b]));
|
image.put_pixel(x, y, Rgb([r, g, b]));
|
||||||
}
|
}
|
||||||
@@ -95,10 +73,11 @@ impl SimStateRenderExt for SimState {
|
|||||||
for y in 0..h {
|
for y in 0..h {
|
||||||
for x in 0..w {
|
for x in 0..w {
|
||||||
if x % evec_spacing == 0 && y % evec_spacing == 0 {
|
if x % evec_spacing == 0 && y % evec_spacing == 0 {
|
||||||
let mut vec = self.e_vector(x, y, evec_spacing) * 0.01;
|
let norm_vec = scale_vector(self.e_vector(x, y, evec_spacing), 100.0);
|
||||||
let vec = scale_vector(self.e_vector(x, y, evec_spacing), 100.0) * (evec_spacing as f64);
|
let alpha = norm_vec.mag_sq().powf(0.33);
|
||||||
|
let vec = norm_vec * (evec_spacing as f64);
|
||||||
let center = Point::new(x as _, y as _) + Point::new(evec_spacing as _, evec_spacing as _)*0.5;
|
let center = Point::new(x as _, y as _) + Point::new(evec_spacing as _, evec_spacing as _)*0.5;
|
||||||
image.draw_field_arrow(center, vec, Rgb([0xff, 0xff, 0xff]));
|
image.draw_field_arrow(center, vec, Rgb([0xff, 0xff, 0xff]), alpha as f32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -130,24 +109,23 @@ impl SimStateRenderExt for SimState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
trait ImageRenderExt {
|
trait ImageRenderExt {
|
||||||
fn draw_field_arrow(&mut self, center: Point, rel: Point, color: Rgb<u8>);
|
fn draw_field_arrow(&mut self, center: Point, rel: Point, color: Rgb<u8>, alpha: f32);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ImageRenderExt for RgbImage {
|
impl ImageRenderExt for RgbImage {
|
||||||
fn draw_field_arrow(&mut self, center: Point, rel: Point, color: Rgb<u8>) {
|
fn draw_field_arrow(&mut self, center: Point, rel: Point, color: Rgb<u8>, alpha: f32) {
|
||||||
let start = (center - rel * 0.5).round();
|
let start = (center - rel * 0.5).round();
|
||||||
let end = (center + rel * 0.5).round();
|
let end = (center + rel * 0.5).round();
|
||||||
let i_start = (start.x() as _, start.y() as _);
|
let i_start = (start.x() as _, start.y() as _);
|
||||||
let i_end = (end.x() as _, end.y() as _);
|
let i_end = (end.x() as _, end.y() as _);
|
||||||
drawing::draw_antialiased_line_segment_mut(self, i_start, i_end, color, pixelops::interpolate);
|
let interpolate_with_alpha = |left, right, left_weight| {
|
||||||
|
pixelops::interpolate(left, right, left_weight*alpha)
|
||||||
|
};
|
||||||
|
drawing::draw_antialiased_line_segment_mut(self, i_start, i_end, color, interpolate_with_alpha);
|
||||||
//drawing::draw_line_segment_mut(self, i_start, i_end, color);
|
//drawing::draw_line_segment_mut(self, i_start, i_end, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn norm_color(v: f64) -> u8 {
|
|
||||||
(v * 64.0 + 128.0).max(0.0).min(255.0) as u8
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait Renderer {
|
pub trait Renderer {
|
||||||
fn render(&mut self, state: &SimState);
|
fn render(&mut self, state: &SimState);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user