forked from emoon/rust_minifb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wasm.rs
54 lines (46 loc) · 1.53 KB
/
wasm.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
extern crate minifb;
use minifb::{Window, Key, Scale, WindowOptions};
const WIDTH: usize = 640;
const HEIGHT: usize = 360;
fn main() {
let mut noise;
let mut carry;
let mut seed = 0xbeefu32;
let mut buffer: Vec<u32> = vec![0; WIDTH * HEIGHT];
let mut window = match Window::new("Noise Test - Press ESC to exit", WIDTH, HEIGHT,
WindowOptions {
resize: true,
scale: Scale::X2,
..WindowOptions::default()
}) {
Ok(win) => win,
Err(err) => {
println!("Unable to create window {}", err);
return;
}
};
while window.is_open() && !window.is_key_down(Key::Escape) {
for i in buffer.iter_mut() {
noise = seed;
noise >>= 3;
noise ^= seed;
carry = noise & 1;
noise >>= 1;
seed >>= 1;
seed |= carry << 30;
noise &= 0xFF;
*i = (noise << 16) | (noise << 8) | noise;
}
window.get_keys().map(|keys| {
for t in keys {
match t {
Key::W => println!("holding w!"),
Key::T => println!("holding t!"),
_ => (),
}
}
});
// We unwrap here as we want this code to exit if it fails
window.update_with_buffer(&buffer).unwrap();
}
}