2024-05-07 07:56:02 +00:00
|
|
|
use crate::BRIGHTNESS;
|
|
|
|
use crate::HEIGHT;
|
|
|
|
use crate::Q;
|
|
|
|
use crate::WIDTH;
|
|
|
|
|
|
|
|
pub struct Cell {
|
|
|
|
pub x: u32,
|
|
|
|
pub y: u32,
|
|
|
|
pub state: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn init_grid() -> Vec<Vec<Cell>> {
|
|
|
|
let mut grid: Vec<Vec<Cell>> = Vec::new();
|
|
|
|
for j in 0..HEIGHT {
|
|
|
|
let mut row: Vec<Cell> = Vec::new();
|
|
|
|
for i in 0..WIDTH {
|
|
|
|
row.push(Cell {
|
|
|
|
x: i,
|
|
|
|
y: j,
|
|
|
|
state: 0,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
grid.push(row);
|
|
|
|
}
|
|
|
|
grid
|
|
|
|
}
|
2024-05-07 09:31:16 +00:00
|
|
|
|
|
|
|
fn map_num(n: usize, s: usize, e: usize, a: usize, b: usize) -> usize {
|
|
|
|
(a as f64 + (n as f64 - s as f64) * (b as f64 - a as f64) / (e as f64 - s as f64)) as usize
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn display_grid(grid: &Vec<Vec<Cell>>) {
|
|
|
|
for i in 0..HEIGHT {
|
|
|
|
for j in 0..WIDTH {
|
|
|
|
let x = i as usize;
|
|
|
|
let y = j as usize;
|
|
|
|
let state = grid[x][y].state as usize;
|
|
|
|
|
|
|
|
let index = map_num(state, 0, Q, 0, BRIGHTNESS.len());
|
|
|
|
print!("{}", BRIGHTNESS.chars().nth(index).unwrap());
|
|
|
|
}
|
|
|
|
println!();
|
|
|
|
}
|
|
|
|
}
|