diff options
author | Sven Gothel <[email protected]> | 2022-10-20 17:32:30 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2022-10-20 17:32:30 +0200 |
commit | 256840aa58bd7a00aa0039101af4f57d0747f30b (patch) | |
tree | 11bc658adb4605128acab887a055d987cb59f37a | |
parent | 5b79eac142d70d8a191c411fa2b810564adbfcad (diff) |
Lesson 01: Complete task setup
-rw-r--r-- | src/lesson01.cpp | 171 |
1 files changed, 160 insertions, 11 deletions
diff --git a/src/lesson01.cpp b/src/lesson01.cpp index 3315458..1e35335 100644 --- a/src/lesson01.cpp +++ b/src/lesson01.cpp @@ -7,34 +7,183 @@ //============================================================================ #include <cstdio> +#include <cmath> +#include <string> /** * Lesson 01 * - * Applications of a C++ function + * Application of C++ functions rendering geometric Objects using ASCII-Art */ /** + * Pyramid w/ base_len == 4 + * XXXX + * XX + * * Pyramid w/ base_len == 5 - * X - * XXX * XXXXX + * XXX + * X + */ +void pyramid_down(const int base_len, const int dx=0, const bool show_title=true) { + if( show_title ) { + printf("\nPyramid(down, l %d, dx %d)\n", base_len, dx); + } +} + +/** + * Pyramid w/ base_len == 4 + * XX + * XXXX * * Pyramid w/ base_len == 5 + * X + * XXX + * XXXXX + */ +void pyramid_up(const int base_len, const int dx=0, const bool show_title=true) { + if( show_title ) { + printf("\nPyramid(up, l %d, dx %d)\n", base_len, dx); + } +} + +/** + * Salino w/ base_len == 4 * XX * XXXX + * XX * - * @param base_len + * Salino w/ base_len == 5 + * X + * XXX + * XXXXX + * XXX + * X + */ +void salino(const int base_len, const int dx=0, const bool show_title=true) { + if( show_title ) { + printf("\nSalino(l %d, dx %d)\n", base_len, dx); + } +} + +/** + * Disk rendering. + * + * Disk1(r 1.00, dx 4, sx 1.00) + ``` + XX + XX + ``` + * Disk1(r 2.00, dx 3, sx 1.00) + ``` + XX + XXXX + XXXX + XX + ``` + + * Disk1(r 3.00, dx 2, sx 1.00) + ``` + XXXX + XXXXXX + XXXXXX + XXXXXX + XXXXXX + XXXX + ``` + + * Disk1(r 3.00, dx 2, sx 2.00) + ``` + XXXXXXX + XXXXXXXXXXX + XXXXXXXXXXX + XXXXXXXXXXX + XXXXXXXXXXX + XXXXXXX + ``` */ -void pyramid(const int base_len) { - printf(" "); // space - printf("X"); // X - printf("\n"); // new line - (void) base_len; +void disk_1(const float radius, const int dx=0, const float sx=1.0, const bool show_title=true) { + if( show_title ) { + printf("\nDisk1(r %.2f, dx %d, sx %.2f)\n", radius, dx, sx); + } +} + +/** + * Antialiased (AA) disk rendering using ASCII-Art alike brightness characters. + * + * Disk2(r 1.00, dx 4, sx 1.00, aa_seam 1.00) + ``` + -- + -- + ``` + + * Disk2(r 2.00, dx 3, sx 1.00, aa_seam 1.00) + ``` + ++ + +##+ + +##+ + ++ + ``` + + * Disk2(r 3.00, dx 2, sx 1.00, aa_seam 1.00) + ``` + .++. + .####. + +####+ + +####+ + .####. + .++. + ``` + + * Disk2(r 3.00, dx 2, sx 2.00, aa_seam 1.00) + ``` + .-+++-. + .+#######+. + +#########+ + +#########+ + .+#######+. + .-+++-. + ``` + */ +void disk_2(const float radius, const int dx=0, const float sx=1.0, const float aa_seam_=1.0, const bool show_title=true) { + const float aa_seam = std::max<float>(1.0, aa_seam_); + if( show_title ) { + printf("\nDisk2(r %.2f, dx %d, sx %.2f, aa_seam %.2f)\n", radius, dx, sx, aa_seam); + } } int main(int argc, const char* argv[]) { - pyramid(4); - pyramid(5); + printf("\nPyramids base_len 4\n"); + pyramid_up(4); + pyramid_down(4); + salino(4); + + printf("\nPyramids base_len 5\n"); + pyramid_up(5); + pyramid_down(5); + salino(5); + + printf("\nDisks radius 1, scale-x 1\n"); + disk_1(1, 1); + disk_1(2, 1); + disk_2(1, 1); + + { + const int max_size = 5; + + printf("\nDisks radius [1..5], sx 1.0\n"); + for(int i=1; i<=max_size; ++i) { + disk_1(i, max_size-i, 1.0); + disk_2(i, max_size-i, 1.0); + } + + printf("\nDisks radius [1..5], sx 1.5\n"); + for(int i=1; i<=max_size; ++i) { + disk_1(i, max_size-i, 2); + disk_2(i, max_size-i, 2); + } + } + return 0; } |