Added columns
This commit is contained in:
parent
b695ee0bf7
commit
b61717cf21
14
src/main.zig
14
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,11 +106,13 @@ pub fn main() !void {
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user