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