-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.cpp
More file actions
63 lines (48 loc) · 1.29 KB
/
util.cpp
File metadata and controls
63 lines (48 loc) · 1.29 KB
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
#include <iostream>
#include <chrono>
#include "include/raylib-cpp.hpp"
#define SIZE 256
#define WIDTH 1280
#define HEIGHT 720
enum MODE {
SELECTION,
BUBBLE,
INSERTION
};
void switchMode(
int (&array)[SIZE],
int &n,
int ¤t,
int &lowest,
int &verified,
MODE &mode,
bool &paused,
MODE newMode
) {
std::random_shuffle(std::begin(array) + 1, std::end(array));
n = 0;
lowest = 0;
current = 0;
verified = 0;
mode = newMode;
paused = true;
}
void drawGraph(int (&array)[SIZE], int n, int lowest, int current, int verified, raylib::Window &window) {
BeginDrawing();
window.ClearBackground(BLACK);
for (int i = 0; i < SIZE; i++) {
Color color = RAYWHITE;
if (i == lowest || i == current) color = RED;
if (i == n || i < verified) color = GREEN;
int barHeight = (HEIGHT) * array[i] / SIZE;
int barWidth = WIDTH / SIZE;
int barPosX = (barWidth) * i + (WIDTH - barWidth * SIZE) / 2; // last two terms center the graph
int barPosY = HEIGHT - barHeight;
DrawRectangle(barPosX, barPosY, barWidth - 1, barHeight, color);
}
EndDrawing();
}
void verify(int (&array)[SIZE], int &verified) {
if (array[verified] == verified + 1)
verified++;
}