Skip to content

Instantly share code, notes, and snippets.

@bltavares
Created January 19, 2016 20:42
Show Gist options
  • Save bltavares/c99d174c4d6acadc26ca to your computer and use it in GitHub Desktop.
Save bltavares/c99d174c4d6acadc26ca to your computer and use it in GitHub Desktop.
extern crate minifb;
use minifb::{Key, Scale};
const WIDTH: usize = 360;
const HEIGHT: usize = 360;
const PIXSIZE: usize = 4;
const PIXEL: [u32; PIXSIZE * PIXSIZE] = [
0x000000, 0x000000, 0xffffff, 0xffffff,
0x000000, 0x000000, 0xffffff, 0xffffff,
0xffffff, 0xffffff, 0x000000, 0x000000,
0xffffff, 0xffffff, 0x000000, 0x000000,
];
fn main() {
let mut buffer: Vec<u32> = vec![0; WIDTH * HEIGHT];
let mut window = match minifb::Window::new("Test - ESC to exit", WIDTH, HEIGHT, Scale::X1) {
Ok(win) => win,
Err(err) => {
panic!("Unable to create window {}", err);
}
};
while window.is_open() && !window.is_key_down(Key::Escape) {
for (index, i) in buffer.iter_mut().enumerate() {
let line = (index % WIDTH) % PIXSIZE;
let column = index % PIXSIZE;
let x : u32 = PIXEL[line + column];
*i = x;
}
window.update(&buffer);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment