Added rgb function
This commit is contained in:
parent
6120807f92
commit
149cf2a9b4
@ -5,6 +5,10 @@ const minifb_c = @cImport({
|
||||
});
|
||||
const testing = std.testing;
|
||||
|
||||
pub fn rgb(r: u8, g: u8, b: u8) u32 {
|
||||
return @intCast(u32, r) << 16 | @intCast(u32, g) << 8 | b;
|
||||
}
|
||||
|
||||
pub const Window = struct{
|
||||
cwin: *minifb_c.mfb_window,
|
||||
|
||||
@ -41,5 +45,5 @@ pub const Window = struct{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
14
src/main.zig
14
src/main.zig
@ -5,12 +5,16 @@ const minifb = @import("minifb");
|
||||
const Width = 800;
|
||||
const Height = 600;
|
||||
|
||||
fn grey(value: u8) u32 {
|
||||
return minifb.rgb(value, value, value);
|
||||
}
|
||||
|
||||
pub fn main() anyerror!void {
|
||||
std.log.info("All your codebase are belong to us.", .{});
|
||||
var win = minifb.Window.open("Hello minifb-zig", Width, Height) catch unreachable;
|
||||
|
||||
var color: u32 = 0xff000000;
|
||||
const deltaColor: u32 = 0x00010101;
|
||||
var color: u32 = grey(0);
|
||||
const deltaColor = grey(1);
|
||||
var increasing = true;
|
||||
var rawBuffer: [Width*Height]u32 = undefined;
|
||||
const buffer = rawBuffer[0..rawBuffer.len];
|
||||
@ -18,13 +22,13 @@ pub fn main() anyerror!void {
|
||||
|
||||
while (win.waitSync()) {
|
||||
if (increasing) {
|
||||
if (color < 0xffffffff) {
|
||||
if (color < grey(255)) {
|
||||
color += deltaColor;
|
||||
} else {
|
||||
increasing = false;
|
||||
}
|
||||
} else {
|
||||
if (color > 0xff000000) {
|
||||
if (color > grey(0)) {
|
||||
color -= deltaColor;
|
||||
} else {
|
||||
increasing = true;
|
||||
@ -33,7 +37,7 @@ pub fn main() anyerror!void {
|
||||
std.mem.set(u32, buffer, color);
|
||||
var i: u32 = 0;
|
||||
while (i < Width) {
|
||||
buffer[i] = 0xffff0000;
|
||||
buffer[i] = minifb.rgb(255,0,0);
|
||||
i += 1;
|
||||
}
|
||||
_ = win.update(buffer) catch unreachable;
|
||||
|
Loading…
Reference in New Issue
Block a user