Compare commits

...

2 Commits

Author SHA1 Message Date
histausse 40c026f32a
space ship 3 years ago
histausse 34cb5fb51c
random start 3 years ago

@ -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,49 @@ 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 new_space_ship() -> Universe {
let width : u32 = 64;
let height : u32 = 64;
let mut cells : Vec<Cell> = (0..width * height)
.map(|_i| { Cell::Dead })
.collect();
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[i] = Cell::Alive;
}
Universe {
width,
height,
cells,
}
}
pub fn render(&self) -> String {
self.to_string()
}

2
www

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