graphics: use dumb lfsr instead of rand crate

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2020-08-14 18:20:37 +08:00
parent 92a21a9fce
commit 6abe2af34e
2 changed files with 7 additions and 8 deletions

View file

@ -7,9 +7,7 @@ description = "Manage the video output"
[dependencies]
xous = { path = "../../xous-rs" }
embedded-graphics = "0.6"
[target.'cfg(not(target_os = "none"))'.dependencies]
minifb = "0.17"
#pixels = "0.1"
rand = "*"

View file

@ -2,12 +2,10 @@ use minifb::{Key, Window, WindowOptions};
const WIDTH: usize = 336;
const HEIGHT: usize = 536;
const MAX_FPS: u64 = 10;
const MAX_FPS: u64 = 15;
const LIGHT_COLOUR: u32 = 0xB5B5AD;
const DARK_COLOUR: u32 = 0x1B1B19;
use rand::prelude::*;
pub fn run() {
let mut buffer: Vec<u32> = vec![0; WIDTH * HEIGHT];
@ -30,10 +28,13 @@ pub fn run() {
1000 * 1000 / MAX_FPS,
)));
let mut rng = rand::thread_rng();
let mut lfsr = 0xace1u32;
while window.is_open() && !window.is_key_down(Key::Escape) {
for i in buffer.iter_mut() {
*i = if rng.gen() { LIGHT_COLOUR } else { DARK_COLOUR };
lfsr ^= lfsr >> 7;
lfsr ^= lfsr << 9;
lfsr ^= lfsr >> 13;
*i = if lfsr & 1 == 0 { LIGHT_COLOUR } else { DARK_COLOUR };
}
// We unwrap here as we want this code to exit if it fails.