Skip to content

Commit

Permalink
Fix randomize
Browse files Browse the repository at this point in the history
  • Loading branch information
davidseid committed Jun 20, 2020
1 parent 6f5c84f commit 84b30a5
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ impl Universe {
let height = 128;

let cells = (0..width * height)
.map(|_| {
if js_sys::Math::random() < 0.5 {
Cell::Dead
} else {
.map(|i| {
if i % 2 == 0 || i % 7 == 0 {
Cell::Alive
} else {
Cell::Dead
}
})
.collect();
Expand All @@ -143,6 +143,20 @@ impl Universe {
}

pub fn restart(&mut self) {
let cells = (0..self.width * self.height)
.map(|i| {
if i % 2 == 0 || i % 7 == 0 {
Cell::Alive
} else {
Cell::Dead
}
})
.collect();

self.cells = cells;
}

pub fn randomize(&mut self) {
let mut next = self.cells.clone();

next = next.iter()
Expand Down

0 comments on commit 84b30a5

Please sign in to comment.