about summary refs log tree commit diff
diff options
context:
space:
mode:
authoriurii plugatarov <[email protected]>2024-08-04 13:25:24 +0200
committeriurii plugatarov <[email protected]>2024-08-04 13:25:24 +0200
commit0b93bb6376e71b5edd336e179de04f0278322a80 (patch)
tree002935a36d693d80f12d3f69744309360111a516
parent67e09cb56ed03efeaf0b7899b0de9844f46f9e92 (diff)
downloaddsazitty-main.tar.gz
some visualization main
-rw-r--r--build.zig3
-rw-r--r--src/c.zig4
-rw-r--r--src/main.zig45
3 files changed, 51 insertions, 1 deletions
diff --git a/build.zig b/build.zig
index ad5ad10..7bb8167 100644
--- a/build.zig
+++ b/build.zig
@@ -19,6 +19,9 @@ pub fn build(b: *std.Build) void {
         .optimize = optimize,
     });
 
+    exe.linkLibC();
+    exe.linkSystemLibrary("raylib");
+
     b.installArtifact(exe);
     const run_cmd = b.addRunArtifact(exe);
 
diff --git a/src/c.zig b/src/c.zig
new file mode 100644
index 0000000..1c6b062
--- /dev/null
+++ b/src/c.zig
@@ -0,0 +1,4 @@
+pub usingnamespace @cImport({
+    @cInclude("stdlib.h");
+    @cInclude("raylib.h");
+});
diff --git a/src/main.zig b/src/main.zig
index 13ab026..5a26b41 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -1,3 +1,46 @@
 const std = @import("std");
+const c = @import("c.zig");
 
-pub fn main() !void {}
+pub fn main() !void {
+    const width = 800;
+    const height = 600;
+    c.InitWindow(width, height, "dsa viz");
+    c.SetTargetFPS(60);
+
+    const original: [6]i32 = .{ 10, 3, 4, 1, 50, 30 };
+    var input_array: [6]i32 = original;
+    var i: usize = 0;
+    var j: usize = 0;
+
+    while (!c.WindowShouldClose()) {
+        c.ClearBackground(c.BLACK);
+
+        c.BeginDrawing();
+        var x_pos: i32 = width / 2;
+        for (input_array) |e| {
+            c.DrawRectangle(x_pos, height - (height / 2) - (e * 5), 20, e * 5, c.RED);
+            x_pos += 30;
+        }
+
+        if (j < input_array.len - 1 - i) {
+            if (input_array[j] > input_array[j + 1]) {
+                const temp = input_array[j];
+                input_array[j] = input_array[j + 1];
+                input_array[j + 1] = temp;
+            }
+            j += 1;
+        } else {
+            i += 1;
+            j = 0;
+
+            if (i >= input_array.len - 1) {
+                input_array = original;
+                i = 0;
+                j = 0;
+            }
+        }
+        c.WaitTime(0.5);
+
+        c.EndDrawing();
+    }
+}