aboutsummaryrefslogtreecommitdiff
path: root/src/distribution-test.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/distribution-test.c')
-rw-r--r--src/distribution-test.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/distribution-test.c b/src/distribution-test.c
new file mode 100644
index 0000000..178bf73
--- /dev/null
+++ b/src/distribution-test.c
@@ -0,0 +1,63 @@
1#define _GNU_SOURCE
2#include <stdlib.h>
3#include <string.h>
4#include <stdio.h>
5#include <time.h>
6#include <raylib.h>
7
8#include "distribution.h"
9
10int
11main (void)
12{
13 const int screen_padding = 10;
14 const int notation_height = 20;
15
16 int screen_width = 800;
17 int screen_height = 450;
18
19 SetConfigFlags (FLAG_MSAA_4X_HINT |
20 FLAG_WINDOW_RESIZABLE |
21 FLAG_VSYNC_HINT |
22 FLAG_WINDOW_UNDECORATED);
23 InitWindow (screen_width, screen_height, "graph");
24 SetTargetFPS (60);
25
26 srand (time (NULL));
27 struct distribution dist;
28 // distribution_init (&dist, 20, 20, 1, 10);
29 distribution_init (&dist, 11, 20, 1, 10);
30
31 int arr[dist.n - 1];
32 memset (arr, 0, sizeof (arr));
33 int iterrations = 10000;
34 for (int i = 0; i < iterrations; ++i)
35 arr[distribution_rand (&dist)] += 1;
36
37 while (!WindowShouldClose ()) {
38 BeginDrawing ();
39 ClearBackground (WHITE);
40
41 screen_width = GetScreenWidth ();
42 screen_height = GetScreenHeight ();
43
44 const int rect_width = (screen_width - screen_padding)/(dist.n - 1) - screen_padding;
45 const int rect_max_height = screen_height - 2*screen_padding - notation_height;
46 for (int i = 0; i < dist.n - 1; ++i) {
47 const int rect_height = rect_max_height*arr[i]/iterrations;
48 DrawRectangle ((i + 1)*screen_padding + i*rect_width,
49 screen_padding + rect_max_height - rect_height,
50 rect_width, rect_height, BLACK);
51
52 char *perc;
53 asprintf (&perc, "%2d%%", arr[i]*100/iterrations);
54 DrawText (perc, (i + 1)*screen_padding + i*rect_width + rect_width/4, screen_height - screen_padding - 3*notation_height/4, notation_height, BLACK);
55 }
56
57 EndDrawing ();
58 }
59
60 CloseWindow ();
61
62 return EXIT_SUCCESS;
63}