-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
39 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
mod desktop; | ||
mod effects; | ||
mod utils; | ||
mod window; | ||
|
||
extern crate alloc; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use agx_definitions::Color; | ||
use rand::rngs::SmallRng; | ||
use rand::RngCore; | ||
use rand::{Rng, SeedableRng}; | ||
|
||
#[cfg(target_os = "axle")] | ||
pub extern crate libc; | ||
#[cfg(target_os = "axle")] | ||
mod conditional_imports {} | ||
#[cfg(not(target_os = "axle"))] | ||
mod conditional_imports { | ||
pub use std::time::{SystemTime, UNIX_EPOCH}; | ||
} | ||
|
||
use crate::utils::conditional_imports::*; | ||
|
||
pub fn get_timestamp() -> u64 { | ||
#[cfg(target_os = "axle")] | ||
return unsafe { libc::ms_since_boot() as u64 }; | ||
#[cfg(not(target_os = "axle"))] | ||
return SystemTime::now() | ||
.duration_since(UNIX_EPOCH) | ||
.unwrap() | ||
.as_millis() as u64; | ||
} | ||
|
||
pub fn random_color() -> Color { | ||
let seed = get_timestamp(); | ||
let mut rng = SmallRng::seed_from_u64(seed); | ||
Color::new(rng.gen(), rng.gen(), rng.gen()) | ||
} | ||
|
||
pub fn random_color_with_rng(rng: &mut SmallRng) -> Color { | ||
Color::new(rng.gen(), rng.gen(), rng.gen()) | ||
} |