2019-12-16 18:24:48 +11:00
|
|
|
use minifb::{Key, ScaleMode, Window, WindowOptions};
|
2015-11-28 07:25:50 +11:00
|
|
|
|
2019-12-16 18:24:48 +11:00
|
|
|
const WIDTH: usize = 640 / 2;
|
|
|
|
const HEIGHT: usize = 360 / 2;
|
2015-11-23 04:55:38 +11:00
|
|
|
|
|
|
|
fn main() {
|
2015-11-28 09:42:28 +11:00
|
|
|
let mut noise;
|
|
|
|
let mut carry;
|
|
|
|
let mut seed = 0xbeefu32;
|
2015-11-28 07:25:50 +11:00
|
|
|
|
2019-12-16 18:24:48 +11:00
|
|
|
let mut window = Window::new(
|
2019-11-27 18:03:33 +11:00
|
|
|
"Noise Test - Press ESC to exit",
|
|
|
|
WIDTH,
|
|
|
|
HEIGHT,
|
|
|
|
WindowOptions {
|
|
|
|
resize: true,
|
2019-12-16 18:24:48 +11:00
|
|
|
scale_mode: ScaleMode::UpperLeft,
|
2019-11-27 18:03:33 +11:00
|
|
|
..WindowOptions::default()
|
|
|
|
},
|
2019-12-16 18:24:48 +11:00
|
|
|
)
|
|
|
|
.expect("Unable to create window");
|
|
|
|
|
|
|
|
// Limit to max ~60 fps update rate
|
|
|
|
window.limit_update_rate(Some(std::time::Duration::from_micros(16600)));
|
2015-11-23 04:55:38 +11:00
|
|
|
|
2019-04-01 19:19:23 +11:00
|
|
|
let mut buffer: Vec<u32> = Vec::with_capacity(WIDTH * HEIGHT);
|
|
|
|
|
|
|
|
let mut size = (0, 0);
|
|
|
|
|
2015-12-10 01:44:34 +11:00
|
|
|
while window.is_open() && !window.is_key_down(Key::Escape) {
|
2019-12-16 18:24:48 +11:00
|
|
|
let new_size = (window.get_size().0, window.get_size().1);
|
2019-12-04 01:24:03 +11:00
|
|
|
if new_size != size {
|
|
|
|
size = new_size;
|
2019-12-16 18:24:48 +11:00
|
|
|
buffer.resize(size.0 * size.1, 0);
|
2019-04-01 19:19:23 +11:00
|
|
|
}
|
|
|
|
|
2015-11-23 04:56:53 +11: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-19 06:21:47 +11:00
|
|
|
|
2016-01-03 07:26:08 +11:00
|
|
|
window.get_keys().map(|keys| {
|
|
|
|
for t in keys {
|
|
|
|
match t {
|
2015-12-19 06:21:47 +11:00
|
|
|
Key::W => println!("holding w!"),
|
|
|
|
Key::T => println!("holding t!"),
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-03-18 04:17:04 +11:00
|
|
|
window.get_keys_released().map(|keys| {
|
|
|
|
for t in keys {
|
|
|
|
match t {
|
|
|
|
Key::W => println!("released w!"),
|
|
|
|
Key::T => println!("released t!"),
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-12-16 18:24:48 +11:00
|
|
|
window
|
|
|
|
.update_with_buffer(&buffer, new_size.0, new_size.1)
|
|
|
|
.unwrap();
|
2015-11-23 04:55:38 +11:00
|
|
|
}
|
|
|
|
}
|