From b61717cf219351dfc1c8e2a41c43d11480136c6a Mon Sep 17 00:00:00 2001 From: Nathan Christopher McRae Date: Sun, 4 Jun 2023 15:19:51 -0700 Subject: [PATCH] Added columns --- src/main.zig | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main.zig b/src/main.zig index 9f9636b..c9d3b31 100644 --- a/src/main.zig +++ b/src/main.zig @@ -8,6 +8,7 @@ const assert = @import("std").debug.assert; pub fn main() !void { const window_width = 300; const window_height = 500; + const column_width = 100; if (c.SDL_Init(c.SDL_INIT_VIDEO) != 0) { c.SDL_Log("Unable to initialize SDL: %s", c.SDL_GetError()); @@ -70,15 +71,24 @@ pub fn main() !void { } var i:usize = 0; + var column:c_int = 0; x = 0; var y:c_int = 0; + // white: false, black: true var color:bool = false; while (i < source_code.len) : (i += 1) { if (source_code[i] == 10) { - x = 0; y += 1; + if (y > window_height) { + y = 0; + column += 1; + // std.debug.print("Column: {any}, x: {any}\n", .{column, column*column_width}); + } + x = column * column_width; continue; } + + if (source_code[i] == 32 and color) { color = false; const white_color_result = c.SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); @@ -96,10 +106,12 @@ pub fn main() !void { } } - const draw_result = c.SDL_RenderDrawPoint(renderer, x, y); - if (draw_result != 0) { - c.SDL_Log("Unable to draw point: %d", draw_result); - return error.SDLDrawingFailed; + if (x < (column + 1) * column_width) { + const draw_result = c.SDL_RenderDrawPoint(renderer, x, y); + if (draw_result != 0) { + c.SDL_Log("Unable to draw point: %d", draw_result); + return error.SDLDrawingFailed; + } } x += 1;