blob: 5a26b41a197226b1cbf2e645e121cf2c800405ea (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
const std = @import("std");
const c = @import("c.zig");
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();
}
}
|