forked from baderouaich/BitmapPlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchess_board.cpp
36 lines (32 loc) · 1.04 KB
/
chess_board.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <filesystem>
#include "BitmapPlusPlus.hpp"
int main() {
try {
// 8x8 chess board
bmp::Bitmap image(640, 640);
const std::size_t board_dims = 8;
const std::int32_t rect_w = image.width() / board_dims;
const std::int32_t rect_h = image.height() / board_dims;
// Iterate over rects
bool is_white = true;
for (std::size_t x = 0; x < image.width(); x += rect_w) {
for (std::size_t y = 0; y < image.height(); y += rect_h) {
const bmp::Pixel color = is_white ? bmp::White : bmp::Black;
// Fill rect
image.fill_rect(x, y, rect_w, rect_h, color);
// Next rect in will be the opposite color
is_white = !is_white;
}
is_white = !is_white;
}
// Save bitmap to file
const auto p1 = std::filesystem::path(BIN_DIR) / "bernoulli.bmp";
const auto s1 = p1.string();
image.save(s1.c_str());
return EXIT_SUCCESS;
} catch (const bmp::Exception &e) {
std::cerr << "[BMP ERROR]: " << e.what() << '\n';
return EXIT_FAILURE;
}
}