From 6abe2af34e738262b96cec844878a6cad6a3c3cf Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Fri, 14 Aug 2020 18:20:37 +0800 Subject: [PATCH] graphics: use dumb lfsr instead of rand crate Signed-off-by: Sean Cross --- examples/graphics/Cargo.toml | 4 +--- examples/graphics/src/backend/minifb.rs | 11 ++++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/examples/graphics/Cargo.toml b/examples/graphics/Cargo.toml index 36f719bf5..c49956da7 100644 --- a/examples/graphics/Cargo.toml +++ b/examples/graphics/Cargo.toml @@ -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 = "*" diff --git a/examples/graphics/src/backend/minifb.rs b/examples/graphics/src/backend/minifb.rs index 995c43ac3..4df589d5f 100644 --- a/examples/graphics/src/backend/minifb.rs +++ b/examples/graphics/src/backend/minifb.rs @@ -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 = 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.