Skip to content

Instantly share code, notes, and snippets.

@NotNite

NotNite/lib.rs Secret

Created September 25, 2024 23:18
Show Gist options
  • Save NotNite/4b48409e335368a7d94665df95b357ae to your computer and use it in GitHub Desktop.
Save NotNite/4b48409e335368a7d94665df95b357ae to your computer and use it in GitHub Desktop.
extern "C" {
// idx goes from 0..size()
// color is 0xRRGGBB
fn set_pixel(idx: u32, color: u32);
fn get_pixel(idx: u32) -> u32;
fn size() -> u32;
fn time() -> u64; // unix ms wall clock
}
#[no_mangle]
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn tick(time: f32) {
// time is elapsed seconds, starting at 0
let p = (time * 5.0) as u32;
for i in 0..size() {
if i == p {
set_pixel(i, 0xFFFFFF);
} else {
set_pixel(i, 0x000000);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment