Skip to content

Commit 2c295b6

Browse files
committed
added chess board example
1 parent 5604b91 commit 2c295b6

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

examples/chess_board.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <iostream>
2+
#include "BitmapPlusPlus.hpp"
3+
4+
int main()
5+
{
6+
try
7+
{
8+
// 8x8 chess board
9+
bmp::Bitmap image(640, 640);
10+
const std::size_t board_dims = 8;
11+
const std::size_t rect_w = image.width() / board_dims;
12+
const std::size_t rect_h = image.height() / board_dims;
13+
14+
// Iterate over rects
15+
bool is_white = true;
16+
for (std::size_t x = 0; x < image.width(); x += rect_w)
17+
{
18+
for (std::size_t y = 0; y < image.height(); y += rect_h)
19+
{
20+
bmp::Pixel color = is_white ? bmp::White : bmp::Black;
21+
// Fill rect
22+
for (size_t dx = x; dx < x + rect_w; dx++)
23+
{
24+
for (size_t dy = y; dy < y + rect_h; dy++)
25+
{
26+
image.set(dx, dy, color);
27+
}
28+
}
29+
is_white = !is_white;
30+
}
31+
is_white = !is_white;
32+
}
33+
34+
// Save bitmap to file
35+
image.save("chess_board.bmp");
36+
37+
return EXIT_SUCCESS;
38+
}
39+
catch (const bmp::Exception &e)
40+
{
41+
std::cerr << "[BMP ERROR]: " << e.what() << '\n';
42+
return EXIT_FAILURE;
43+
}
44+
}

0 commit comments

Comments
 (0)