Skip to content

Instantly share code, notes, and snippets.

@crumblingstatue
Created September 6, 2016 07:14
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 crumblingstatue/71eb9ae274502a4a462dbb332ebcd871 to your computer and use it in GitHub Desktop.
Save crumblingstatue/71eb9ae274502a4a462dbb332ebcd871 to your computer and use it in GitHub Desktop.
extern crate sdl2;
use sdl2::event::Event;
use sdl2::keyboard::Keycode;
use sdl2::pixels::PixelFormatEnum::RGB24;
use sdl2::render::TextureAccess;
fn main() {
let sdl = sdl2::init().unwrap();
let video = sdl.video().unwrap();
let window = video.window("Pixel fun", 0, 0).fullscreen_desktop().build().unwrap();
let mut renderer = window.renderer().build().unwrap();
let mut event_pump = sdl.event_pump().unwrap();
let (w, h) = renderer.output_size().unwrap();
let mut texture = renderer.create_texture(RGB24, TextureAccess::Streaming, w, h).unwrap();
for t in 0.. {
for event in event_pump.poll_iter() {
match event {
Event::Quit { .. } |
Event::KeyDown { keycode: Some(Keycode::Escape), .. } => {
return;
}
_ => {}
}
}
texture.with_lock(None, |data, _| {
for (i, b) in data.iter_mut().enumerate() {
let x = i as u32 % w;
let y = i as u32 / w;
*b = ((x ^ y) + t) as u8;
}
})
.unwrap();
renderer.copy(&texture, None, None);
renderer.present();
std::thread::sleep(std::time::Duration::from_millis(16));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment