-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguitest.c
87 lines (73 loc) · 2.26 KB
/
guitest.c
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#define RAYGUI_IMPLEMENTATION
#include "include/raylib.h"
#include "include/raygui.h"
#include <time.h>
int main(void)
{
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
int currentScreen = 0;
int histogram[10];
int i, j, temp;
bool sorted = false;
for (i = 0; i < 10; i++)
{
histogram[i] = GetRandomValue(10, 200);
}
SetTargetFPS(5); // Lower the FPS to slow down the animations
while (!WindowShouldClose())
{
BeginDrawing();
ClearBackground(GRAY);
if (currentScreen == 0)
{
if (GuiButton((Rectangle){ 320, 200, 150, 50 }, "Go to next screen"))
{
currentScreen = 1;
for (i = 0; i < 10; i++)
{
histogram[i] = GetRandomValue(10, 200);
}
}
if (GuiButton((Rectangle){ 320, 260, 150, 50 }, "Exit")) CloseWindow();
}
else if (currentScreen == 1)
{
if (GuiButton((Rectangle){ 320, 200, 150, 50 }, "Go to previous screen")) currentScreen = 0;
if (!sorted)
{
for (i = 0; i < 10; i++)
{
for (j = 0; j < 10 - i - 1; j++)
{
if (histogram[j] > histogram[j + 1])
{
temp = histogram[j];
histogram[j] = histogram[j + 1];
histogram[j + 1] = temp;
sorted = true;
break;
}
}
if (sorted) break;
}
}
for (j = 0; j < 10; j++)
{
if (sorted && j == i)
{
DrawRectangle(70 + 70 * j, 450 - histogram[j], 50, histogram[j], RED);
}
else
{
DrawRectangle(70 + 70 * j, 450 - histogram[j], 50, histogram[j], DARKGRAY);
}
}
if (sorted) sorted = false;
}
EndDrawing();
}
CloseWindow();
return 0;
}