Added columns
This commit is contained in:
parent
b695ee0bf7
commit
b61717cf21
22
src/main.zig
22
src/main.zig
|
@ -8,6 +8,7 @@ const assert = @import("std").debug.assert;
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
const window_width = 300;
|
const window_width = 300;
|
||||||
const window_height = 500;
|
const window_height = 500;
|
||||||
|
const column_width = 100;
|
||||||
|
|
||||||
if (c.SDL_Init(c.SDL_INIT_VIDEO) != 0) {
|
if (c.SDL_Init(c.SDL_INIT_VIDEO) != 0) {
|
||||||
c.SDL_Log("Unable to initialize SDL: %s", c.SDL_GetError());
|
c.SDL_Log("Unable to initialize SDL: %s", c.SDL_GetError());
|
||||||
|
@ -70,15 +71,24 @@ pub fn main() !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
var i:usize = 0;
|
var i:usize = 0;
|
||||||
|
var column:c_int = 0;
|
||||||
x = 0;
|
x = 0;
|
||||||
var y:c_int = 0;
|
var y:c_int = 0;
|
||||||
|
// white: false, black: true
|
||||||
var color:bool = false;
|
var color:bool = false;
|
||||||
while (i < source_code.len) : (i += 1) {
|
while (i < source_code.len) : (i += 1) {
|
||||||
if (source_code[i] == 10) {
|
if (source_code[i] == 10) {
|
||||||
x = 0;
|
|
||||||
y += 1;
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (source_code[i] == 32 and color) {
|
if (source_code[i] == 32 and color) {
|
||||||
color = false;
|
color = false;
|
||||||
const white_color_result = c.SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
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 (x < (column + 1) * column_width) {
|
||||||
if (draw_result != 0) {
|
const draw_result = c.SDL_RenderDrawPoint(renderer, x, y);
|
||||||
c.SDL_Log("Unable to draw point: %d", draw_result);
|
if (draw_result != 0) {
|
||||||
return error.SDLDrawingFailed;
|
c.SDL_Log("Unable to draw point: %d", draw_result);
|
||||||
|
return error.SDLDrawingFailed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
x += 1;
|
x += 1;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user