Skip to content

Instantly share code, notes, and snippets.

@jedahan
Created July 17, 2016 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jedahan/63ff4bf56f9579d534c99a2aad3b6cbb to your computer and use it in GitHub Desktop.
Save jedahan/63ff4bf56f9579d534c99a2aad3b6cbb to your computer and use it in GitHub Desktop.
extern crate minifb;
use std::thread;
use std::time::Duration;
use std::thread::sleep;
use minifb::WindowOptions;
const WIDTH: usize = 288;
const HEIGHT: usize = 160;
fn main() {
let mut buffer = vec![0; WIDTH * HEIGHT];
let mut frames: u32 = 0;
let _ = thread::spawn(move || {
println!("Hello from child thread");
let mut window = minifb::Window::new("debug", WIDTH, HEIGHT, WindowOptions::default()).unwrap();
println!("Hello from after window creation in the child thread");
while frames < 0xFF {
println!("Hello from frame {}", frames);
for i in buffer.iter_mut() {
*i = frames;
}
window.update_with_buffer(&buffer);
frames = frames + 1;
sleep(Duration::from_millis(16));
}
});
loop {
println!("Hi from the main thread");
sleep(Duration::from_millis(10000));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment