From 0b93bb6376e71b5edd336e179de04f0278322a80 Mon Sep 17 00:00:00 2001 From: iurii plugatarov Date: Sun, 4 Aug 2024 14:25:24 +0300 Subject: some visualization --- src/c.zig | 4 ++++ src/main.zig | 45 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/c.zig (limited to 'src') 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(); + } +} -- cgit 1.4.1-2-gfad0