mirror of
https://gitlab1.ptb.de/waltem01/Matrix
synced 2024-12-26 03:51:45 +00:00
optionally reuse old values
This commit is contained in:
parent
c9005a9150
commit
ef52dcfd7d
@ -9,15 +9,20 @@ pub struct Cell {
|
|||||||
pub state: u32,
|
pub state: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_grid() -> Vec<Vec<Cell>> {
|
pub fn init_grid(option: Option<&Vec<Vec<Cell>>>) -> Vec<Vec<Cell>> {
|
||||||
let mut grid: Vec<Vec<Cell>> = Vec::new();
|
let mut grid: Vec<Vec<Cell>> = Vec::new();
|
||||||
for j in 0..HEIGHT {
|
for j in 0..HEIGHT {
|
||||||
let mut row: Vec<Cell> = Vec::new();
|
let mut row: Vec<Cell> = Vec::new();
|
||||||
for i in 0..WIDTH {
|
for i in 0..WIDTH {
|
||||||
|
let mut value = rand::random::<u32>() % Q;
|
||||||
|
if let Some(g) = option {
|
||||||
|
value = g[j as usize][i as usize].state;
|
||||||
|
}
|
||||||
|
|
||||||
row.push(Cell {
|
row.push(Cell {
|
||||||
x: i,
|
x: i,
|
||||||
y: j,
|
y: j,
|
||||||
state: 0,
|
state: value,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
grid.push(row);
|
grid.push(row);
|
||||||
|
Loading…
Reference in New Issue
Block a user