game-life-rs/src/main.rs

27 lines
599 B
Rust

use std::time::{Duration, Instant};
use game_life::Board;
const W: usize = 22;
const H: usize = 12;
// Framerate
const RATE: f32 = 60.0;
#[allow(unused_mut)]
fn main() {
let mut board: Board<W, H> = Default::default();
// Stick a glider in the top left corner
board.copy_from([
[0, 1, 0],
[0, 0, 1],
[1, 1, 1],
]);
println!("\x1b[H\x1b[J");
loop {
let time = Instant::now();
println!("\x1b[H{board}");
board.update();
std::thread::sleep(Duration::from_secs_f32(RATE.recip()).saturating_sub(time.elapsed()));
}
}