diff options
author | Adrian Kummerlaender | 2016-12-11 17:38:50 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2016-12-11 17:38:50 +0100 |
commit | 0263d6fa06efb78912fc51441162c230dd2003ce (patch) | |
tree | ad5b978cce0a681283816a9d20fcd0178e15af0a | |
parent | d139217ed53516bfcb71de171bf209706f5c842a (diff) | |
download | termlife-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.cc | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -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())); |