bonus_00_checker_gradient.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <cstdio>
  2. #include <cerrno>
  3. #include "simple/graphical/initializer.h"
  4. #include "simple/graphical/algorithm/fill.h"
  5. #include "simple/support/misc.hpp"
  6. #include "common.h"
  7. using namespace simple::graphical;
  8. using namespace color_literals;
  9. using simple::support::ston;
  10. int main(int argc, char const* argv[]) try
  11. {
  12. switch(argc)
  13. {
  14. case 0: std::puts("Command not specified??");
  15. case 1: std::puts("Tile width not specified.");
  16. case 2: std::puts("Tile height not specified.");
  17. case 3: std::puts("Columns not specified");
  18. case 4: std::puts("Rows not specified");
  19. case 5: std::puts("Destination not specified");
  20. return -1;
  21. }
  22. int2 tile_size { ston<int>(argv[1]), ston<int>(argv[2]) };
  23. int2 board_dimensions { ston<int>(argv[3]), ston<int>(argv[4]) };
  24. initializer init;
  25. surface board (tile_size * board_dimensions, pixel_format(pixel_format::type::rgb24));
  26. const auto start = rgb_vector::red() + rgb_vector::green();
  27. const auto end = rgb_vector::blue();
  28. checker_up(board, tile_size, [start, end](const surface& s, rect r)
  29. {
  30. auto end_ratio = rgb_vector(r.position.mix<0,1,1>(1)) / rgb_vector(s.size().mix<0,1,1>());
  31. auto start_ratio = rgb_vector::white() - end_ratio;
  32. class color c(s.format(), rgb_pixel(start * start_ratio + end * end_ratio ));
  33. fill(s, c, r);
  34. r.position -= r.size * int2::i(); // a bit of a hack
  35. class color c2(s.format(), rgb_pixel(start * end_ratio + end * start_ratio ));
  36. fill(s, c2, r);
  37. });
  38. board.save(argv[5]);
  39. return 0;
  40. }
  41. catch(...)
  42. {
  43. if(errno)
  44. std::perror("ERROR");
  45. const char* sdl_error = SDL_GetError();
  46. if(*sdl_error)
  47. std::puts(sdl_error);
  48. throw;
  49. }