Created
November 11, 2023 16:40
-
-
Save peterhellberg/e56ca1373f3fdf18a54733263196e0ab to your computer and use it in GitHub Desktop.
Implementation of https://github.com/nesbox/TIC-80/wiki/Code-examples-and-snippets#screen-wave-and-sky-gradient in Zig ⚡
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
const math = @import("std").math; | |
const tic = @import("tic80.zig"); | |
export fn BDR(row: i32) void { | |
const urow: u8 = @intCast(row); | |
{ // skygradient | |
scanline(0x42, 0xFF -| urow, 0x99 +| urow); | |
} | |
{ // screen wave | |
if (row < 90) { | |
tic.poke(0x3ff9, 0); | |
} else { | |
tic.poke(0x3ff9, @intFromFloat( | |
5 + math.sin(tic.time() / 200 + @as( | |
f32, | |
@floatFromInt(row), | |
) / 5) * 10, | |
)); | |
} | |
} | |
} | |
fn scanline(r: u8, g: u8, b: u8) void { | |
tic.poke(0x3fc0, r); | |
tic.poke(0x3fc1, g); | |
tic.poke(0x3fc2, b); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Peek.2023-11-11.17-17.webm
Peek.2023-11-11.17-19.webm