From 556fea05affe6fe8866557d42b6c1ef6559d7880 Mon Sep 17 00:00:00 2001 From: Martin Michalec Date: Sat, 7 Nov 2026 06:20:46 +0300 Subject: publish --- src/distribution-test.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/distribution-test.c (limited to 'src/distribution-test.c') 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 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include + +#include "distribution.h" + +int +main (void) +{ + const int screen_padding = 10; + const int notation_height = 20; + + int screen_width = 800; + int screen_height = 450; + + SetConfigFlags (FLAG_MSAA_4X_HINT | + FLAG_WINDOW_RESIZABLE | + FLAG_VSYNC_HINT | + FLAG_WINDOW_UNDECORATED); + InitWindow (screen_width, screen_height, "graph"); + SetTargetFPS (60); + + srand (time (NULL)); + struct distribution dist; + // distribution_init (&dist, 20, 20, 1, 10); + distribution_init (&dist, 11, 20, 1, 10); + + int arr[dist.n - 1]; + memset (arr, 0, sizeof (arr)); + int iterrations = 10000; + for (int i = 0; i < iterrations; ++i) + arr[distribution_rand (&dist)] += 1; + + while (!WindowShouldClose ()) { + BeginDrawing (); + ClearBackground (WHITE); + + screen_width = GetScreenWidth (); + screen_height = GetScreenHeight (); + + const int rect_width = (screen_width - screen_padding)/(dist.n - 1) - screen_padding; + const int rect_max_height = screen_height - 2*screen_padding - notation_height; + for (int i = 0; i < dist.n - 1; ++i) { + const int rect_height = rect_max_height*arr[i]/iterrations; + DrawRectangle ((i + 1)*screen_padding + i*rect_width, + screen_padding + rect_max_height - rect_height, + rect_width, rect_height, BLACK); + + char *perc; + asprintf (&perc, "%2d%%", arr[i]*100/iterrations); + DrawText (perc, (i + 1)*screen_padding + i*rect_width + rect_width/4, screen_height - screen_padding - 3*notation_height/4, notation_height, BLACK); + } + + EndDrawing (); + } + + CloseWindow (); + + return EXIT_SUCCESS; +} -- cgit v1.3.1