defaut constructor generate a blank grid

This commit is contained in:
histausse 2021-05-16 12:17:26 +02:00
parent ab37033267
commit 2cb68b6bdc
Signed by: histausse
GPG key ID: 67486F107F62E9E9
2 changed files with 30 additions and 23 deletions

View file

@ -112,6 +112,24 @@ impl Universe {
let mut cells = FixedBitSet::with_capacity(size);
for i in 0..size {
cells.set(i, false);
}
Universe {
width,
height,
cells,
}
}
pub fn new_modulo() -> Universe {
let width = 64;
let height = 64;
let size = (width * height) as usize;
let mut cells = FixedBitSet::with_capacity(size);
for i in 0..size {
cells.set(i, i % 2 == 0 || i % 7 == 0);
}
@ -142,28 +160,17 @@ impl Universe {
}
pub fn new_space_ship() -> Universe {
let width : u32 = 64;
let height : u32 = 64;
let size = (width * height) as usize;
let mut cells = FixedBitSet::with_capacity(size);
for i in 0..size {
cells.set(i, false);
}
let x0 = 32;
let y0 = 32;
for (x, y) in [(0, 2), (1, 0), (1, 2), (2, 1), (2, 2)].iter().cloned() {
let i = ((y0 + y) * width + x0 + x) as usize;
cells.set(i, true);
}
Universe {
width,
height,
cells,
}
let mut univese = Universe::new();
const X0: u32 = 32;
const Y0: u32 = 32;
let cells = &(
[(0, 2), (1, 0), (1, 2), (2, 1), (2, 2)]
.iter()
.map(|(x, y)| (X0+x, Y0+y))
.collect::<Vec<(u32, u32)>>()
);
univese.set_cells(cells);
univese
}
pub fn render(&self) -> String {

2
www

@ -1 +1 @@
Subproject commit f6fa2759a6dce5379554d7294f00487bb1565004
Subproject commit 38933c4a49773b2c7acd9bdd9d398da278186ac3