rust_minifb/examples/noise.rs
Daniel Collin d8c2a38f39 Changed keys api and added check if window is open
Also removed ugly CLOSE_APP global
2015-12-09 15:44:34 +01:00

37 lines
937 B
Rust

extern crate minifb;
use minifb::*;
const WIDTH: usize = 640;
const HEIGHT: usize = 360;
fn main() {
let mut noise;
let mut carry;
let mut seed = 0xbeefu32;
let mut buffer: [u32; WIDTH * HEIGHT] = [0; WIDTH * HEIGHT];
let mut window = Window::new("Noise Test - Press ESC to exit",
WIDTH,
HEIGHT,
Scale::X1,
Vsync::No)
.unwrap();
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.update(&buffer);
}
}