aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/debug.txt13
-rw-r--r--src/generation.rs28
-rw-r--r--src/ui.rs9
3 files changed, 32 insertions, 18 deletions
diff --git a/src/debug.txt b/src/debug.txt
new file mode 100644
index 0000000..1aec867
--- /dev/null
+++ b/src/debug.txt
@@ -0,0 +1,13 @@
+warning: function `render_gen` is never used
+ --> src/generation.rs:38:8
+ |
+38 | pub fn render_gen(chunk: &Rect, gen: &Gen) {
+ | ^^^^^^^^^^
+ |
+ = note: `#[warn(dead_code)]` on by default
+
+warning: `gof-rs` (bin "gof-rs") generated 1 warning
+ Finished dev [unoptimized + debuginfo] target(s) in 0.02s
+ Running `/home/pengu/test/rust-dev/gof-rs/target/debug/gof-rs`
+heigt: 44
+width: 62
diff --git a/src/generation.rs b/src/generation.rs
index a105d43..df971d7 100644
--- a/src/generation.rs
+++ b/src/generation.rs
@@ -50,18 +50,20 @@ pub fn render_gen(chunk: &Rect, gen: &Gen) {
pub fn new_gen(chunk: &Rect) -> Gen {
let cells = vec![Cell::Dead, Cell::Dead, Cell::Alive, Cell::Dead, Cell::Alive];
- let cols: u16 = chunk.height;
- let rows: u16 = chunk.width;
- let mut colums: Vec<Vec<Cell>> = Vec::new();
- for _ in 0..cols {
- let mut col: Vec<Cell> = Vec::new();
- for _ in 0..rows {
+ let cols: u16 = chunk.width - 90;
+ let rows: u16 = chunk.height - 2;
+ eprintln!("heigt: {}", rows);
+ eprintln!("width: {}", cols);
+ let mut grid: Vec<Vec<Cell>> = Vec::new();
+ for _ in 0..rows {
+ let mut row: Vec<Cell> = Vec::new();
+ for _ in 0..cols{
let rand = thread_rng().gen_range(0..10);
- col.push(cells[rand % 5]);
+ row.push(cells[rand % 5]);
}
- colums.push(col);
+ grid.push(row);
}
- colums
+ grid
}
pub fn gen_to_spans(gen: &Gen) -> Vec<Spans> {
@@ -70,8 +72,12 @@ pub fn gen_to_spans(gen: &Gen) -> Vec<Spans> {
let mut txt = String::new();
for j in 0..gen[0].len() {
match gen[i][j] {
- Cell::Alive => txt.push('X'),
- Cell::Dead => txt.push('-'),
+ // Cell::Alive => print!("😎"),
+ // Cell::Alive => txt.push_str("🦀"),
+ Cell::Alive => txt.push_str("❌"),
+ Cell::Dead => txt.push_str("⬛️"),
+ // Cell::Alive => txt.push('X'),
+ // Cell::Dead => txt.push('-'),
}
}
spans.push(Spans::from(txt));
diff --git a/src/ui.rs b/src/ui.rs
index 08d615f..7317901 100644
--- a/src/ui.rs
+++ b/src/ui.rs
@@ -115,13 +115,8 @@ pub fn run_app<B: Backend>(
let mut last_tick = Instant::now();
loop {
terminal.draw(|f| ui(f, &mut app))?;
- // let mut frame = app.generation;
- // let nxt;
- // let timeout = tick_rate
- // .checked_sub(last_tick.elapsed())
- // .unwrap_or_else(|| Duration::from_secs(0));
- let timeout = Duration::from_millis(40);
+ let timeout = Duration::from_millis(10);
if crossterm::event::poll(timeout)? {
if let Event::Key(key) = event::read()? {
match key.code {
@@ -214,6 +209,6 @@ fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
let paragraph = Paragraph::new(spans.clone())
.style(Style::default().bg(Color::Black).fg(Color::Blue))
.block(create_block(" Game Of Life "))
- .alignment(Alignment::Left);
+ .alignment(Alignment::Center);
f.render_widget(paragraph, chunks[1]);
}