rust_minifb/examples/noise.rs

39 lines
936 B
Rust
Raw Normal View History

2015-11-23 04:55:38 +11:00
extern crate minifb;
2015-11-28 07:25:50 +11:00
use minifb::*;
2015-11-24 05:23:11 +11:00
const WIDTH: usize = 640;
const HEIGHT: usize = 360;
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
2015-11-28 09:42:28 +11:00
let mut buffer: [u32; WIDTH * HEIGHT] = [0; WIDTH * HEIGHT];
2015-11-23 04:55:38 +11:00
let mut window = Window::new("Noise Test - Press ESC to exit", WIDTH, HEIGHT, Scale::X1, Vsync::No).unwrap();
2015-11-23 04:55:38 +11:00
while window.update(&buffer) {
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;
}
for key in window.get_keys().iter() {
match *key {
Key::A => println!("Pressed A"),
Key::B => println!("Pressed B"),
_ => (),
}
}
2015-11-23 04:55:38 +11:00
}
}