random start

master
histausse 3 years ago
parent 93eee26940
commit 34cb5fb51c
Signed by: histausse
GPG Key ID: 67486F107F62E9E9

@ -11,6 +11,7 @@ crate-type = ["cdylib", "rlib"]
default = ["console_error_panic_hook"]
[dependencies]
js-sys = "0.3"
wasm-bindgen = "0.2.63"
# The `console_error_panic_hook` crate provides better debugging of panics by

@ -3,6 +3,8 @@ mod utils;
use std::fmt;
use wasm_bindgen::prelude::*;
extern crate js_sys;
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
// allocator.
#[cfg(feature = "wee_alloc")]
@ -101,6 +103,27 @@ impl Universe {
}
}
pub fn new_random() -> Universe {
let width = 64;
let height = 64;
let cells = (0..width * height)
.map(|_i| {
if js_sys::Math::random() < 0.5 {
Cell::Alive
} else {
Cell::Dead
}
})
.collect();
Universe {
width,
height,
cells,
}
}
pub fn render(&self) -> String {
self.to_string()
}

2
www

@ -1 +1 @@
Subproject commit 645cf7d32c691bf9c156d34c5b18c0ea5f85e767
Subproject commit 7ba57de4672a6a84db7f155c162a267809bacd7e
Loading…
Cancel
Save