diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3389c86 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.zig-cache/ +zig-out/ diff --git a/src/main.zig b/src/main.zig index 89cd135..c1c8dba 100644 --- a/src/main.zig +++ b/src/main.zig @@ -7,7 +7,6 @@ const SCREENHEIGHT = 1080; const SCALE = 50; pub fn main() !void { - // std.debug.print("{d}\n", .{SCREENWIDTH / 2}); var gpa = std.heap.GeneralPurposeAllocator(.{}){}; defer _ = gpa.deinit(); const allocator = gpa.allocator(); @@ -19,19 +18,17 @@ pub fn main() !void { rl.setTargetFPS(60); rl.beginDrawing(); - rl.clearBackground(rl.Color.white); + rl.clearBackground(rl.Color.light_gray); plotGraph(); drawAxis(); try markAxis(allocator); + calculateArea(); rl.endDrawing(); while (!rl.windowShouldClose()) { rl.beginDrawing(); - // DEBUG - // const pos = rl.getMousePosition(); - // std.debug.print("x: {d} y:{}\n", .{ pos.x, pos.y }); rl.endDrawing(); } } @@ -50,7 +47,7 @@ fn markAxis(allocator: std.mem.Allocator) !void { const font_size = 20; const start_x = SCREENWIDTH / 2; const start_y = SCREENHEIGHT / 2; - const radius = SCALE / 15; + const radius = 50 / 15; var buf: [20]u8 = undefined; var cnt: usize = 0; @@ -131,7 +128,7 @@ fn plotGraph() void { // f(x) fn getY(x: f32) !f32 { - return math.calculate(x, -3, .Power); + return try math.calculate(x, 2, .Power) / -2 + 6; } fn adjustForGridSystem(input_vector: rl.Vector2) rl.Vector2 { @@ -144,3 +141,7 @@ fn adjustForGridSystem(input_vector: rl.Vector2) rl.Vector2 { return new_vector; } + +fn calculateArea() void { + rl.drawText("Test", SCREENWIDTH - 75, 25, 20, rl.Color.red); +} diff --git a/src/math.zig b/src/math.zig index 25825f5..99c75a8 100644 --- a/src/math.zig +++ b/src/math.zig @@ -15,11 +15,10 @@ pub fn calculate(first: f32, second: f32, op: MathOperation) !f32 { return first / second; }, .Power => { - if (first == 0) std.debug.print("KOK", .{}); if (first == 0 and second < 0) { return error.InvalidParam; } - return pow(first, @intFromFloat(second)); + return std.math.pow(f32, first, second); }, .Root => { if (first < 0 or second < 0) { @@ -37,23 +36,3 @@ fn abs(a: f32) f32 { return a; } - -fn pow(a: f32, b: i32) f32 { - var res: f32 = 1.0; - var n: usize = undefined; - var f: f32 = undefined; - - if (b < 0) { - f = 1 / a; - n = @intCast(-b); - } else { - f = a; - n = @intCast(b); - } - - for (0..n) |_| { - res *= f; - } - - return res; -}