aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2024-07-26 21:07:18 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2024-07-26 21:07:18 +0100
commit2ddf2d0b48d42dae93545e6c6c6540b672caba7b (patch)
treef518bf0c9314969190223ee893f9677c68c21cf1 /src
parentedc038313286f631c05dfc6ef5dbf8b71e1ba7ee (diff)
downloadcw_tree-2ddf2d0b48d42dae93545e6c6c6540b672caba7b.tar.gz
cw_tree-2ddf2d0b48d42dae93545e6c6c6540b672caba7b.tar.bz2
cw_tree-2ddf2d0b48d42dae93545e6c6c6540b672caba7b.zip
Clean up count drawing logic a bit, add iterations to the count text
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 6f81d5b..da7cca4 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -112,11 +112,10 @@ int main(void)
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;
+ word_t count = 1, prev_count = 0;
+ std::stringstream format_stream;
+ std::string format_str;
+ word_t format_str_width = 0;
InitWindow(WIDTH, HEIGHT, "Calkin-Wilf Trees");
while (!WindowShouldClose())
@@ -129,16 +128,17 @@ int main(void)
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);
+ format_stream << "Count=" << count << "\n\n";
+ format_stream << "Iterations=" << (count - 1) / 2;
+ format_str = format_stream.str();
+ format_stream.str("");
+ format_str_width = MeasureText(format_str.c_str(), FONT_SIZE * 2);
}
ClearBackground(BLACK);
BeginDrawing();
draw_number_line(allocator);
- DrawText(count_str.c_str(), WIDTH / 2 - count_str_width / 2,
+ DrawText(format_str.c_str(), WIDTH / 2 - format_str_width / 2,
LINE_TOP - HEIGHT / 8, FONT_SIZE * 2, WHITE);
EndDrawing();
}