06_make_checkerboard.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <cstdio>
  2. #include <cerrno>
  3. #include <array>
  4. #include "simple/graphical/initializer.h"
  5. #include "simple/graphical/algorithm/fill.h"
  6. #include "simple/support/misc.hpp"
  7. #include "common.h"
  8. using namespace simple::graphical;
  9. using namespace simple::support::literals;
  10. using simple::support::ston;
  11. enum ColorIndex
  12. {
  13. Black,
  14. White
  15. };
  16. constexpr auto colors = std::array
  17. {
  18. rgba_pixel::white(0_u8),
  19. rgba_pixel::white(255_u8)
  20. };
  21. int main(int argc, char const* argv[]) try
  22. {
  23. switch(argc)
  24. {
  25. case 0: std::puts("Command not specified??");
  26. case 1: std::puts("Tile width not specified.");
  27. case 2: std::puts("Tile height not specified.");
  28. case 3: std::puts("Columns not specified");
  29. case 4: std::puts("Rows not specified");
  30. case 5: std::puts("Destination not specified");
  31. return -1;
  32. }
  33. int2 tile_size { ston<int>(argv[1]), ston<int>(argv[2]) };
  34. int2 board_dimensions { ston<int>(argv[3]), ston<int>(argv[4]) };
  35. initializer init;
  36. surface board (tile_size * board_dimensions, pixel_format(pixel_format::type::index8));
  37. auto palette = board.format().palette();
  38. if(palette)
  39. palette->set_colors(colors);
  40. fill(board, color(White));
  41. checker_up(board, tile_size, color(Black));
  42. board.save(argv[5]);
  43. return 0;
  44. }
  45. catch(...)
  46. {
  47. if(errno)
  48. std::perror("ERROR");
  49. const char* sdl_error = SDL_GetError();
  50. if(*sdl_error)
  51. std::puts(sdl_error);
  52. throw;
  53. }