aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2016-12-11 17:38:50 +0100
committerAdrian Kummerlaender2016-12-11 17:38:50 +0100
commit0263d6fa06efb78912fc51441162c230dd2003ce (patch)
treead5b978cce0a681283816a9d20fcd0178e15af0a
parentd139217ed53516bfcb71de171bf209706f5c842a (diff)
downloadtermlife-0263d6fa06efb78912fc51441162c230dd2003ce.tar
termlife-0263d6fa06efb78912fc51441162c230dd2003ce.tar.gz
termlife-0263d6fa06efb78912fc51441162c230dd2003ce.tar.bz2
termlife-0263d6fa06efb78912fc51441162c230dd2003ce.tar.lz
termlife-0263d6fa06efb78912fc51441162c230dd2003ce.tar.xz
termlife-0263d6fa06efb78912fc51441162c230dd2003ce.tar.zst
termlife-0263d6fa06efb78912fc51441162c230dd2003ce.zip
Convert drawing logic to use `BoxTraverser`
-rw-r--r--life.cc18
1 files changed, 9 insertions, 9 deletions
diff --git a/life.cc b/life.cc
index 08a205a..ad69d56 100644
--- a/life.cc
+++ b/life.cc
@@ -12,19 +12,19 @@ void draw(
std::size_t y,
life::World<WIDTH, HEIGHT>& world
) {
+ life::util::BoxTraverser viewport(x, y, WIDTH, HEIGHT);
+
tb_clear();
- for ( std::size_t i = 0; i < HEIGHT; i++ ) {
- for ( std::size_t j = 0; j < WIDTH; j++ ) {
- const char density{std::to_string(world.lifeDensityAt(j,i))[0]};
+ viewport.for_each([&](std::size_t i, std::size_t j) {
+ const std::uint8_t density{world.lifeDensityAt(i-x, j-y)};
- if ( world.isLifeAt(j,i) ) {
- tb_change_cell(x+j, y+i, density, TB_BLACK, TB_GREEN);
- } else {
- tb_change_cell(x+j, y+i, density, TB_BLACK, TB_BLUE);
- }
+ if ( world.isLifeAt(i-x, j-y) ) {
+ tb_change_cell(i, j, 48+density, TB_BLACK, TB_GREEN);
+ } else {
+ tb_change_cell(i, j, 48+density, TB_BLACK, TB_BLUE);
}
- }
+ });
util::print_tb(1, 1, TB_WHITE, TB_DEFAULT, "Age:");
util::print_tb(6, 1, TB_WHITE, TB_DEFAULT, std::to_string(world.getAge()));