Skip to content

Instantly share code, notes, and snippets.

@peterhellberg
Created November 12, 2023 18:08
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 peterhellberg/198498dddf0ba0147b4ea9de68041c5b to your computer and use it in GitHub Desktop.
Save peterhellberg/198498dddf0ba0147b4ea9de68041c5b to your computer and use it in GitHub Desktop.
const tic = @import("tic80.zig");
const Rainbow = struct {
red: u8 = 255,
grn: u8 = 0,
blu: u8 = 0,
cyRG: bool = true,
cyGB: bool = false,
cyBR: bool = false,
fn update(self: *Rainbow, slot: u32) void {
if (self.cyRG == true) {
self.grn +|= 1;
if (self.grn == 255) {
self.red -|= 1;
}
if (self.red == 0) {
self.cyRG = false;
self.cyGB = true;
}
}
if (self.cyGB == true) {
self.blu +|= 1;
if (self.blu == 255) {
self.grn -|= 1;
if (self.grn == 0) {
self.cyGB = false;
self.cyBR = true;
}
}
}
if (self.cyBR == true) {
self.red +|= 1;
if (self.red == 255) {
self.blu -|= 1;
if (self.blu == 0) {
self.cyBR = false;
self.cyRG = true;
}
}
}
tic.poke(0x3fc0 + (slot * 3) + 2, self.blu);
tic.poke(0x3fc0 + (slot * 3) + 1, self.grn);
tic.poke(0x3fc0 + (slot * 3), self.red);
}
};
@peterhellberg
Copy link
Author

peterhellberg commented Nov 12, 2023

Updating the color in BDR:
TICGuy with rainbow eyes: BDR

Updating the color in TIC:
TICGuy with rainbow eyes: TIC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment