Skip to content

Instantly share code, notes, and snippets.

@jackmott
Created June 10, 2017 11:54
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 jackmott/d654720a5647166b119e23b646358a40 to your computer and use it in GitHub Desktop.
Save jackmott/d654720a5647166b119e23b646358a40 to your computer and use it in GitHub Desktop.
checkerboard pattern sdl2 rust
let mut finish_line_tex = texture_creator
.create_texture_streaming(PixelFormatEnum::RGB24,
FINISH_LINE_LENGTH as u32,
FINISH_LINE_WIDTH as u32)
.unwrap();
finish_line_tex.set_blend_mode(BlendMode::Add);
finish_line_tex
.with_lock(None,
|buffer: &mut [u8], pitch: usize| for y in 0..FINISH_LINE_WIDTH {
for x in 0..FINISH_LINE_LENGTH {
let offset = y as usize * pitch + x as usize * 3;
let color = if (y as f64 / 5.0) as i32 % 2 == 0 {
if (x as f64 / 5.0) as i32 % 2 == 0 {
0
} else {
128
}
} else {
if (x as f64 / 5.0) as i32 % 2 == 0 {
128
} else {
0
}
};
buffer[offset] = color;
buffer[offset + 1] = color;
buffer[offset + 2] = color;
}
})
.unwrap();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment