2015-11-22 18:55:38 +01:00
|
|
|
extern crate minifb;
|
|
|
|
|
2016-01-05 21:29:52 +01:00
|
|
|
use minifb::{Window, Key, Scale};
|
2015-11-27 21:25:50 +01:00
|
|
|
|
2015-11-23 19:23:11 +01:00
|
|
|
const WIDTH: usize = 640;
|
|
|
|
const HEIGHT: usize = 360;
|
2015-11-22 18:55:38 +01:00
|
|
|
|
|
|
|
fn main() {
|
2015-11-27 23:42:28 +01:00
|
|
|
let mut noise;
|
|
|
|
let mut carry;
|
|
|
|
let mut seed = 0xbeefu32;
|
2015-11-27 21:25:50 +01:00
|
|
|
|
2016-01-05 21:29:52 +01:00
|
|
|
let mut buffer: Vec<u32> = vec![0; WIDTH * HEIGHT];
|
2015-11-22 18:55:38 +01:00
|
|
|
|
2016-01-02 19:40:41 +01:00
|
|
|
let mut window = match Window::new("Noise Test - Press ESC to exit", WIDTH, HEIGHT, Scale::X2) {
|
|
|
|
Ok(win) => win,
|
|
|
|
Err(err) => {
|
|
|
|
println!("Unable to create window {}", err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
2015-11-22 18:55:38 +01:00
|
|
|
|
2015-12-09 15:44:34 +01:00
|
|
|
while window.is_open() && !window.is_key_down(Key::Escape) {
|
2015-11-22 18:56:53 +01:00
|
|
|
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;
|
|
|
|
}
|
2015-12-18 20:21:47 +01:00
|
|
|
|
2016-01-02 21:26:08 +01:00
|
|
|
window.get_keys().map(|keys| {
|
|
|
|
for t in keys {
|
|
|
|
match t {
|
2015-12-18 20:21:47 +01:00
|
|
|
Key::W => println!("holding w!"),
|
|
|
|
Key::T => println!("holding t!"),
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-12-09 15:44:34 +01:00
|
|
|
window.update(&buffer);
|
2015-11-22 18:55:38 +01:00
|
|
|
}
|
|
|
|
}
|