aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2024-07-26 21:03:56 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2024-07-26 21:03:56 +0100
commitedc038313286f631c05dfc6ef5dbf8b71e1ba7ee (patch)
tree0fc389fa865a9c2a0f769245fddc506b6864efca /src
parenta614626b21849eed9c5f1580388fb31402f4bc31 (diff)
downloadcw_tree-edc038313286f631c05dfc6ef5dbf8b71e1ba7ee.tar.gz
cw_tree-edc038313286f631c05dfc6ef5dbf8b71e1ba7ee.tar.bz2
cw_tree-edc038313286f631c05dfc6ef5dbf8b71e1ba7ee.zip
Added counter to draw loop to show the amount of nodes computed
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 91610db..6f81d5b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -111,6 +111,13 @@ int main(void)
Fraction best_frac{1, 2};
word_t root = allocator.alloc({best_frac});
to_iterate.push(root);
+
+ word_t count = 1;
+ word_t prev_count = 0;
+ std::stringstream count_format;
+ std::string count_str;
+ word_t count_str_width = 0;
+
InitWindow(WIDTH, HEIGHT, "Calkin-Wilf Trees");
while (!WindowShouldClose())
{
@@ -119,9 +126,20 @@ int main(void)
iterate(to_iterate, allocator);
count += 2;
}
+ if (prev_count != count)
+ {
+ prev_count = count;
+ count_format << "Count=" << count;
+ count_str = count_format.str();
+ count_format.str("");
+ count_str_width = MeasureText(count_str.c_str(), FONT_SIZE * 2);
+ }
+
ClearBackground(BLACK);
BeginDrawing();
draw_number_line(allocator);
+ DrawText(count_str.c_str(), WIDTH / 2 - count_str_width / 2,
+ LINE_TOP - HEIGHT / 8, FONT_SIZE * 2, WHITE);
EndDrawing();
}
CloseWindow();