defaut constructor generate a blank grid

master
histausse 3 years ago
parent ab37033267
commit 2cb68b6bdc
Signed by: histausse
GPG Key ID: 67486F107F62E9E9

@ -113,7 +113,7 @@ impl Universe {
let mut cells = FixedBitSet::with_capacity(size);
for i in 0..size {
cells.set(i, i % 2 == 0 || i % 7 == 0);
cells.set(i, false);
}
Universe {
@ -123,7 +123,7 @@ impl Universe {
}
}
pub fn new_random() -> Universe {
pub fn new_modulo() -> Universe {
let width = 64;
let height = 64;
let size = (width * height) as usize;
@ -131,7 +131,7 @@ impl Universe {
let mut cells = FixedBitSet::with_capacity(size);
for i in 0..size {
cells.set(i, js_sys::Math::random() < 0.5);
cells.set(i, i % 2 == 0 || i % 7 == 0);
}
Universe {
@ -141,22 +141,15 @@ impl Universe {
}
}
pub fn new_space_ship() -> Universe {
let width : u32 = 64;
let height : u32 = 64;
pub fn new_random() -> 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, 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);
cells.set(i, js_sys::Math::random() < 0.5);
}
Universe {
@ -166,6 +159,20 @@ impl Universe {
}
}
pub fn new_space_ship() -> Universe {
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 {
self.to_string()
}

2
www

@ -1 +1 @@
Subproject commit f6fa2759a6dce5379554d7294f00487bb1565004
Subproject commit 38933c4a49773b2c7acd9bdd9d398da278186ac3
Loading…
Cancel
Save