defaut constructor generate a blank grid
This commit is contained in:
parent
ab37033267
commit
2cb68b6bdc
2 changed files with 30 additions and 23 deletions
51
src/lib.rs
51
src/lib.rs
|
@ -112,6 +112,24 @@ impl Universe {
|
||||||
|
|
||||||
let mut cells = FixedBitSet::with_capacity(size);
|
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 {
|
for i in 0..size {
|
||||||
cells.set(i, i % 2 == 0 || i % 7 == 0);
|
cells.set(i, i % 2 == 0 || i % 7 == 0);
|
||||||
}
|
}
|
||||||
|
@ -142,28 +160,17 @@ impl Universe {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_space_ship() -> Universe {
|
pub fn new_space_ship() -> Universe {
|
||||||
let width : u32 = 64;
|
let mut univese = Universe::new();
|
||||||
let height : u32 = 64;
|
const X0: u32 = 32;
|
||||||
let size = (width * height) as usize;
|
const Y0: u32 = 32;
|
||||||
|
let cells = &(
|
||||||
let mut cells = FixedBitSet::with_capacity(size);
|
[(0, 2), (1, 0), (1, 2), (2, 1), (2, 2)]
|
||||||
|
.iter()
|
||||||
for i in 0..size {
|
.map(|(x, y)| (X0+x, Y0+y))
|
||||||
cells.set(i, false);
|
.collect::<Vec<(u32, u32)>>()
|
||||||
}
|
);
|
||||||
|
univese.set_cells(cells);
|
||||||
let x0 = 32;
|
univese
|
||||||
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,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(&self) -> String {
|
pub fn render(&self) -> String {
|
||||||
|
|
2
www
2
www
|
@ -1 +1 @@
|
||||||
Subproject commit f6fa2759a6dce5379554d7294f00487bb1565004
|
Subproject commit 38933c4a49773b2c7acd9bdd9d398da278186ac3
|
Loading…
Reference in a new issue