/
SilovAndrey
/
easel_examples
Обзор
Документация
Войти
/
SilovAndrey
/
easel_examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
chessboard.cpp
69 строк
2 KB
Andrey HomePC
Add easel_examples v0.1.0 with shapes, space, paths examples
10 июл 2026, 10:34
10 июл 2026, 10:34
8ecc405
Код
Авторство
О чём код?
module; #include <cstdint> #include <functional> #include <memory> module App; inline bool is_little_endian() { static_assert(sizeof(char)!=sizeof(short), "Error: not usable on this machine"); short number = 0x1; char *p = reinterpret_cast<char*>(&number); return (p[0] == 1); } using namespace easel; int constexpr rows = 8; int constexpr cols = 8; int constexpr square_side = 60; int constexpr square_area = square_side * square_side; int constexpr width = cols * square_side; int constexpr height = rows * square_side; size_t constexpr pix_buf_size = rows * cols * square_area; uint32_t constexpr white = 0xffffffff; // on little endian systems RGBA is formatted as ABGR for values std::function<uint32_t()> black = []() { return is_little_endian() ? 0xff000000 : 0x000000ff; }; auto constexpr window_size = extent{ static_cast<float>(cols * square_side), static_cast<float>(rows * square_side) }; void draw(canvas& cnv) { // Create a chess board std::unique_ptr<uint32_t> pix_buf(new uint32_t[pix_buf_size]); for (int y = 0; y < rows; y++) { uint32_t* row_slice = &(pix_buf.get()[y * rows * square_area]); uint32_t color = black(); if (y % 2 != 0) color = white; for (int x = 0; x < cols * square_area; x++) { if (x % square_side == 0) { if (color == white) color = black(); else color = white; } row_slice[x] = color; } } auto img = make_image<pixel_format::rgba32>(pix_buf.get(), {window_size.x, window_size.y}); cnv.draw(img); print_elapsed(cnv, {0, 0}); } int start(int argc, char const* argv[]) { return run_app(argc, argv, window_size, colors::white, false); }