-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
54 lines (40 loc) · 1.29 KB
/
Copy pathmain.cpp
File metadata and controls
54 lines (40 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
#include "clustering.hpp"
#include "matrix.hpp"
#include "raylib.h"
#include "raymath.h"
#include <iostream>
#define WIDTH 1280
#define HEIGHT 900
#define POINT_RADIUS 15
Vector2 matrix_to_raylib_Vector2(const mat::Matrix<double> &mat) {
Vector2 result;
result.x = mat.items[0] * 70 + WIDTH / 2;
result.y = HEIGHT / 2 - mat.items[1] * 70;
return result;
}
int main() {
InitWindow(WIDTH, HEIGHT, "Hello Raylib!");
mat::Matrix<double> data = {{1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, {3, 3},
{4, 4}, {3, 4}, {1, 7}, {2, 6}, {2, 7}};
std::vector<Vector2> centroids;
mat::Matrix<double> centers = clus::kmeans(data, 2, 100000000);
std::cout << centers;
for (auto centroid : centers.row_view()) {
centroids.push_back(matrix_to_raylib_Vector2(centroid));
}
while (!WindowShouldClose()) {
ClearBackground(WHITE);
std::vector<Vector2> points;
for (auto point : data.row_view()) {
points.push_back(matrix_to_raylib_Vector2(point));
}
BeginDrawing();
for (auto point : points) {
DrawCircleV(point, POINT_RADIUS, BLACK);
}
for (auto center : centroids) {
DrawCircleV(center, POINT_RADIUS, RED);
}
EndDrawing();
}
}