diff --git a/src/main.zig b/src/main.zig index 57238e8..ef33989 100644 --- a/src/main.zig +++ b/src/main.zig @@ -2,35 +2,21 @@ const std = @import("std"); const rl = @import("raylib"); const rg = @import("raygui"); const pr = @import("primitives.zig"); +const plot = @import("plot.zig"); + const allocator = std.heap.page_allocator; - -var prng = std.rand.DefaultPrng.init(124346556); - +var prng = std.rand.DefaultPrng.init(124346234556); const rand = prng.random(); +const screenWidth = 1200; +const screenHeight = 800; + fn randMinMaxFloat(min: f32, max: f32) f32 { var r1 = rand.float(f32); r1 = 2 * (r1 - 0.5); //-0.5..0.5 return (@abs(min) + @abs(max)) / 2 * r1; } -test "random" { - var seed: u64 = undefined; - var r1: f32 = undefined; - try std.posix.getrandom(std.mem.asBytes(&seed)); - - prng = std.rand.DefaultPrng.init(seed); - while (true) { - r1 = randMinMaxFloat(-10, 10); - //std.debug.print("randMinMaxFloat:{}\n",.{r1}); - if (r1 > 8 or r1 < -8) { - std.debug.print("Greater:{}\n", .{r1}); - } - } -} -const screenWidth = 1200; -const screenHeight = 800; - const Particle = struct { const Self = @This(); position: pr.Vec = .{ .a = .{ .x = 0, .y = 0, .z = 0 } }, @@ -193,6 +179,12 @@ pub fn main() anyerror!void { rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second + const file = try plot.open("plot.dat"); + try plot.log(file,"test\ntest2\n"); + + var plotStr : []u8 = undefined; + var plotStrBuf : [128]u8 = undefined; + while (!rl.windowShouldClose()) { // Detect window close button or ESC key rl.beginDrawing(); defer rl.endDrawing(); @@ -211,11 +203,17 @@ pub fn main() anyerror!void { if (rl.isMouseButtonDown(rl.MouseButton.mouse_button_left)) { emitter.emit(@as(u32, @intFromFloat(value)), value2, value3); } - + rl.beginBlendMode(rl.BlendMode.blend_additive); - emitter.update(texture); + rl.endBlendMode(); + + plotStr = try std.fmt.bufPrint(&plotStrBuf,"{}, {}, {}\n",.{emitter.particles[0].acceleration.a.x,emitter.particles[0].position.a.x,emitter.particles[0].velocity.a.x}); + try plot.log(file,plotStr); + + emitter.update(texture); } + plot.close(file); } test "simple test" { @@ -224,3 +222,18 @@ test "simple test" { try list.append(42); try std.testing.expectEqual(@as(i32, 42), list.pop()); } + +test "random" { + var seed: u64 = undefined; + var r1: f32 = undefined; + try std.posix.getrandom(std.mem.asBytes(&seed)); + + prng = std.rand.DefaultPrng.init(seed); + while (true) { + r1 = randMinMaxFloat(-10, 10); + //std.debug.print("randMinMaxFloat:{}\n",.{r1}); + if (r1 > 8 or r1 < -8) { + std.debug.print("Greater:{}\n", .{r1}); + } + } +} diff --git a/src/plot.zig b/src/plot.zig new file mode 100644 index 0000000..894405e --- /dev/null +++ b/src/plot.zig @@ -0,0 +1,16 @@ +const std = @import("std"); + +pub fn log(self : std.fs.File,data : []const u8) !void +{ + try self.writeAll(data); +} + +pub fn open(file : []const u8) !std.fs.File +{ + const fileh = try std.fs.cwd().createFile(file,.{.read = true}); + return fileh; +} +pub fn close(file : std.fs.File) void +{ + file.close(); +} diff --git a/zig-out/bin/raylib-test b/zig-out/bin/raylib-test index 9a4581a..8759ba8 100755 Binary files a/zig-out/bin/raylib-test and b/zig-out/bin/raylib-test differ