Randomize cell initialization
parent
ac1fad7be2
commit
49ec2a21a5
|
@ -16,6 +16,7 @@ default = ["console_error_panic_hook"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
wasm-bindgen = "0.2.63"
|
wasm-bindgen = "0.2.63"
|
||||||
|
js-sys = "0.3"
|
||||||
|
|
||||||
# The `console_error_panic_hook` crate provides better debugging of panics by
|
# The `console_error_panic_hook` crate provides better debugging of panics by
|
||||||
# logging them with `console.error`. This is great for development, but requires
|
# logging them with `console.error`. This is great for development, but requires
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
|
extern crate js_sys;
|
||||||
|
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
|
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
|
||||||
|
@ -129,10 +131,9 @@ impl Universe {
|
||||||
let width = w;
|
let width = w;
|
||||||
let height = h;
|
let height = h;
|
||||||
|
|
||||||
|
|
||||||
let cells = (0..width * height)
|
let cells = (0..width * height)
|
||||||
.map(|i| {
|
.map(|_| {
|
||||||
if i % 2 == 0 || i % 7 == 0 {
|
if js_sys::Math::random() < 0.5 {
|
||||||
Cell::Alive
|
Cell::Alive
|
||||||
} else {
|
} else {
|
||||||
Cell::Dead
|
Cell::Dead
|
||||||
|
|
Loading…
Reference in New Issue