Skip to content

FileImage Sample

Kasugaccho edited this page May 2, 2019 · 1 revision
#include <DTL.hpp>
#include <Dungeon/ImageWrite.hpp>
#include <cstdint>
#include <array>

int main() {

	using shape_t = std::uint_fast8_t;
	std::array<std::array<shape_t, 256>, 256> matrix{ {} };

	dtl::CellularAutomatonMixIsland<shape_t>(200, 0, 1, 2, 3, 4).draw(matrix);

	dtl::storage::FilePNG<shape_t>("sample.png").write(matrix, [](const shape_t value, unsigned char* const color) {

		const unsigned char a{ static_cast<unsigned char>(dtl::random::mt32bit.get<unsigned char>(20) - 10) };
		const unsigned char b{ static_cast<unsigned char>(dtl::random::mt32bit.get<unsigned char>(20) - 10) };
		const unsigned char c{ static_cast<unsigned char>(dtl::random::mt32bit.get<unsigned char>(20) - 10) };

		switch (value) {
		case 0:
			color[0] = static_cast<unsigned char>(41 + a);
			color[1] = static_cast<unsigned char>(40 + b);
			color[2] = static_cast<unsigned char>(159 + c);
			break;
		case 1:
			color[0] = static_cast<unsigned char>(101 + a);
			color[1] = static_cast<unsigned char>(163 + b);
			color[2] = static_cast<unsigned char>(56 + c);
			break;
		case 2:
			color[0] = static_cast<unsigned char>(223 + a);
			color[1] = static_cast<unsigned char>(203 + b);
			color[2] = static_cast<unsigned char>(140 + c);
			break;
		case 3:
			color[0] = static_cast<unsigned char>(9);
			color[1] = static_cast<unsigned char>(100 + b);
			color[2] = static_cast<unsigned char>(5);
			break;
		case 4:
			color[0] = static_cast<unsigned char>(164 + a);
			color[1] = static_cast<unsigned char>(143 + b);
			color[2] = static_cast<unsigned char>(50 + c);
			break;
		}
		});

	return 0;
}
Clone this wiki locally