better function naming
This commit is contained in:
parent
d45a70adcf
commit
e8f0988d46
91
main.zig
91
main.zig
@ -43,18 +43,7 @@ pub fn main() !void {
|
|||||||
win = try getTermDimension();
|
win = try getTermDimension();
|
||||||
|
|
||||||
print("winsize.ws_row: {}\nws_line: {}\nws_xpixel: {} \nws_ypixel: {}\n", .{ win.ws_row, win.ws_col, win.ws_xpixel, win.ws_ypixel });
|
print("winsize.ws_row: {}\nws_line: {}\nws_xpixel: {} \nws_ypixel: {}\n", .{ win.ws_row, win.ws_col, win.ws_xpixel, win.ws_ypixel });
|
||||||
try fillBuffer();
|
try draw();
|
||||||
try createFile();
|
|
||||||
if (getenv("TERM")) |buf| {
|
|
||||||
print("Buffer:{s}\n", .{buf});
|
|
||||||
const slice = getNum(buf);
|
|
||||||
_ = slice;
|
|
||||||
//for (slice) |num| {
|
|
||||||
// print("extracted number:\n{d}\n", .{num});
|
|
||||||
//}
|
|
||||||
} else {
|
|
||||||
print("Error getenv\n", .{});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getTermDimension() !Winsize {
|
fn getTermDimension() !Winsize {
|
||||||
@ -70,57 +59,7 @@ fn getTermDimension() !Winsize {
|
|||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getNum(str1: []const u8) []u64 {
|
fn draw() !void {
|
||||||
var pos: u64 = 0;
|
|
||||||
var num = std.mem.zeroes([64]u64);
|
|
||||||
var num_res = std.mem.zeroes([16]u64);
|
|
||||||
var it: u64 = 0;
|
|
||||||
for (str1, 0..) |elem, it2| {
|
|
||||||
if (elem >= 48 and elem <= 57) { //is ascii number?
|
|
||||||
num[pos] = @intCast(elem - 48);
|
|
||||||
if (pos <= @bitSizeOf(@TypeOf(pos))) {
|
|
||||||
pos += 1;
|
|
||||||
} else {
|
|
||||||
print("ERROR int u64 oveflow! pos {d} ,max {d}\n", .{ pos, @bitSizeOf(@TypeOf(pos)) });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//Calculate int out of characters
|
|
||||||
if ((elem < 48 or elem > 57) or it2 == (str1.len - 1)) {
|
|
||||||
if (pos != 0) {
|
|
||||||
for (0..pos) |i| {
|
|
||||||
if (i < pos - 1) {
|
|
||||||
num_res[it] = num_res[it] + num[i] * (std.math.pow(u64, 10, (pos - i - 1)));
|
|
||||||
} else {
|
|
||||||
num_res[it] = num_res[it] + num[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//print("numres:{}={}\n", .{ it, num_res[it] });
|
|
||||||
pos = 0;
|
|
||||||
it += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return &num_res;
|
|
||||||
}
|
|
||||||
fn createFile() !void {
|
|
||||||
const file = try std.fs.cwd().openFile("junk-file.txt", .{ .mode = std.fs.File.OpenMode.read_write });
|
|
||||||
defer file.close();
|
|
||||||
|
|
||||||
const bytes_written = try file.writeAll("hello world!");
|
|
||||||
//_ = bytes_written;
|
|
||||||
std.debug.print("files written:{any}, {any}", .{ bytes_written, @TypeOf(bytes_written) });
|
|
||||||
|
|
||||||
var buffer: [100]u8 = undefined;
|
|
||||||
try file.seekTo(0);
|
|
||||||
const bytes_read = try file.readAll(&buffer);
|
|
||||||
print("buffer: {s} check: {s}\n", .{ buffer[0..bytes_read], "hello world!" });
|
|
||||||
if (std.mem.eql(u8, buffer[0 .. bytes_read - 1], "hello world!") == true) {
|
|
||||||
print("equal\n", .{});
|
|
||||||
} else {
|
|
||||||
print("not equal\n", .{});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn fillBuffer() !void {
|
|
||||||
const allocator = std.heap.page_allocator;
|
const allocator = std.heap.page_allocator;
|
||||||
|
|
||||||
var w = Winsize{};
|
var w = Winsize{};
|
||||||
@ -171,26 +110,26 @@ fn fillBuffer() !void {
|
|||||||
//sleep(100000);
|
//sleep(100000);
|
||||||
|
|
||||||
try triangle(buffer, w, vec);
|
try triangle(buffer, w, vec);
|
||||||
bounce(w, &vec.a, 'x');
|
mv_axis_border_bounce(w, &vec.a, 'x');
|
||||||
bounce(w, &vec.a, 'y');
|
mv_axis_border_bounce(w, &vec.a, 'y');
|
||||||
bounce(w, &vec.b, 'x');
|
mv_axis_border_bounce(w, &vec.b, 'x');
|
||||||
bounce(w, &vec.b, 'y');
|
mv_axis_border_bounce(w, &vec.b, 'y');
|
||||||
bounce(w, &vec.c, 'x');
|
mv_axis_border_bounce(w, &vec.c, 'x');
|
||||||
bounce(w, &vec.c, 'y');
|
mv_axis_border_bounce(w, &vec.c, 'y');
|
||||||
|
|
||||||
try triangle(buffer, w, vec2);
|
try triangle(buffer, w, vec2);
|
||||||
bounce(w, &vec2.a, 'x');
|
mv_axis_border_bounce(w, &vec2.a, 'x');
|
||||||
bounce(w, &vec2.a, 'y');
|
mv_axis_border_bounce(w, &vec2.a, 'y');
|
||||||
bounce(w, &vec2.b, 'x');
|
mv_axis_border_bounce(w, &vec2.b, 'x');
|
||||||
bounce(w, &vec2.b, 'Y');
|
mv_axis_border_bounce(w, &vec2.b, 'Y');
|
||||||
bounce(w, &vec2.c, 'x');
|
mv_axis_border_bounce(w, &vec2.c, 'x');
|
||||||
bounce(w, &vec2.c, 'y');
|
mv_axis_border_bounce(w, &vec2.c, 'y');
|
||||||
try out.print("{s}", .{buffer});
|
try out.print("{s}", .{buffer});
|
||||||
sleep(30000000);
|
sleep(30000000);
|
||||||
//_ = try stdin.readUntilDelimiterOrEof(&buf, '\n');
|
//_ = try stdin.readUntilDelimiterOrEof(&buf, '\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn bounce(w: Winsize, point: *Point, axis: u8) void {
|
fn mv_axis_border_bounce(w: Winsize, point: *Point, axis: u8) void {
|
||||||
var cor = &point.x;
|
var cor = &point.x;
|
||||||
var dir = &point.direction.x;
|
var dir = &point.direction.x;
|
||||||
var upper = w.ws_col;
|
var upper = w.ws_col;
|
||||||
|
Loading…
Reference in New Issue
Block a user