feat: improve UX
- invalid iteration counts are met with a usage error - pressing 'h' will print out an (incomplete) help menu - information about the current best point and iteration count is shown
This commit is contained in:
parent
fe62617beb
commit
1b2ff590ec
25
src/main.cpp
25
src/main.cpp
@ -1,4 +1,4 @@
|
|||||||
#include "screen.hpp"
|
#include <screen.hpp>
|
||||||
#include "vec.hpp"
|
#include "vec.hpp"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
@ -16,7 +16,13 @@ int
|
|||||||
main(int argc, char **argv) {
|
main(int argc, char **argv) {
|
||||||
int iter_count;
|
int iter_count;
|
||||||
if(argc < 2) iter_count = 100;
|
if(argc < 2) iter_count = 100;
|
||||||
else sscanf(argv[1], "%d", &iter_count);
|
else {
|
||||||
|
int scanned = sscanf(argv[1], "%d", &iter_count);
|
||||||
|
if(!scanned) {
|
||||||
|
printf("Usage: %s <iteration count>\n", argv[0]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Swarm<2> swarm(f, iter_count);
|
Swarm<2> swarm(f, iter_count);
|
||||||
Screen scr(80, 24);
|
Screen scr(80, 24);
|
||||||
@ -63,6 +69,10 @@ main(int argc, char **argv) {
|
|||||||
|
|
||||||
auto update_and_draw = [&]() -> void {
|
auto update_and_draw = [&]() -> void {
|
||||||
scr.draw();
|
scr.draw();
|
||||||
|
auto [y, x] = swarm.best();
|
||||||
|
printf("\033[30;40m\33[2K\r\033[48;2;%d;%d;%dm"
|
||||||
|
"Current best: (%f, %f) = %f\n",
|
||||||
|
255, 255, 255, x.x, x.y, y);
|
||||||
};
|
};
|
||||||
|
|
||||||
// We draw to the screen at a rate of `kFPS', but step()ing the swarm at
|
// We draw to the screen at a rate of `kFPS', but step()ing the swarm at
|
||||||
@ -85,6 +95,7 @@ main(int argc, char **argv) {
|
|||||||
swarm.step();
|
swarm.step();
|
||||||
|
|
||||||
++i;
|
++i;
|
||||||
|
printf("Current iteration: %d\nCurrent frame: %d\n", i * 4 / kFPS, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(frame_step) {
|
if(frame_step) {
|
||||||
@ -155,9 +166,11 @@ main(int argc, char **argv) {
|
|||||||
update_and_draw();
|
update_and_draw();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'p':
|
case 'h':
|
||||||
auto [y, x] = swarm.best();
|
printf(" movement zoom coloring pause step \n"
|
||||||
printf("Current best: f(%.10f, %.10f) = %.10f", x.x, x.y, y);
|
" W i I K SPC . \n"
|
||||||
|
" ASD o O L \n"
|
||||||
|
" quit: q \n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +184,7 @@ cleanup:
|
|||||||
enter_canonical_mode();
|
enter_canonical_mode();
|
||||||
|
|
||||||
auto [y, x] = swarm.best();
|
auto [y, x] = swarm.best();
|
||||||
printf("Best: f(" V2_FMT ") = %.3f", V2_ARG(x), y);
|
printf("Minimum found:\n f(%f, %f) = %f\n", x.x, x.y, y);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user