Randomize cell initialization

master
Benoît 2020-06-10 20:50:04 +02:00
parent ac1fad7be2
commit 49ec2a21a5
2 changed files with 5 additions and 3 deletions

View File

@ -16,6 +16,7 @@ default = ["console_error_panic_hook"]
[dependencies]
wasm-bindgen = "0.2.63"
js-sys = "0.3"
# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires

View File

@ -1,5 +1,7 @@
mod utils;
extern crate js_sys;
use wasm_bindgen::prelude::*;
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
@ -129,10 +131,9 @@ impl Universe {
let width = w;
let height = h;
let cells = (0..width * height)
.map(|i| {
if i % 2 == 0 || i % 7 == 0 {
.map(|_| {
if js_sys::Math::random() < 0.5 {
Cell::Alive
} else {
Cell::Dead