Skip to content

DxLib雑多なサンプル

Kasugaccho edited this page Jul 3, 2019 · 19 revisions

0.4.X

PerlinIsland

#include <DTL.hpp>
#include <DxLib.h>

namespace System {
	bool Update() noexcept { return (DxLib::ScreenFlip() != -1 && DxLib::ProcessMessage() != -1); }
}

void Main();

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
	DxLib::SetOutApplicationLogValidFlag(FALSE);
	DxLib::ChangeWindowMode(TRUE);
	DxLib::SetGraphMode(512, 512, 32);
	if (DxLib::DxLib_Init() == -1) return -1;
	DxLib::SetDrawScreen(DX_SCREEN_BACK);
	DxLib::SetMainWindowText("Sample");
	Main();
	return DxLib::DxLib_End();
}

constexpr std::size_t size_x{ 512 };
constexpr std::size_t size_y{ 512 };

constexpr int hachi{ 1 };
template<typename Matrix_, typename Matrix2_>
void output(const Matrix_& matrix_, const Matrix2_& elevation_) {
	float a{1}, b{1}, c{1};
	for (std::size_t y{}; y < size_y; ++y)
		for (std::size_t x{}; x < size_x; ++x) {
			a = ((elevation_[y][x] < 50) ? 1.1f : (elevation_[y][x] < 110) ? 0.9f : ((elevation_[y][x] < 140) ? 1.0f : 1.3f));
			b = ((elevation_[y][x] < 50) ? 1.1f : (elevation_[y][x] < 110) ? 0.9f : ((elevation_[y][x] < 140) ? 1.0f : 1.3f));
			c = ((elevation_[y][x] < 50) ? 1.1f : (elevation_[y][x] < 110) ? 0.9f : ((elevation_[y][x] < 140) ? 1.0f : 1.3f));
			switch (matrix_[y][x]) {
			case 0:
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi, GetColor(int(41 / a), int(40 / b), int(159 / c)), TRUE);
				break;
			case 1:
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi, GetColor(int(218 / a), int(217 / b), int(225 / c)), TRUE);
				break;
			case 2:
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi, GetColor(int(223 / a), int(203 / b), int(140 / c)), TRUE);
				break;
			case 3:
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi, GetColor(int(188 / a), int(205 / b), int(146 / c)), TRUE);
				break;
			case 4:
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi, GetColor(int(164 / a), int(143 / b), int(50 / c)), TRUE);
				break;
			case 5:
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi, GetColor(int(97 / a), int(154 / b), int(96 / c)), TRUE);
				break;
			case 6:
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi, GetColor(int(101 / a), int(163 / b), int(56 / c)), TRUE);
				break;
			case 7:
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi, GetColor(9, int(100 / b), 5), TRUE);
				break;
			case 8:
			case 9:
			case 10:
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi, GetColor(int(43 / a), int(84 / b), int(41 / c)), TRUE);
				break;
			}
		}
}

void Main() {

	using shape_t = std::uint_fast8_t;


	//温度
	std::unique_ptr<float[][size_x] > temperature(new(std::nothrow) float[size_y][size_x]);
	

	//降水量
	std::unique_ptr<std::int_fast16_t[][size_x] > amount_of_rainfall(new(std::nothrow) std::int_fast16_t[size_y][size_x]);
	

	std::unique_ptr<std::uint_fast8_t[][size_x] > elevation(new(std::nothrow) std::uint_fast8_t[size_y][size_x]);
	std::unique_ptr<shape_t[][size_x] > biome(new(std::nothrow) shape_t[size_y][size_x]);



	constexpr int update_fps{ 30 };
	int now_fps{ update_fps };
	while (System::Update()) {
		++now_fps;
		if (now_fps < update_fps) continue;
		now_fps = 0;

		dtl::shape::PerlinIsland<float>(6.0, 8, -20.0f, 60.0f).draw(temperature, size_x, size_y);
		dtl::shape::PerlinIsland<std::int_fast16_t>(6.0, 8, 0, 4500).draw(amount_of_rainfall, size_x, size_y);
		dtl::shape::PerlinIsland<std::uint_fast8_t>(6.0, 8, 200).draw(elevation, size_x, size_y);
		//dtl::shape::PerlinIsland<std::int_fast8_t>(6.0, 8, 0, 0).draw(elevation, size_x, size_y);

		for (std::size_t row{}; row < size_x; ++row)
			for (std::size_t col{}; col < size_y; ++col) {

				if (elevation[row][col] < 90) biome[row][col] = 0;

				//ツンドラ
				else if (temperature[row][col] < -5.0f) biome[row][col] = 1;
				//砂漠
				else if (amount_of_rainfall[row][col] < 500) biome[row][col] = 2;//(((temperature[row][col] + 5.0f) / 35.0f) * 500)
				else if (amount_of_rainfall[row][col] < 1500) {
					//ステップ
					if (temperature[row][col] < 20.0f) biome[row][col] = 3;
					//サバンナ
					else biome[row][col] = 4;
				}
				//針葉樹林
				else if (temperature[row][col] < 3.0f) biome[row][col] = 5;
				//夏緑樹林
				else if (temperature[row][col] < 12.0f) biome[row][col] = 6;
				//照葉樹林
				else if (temperature[row][col] < 20.0f) biome[row][col] = 7;
				//雨緑樹林
				else if (amount_of_rainfall[row][col] < 2500) biome[row][col] = 8;
				//亜熱帯多雨林
				else if (temperature[row][col] < 24.0f) biome[row][col] = 9;
				//熱帯多雨林
				else biome[row][col] = 10;
			}

		output(biome, elevation);
	}

}

pim

CellularAutomatonMixIsland

#include <DTL.hpp>
#include <DxLib.h>

namespace System {
	bool Update() noexcept { return (DxLib::ScreenFlip() != -1 && DxLib::ProcessMessage() != -1); }
}

void Main();

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
	DxLib::SetOutApplicationLogValidFlag(FALSE);
	DxLib::ChangeWindowMode(TRUE);
	DxLib::SetGraphMode(512, 512, 32);
	if (DxLib::DxLib_Init() == -1) return -1;
	DxLib::SetDrawScreen(DX_SCREEN_BACK);
	DxLib::SetMainWindowText("Sample");
	Main();
	return DxLib::DxLib_End();
}

constexpr int hachi{ 2 };
template<typename Matrix_>
void output(const Matrix_& matrix_) {
	int a{}, b{}, c{};
	for (std::size_t y{}; y < matrix_.size(); ++y)
		for (std::size_t x{}; x < matrix_[y].size(); ++x) {
			a = dtl::random::mt32bit.get<int>(20) - 10;
			b = dtl::random::mt32bit.get<int>(20) - 10;
			c = dtl::random::mt32bit.get<int>(20) - 10;
			switch (matrix_[y][x]) {
			case 0:
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi, GetColor(41 + a, 40 + b, 159 + c), TRUE);
				break;
			case 1:
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi, GetColor(101 + a, 163 + b, 56 + c), TRUE);
				break;
			case 2:
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi, GetColor(223 + a, 203 + b, 140 + c), TRUE);
				break;
			case 3:
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi, GetColor(9, 100 + b, 5), TRUE);
				break;
			case 4:
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi, GetColor(164 + a, 143 + b, 50 + c), TRUE);
				break;
			}
		}
}

void Main() {

	using shape_t = std::uint_fast8_t;
	constexpr std::size_t width{ 256 };
	constexpr std::size_t height{ 256 };
	std::array<std::array<shape_t, width>, height> matrix{ {} };

	constexpr int update_fps{ 30 };
	int now_fps{ update_fps };
	while (System::Update()) {
		++now_fps;
		if (now_fps < update_fps) continue;
		now_fps = 0;
		dtl::CellularAutomatonMixIsland<shape_t>(200, 0, 1, 2, 3, 4).draw(matrix);
		output(matrix);
	}

}

ri

#include <DTL.hpp>
#include <DxLib.h>

namespace System {
	bool Update() noexcept { return (DxLib::ScreenFlip() != -1 && DxLib::ProcessMessage() != -1); }
}

void Main();

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
	DxLib::SetOutApplicationLogValidFlag(FALSE);
	DxLib::ChangeWindowMode(TRUE);
	DxLib::SetGraphMode(512, 512, 32);
	if (DxLib::DxLib_Init() == -1) return -1;
	DxLib::SetDrawScreen(DX_SCREEN_BACK);
	DxLib::SetMainWindowText("Sample");
	Main();
	return DxLib::DxLib_End();
}

void Main() {

	using shape_t = std::uint_fast8_t;
	constexpr std::size_t width{ 256 };
	constexpr std::size_t height{ 256 };
	std::array<std::array<shape_t, width>, height> matrix{ {} };

	constexpr int length{ 2 };
	constexpr int update_fps{ 30 };
	int now_fps{ update_fps };
	while (System::Update()) {
		++now_fps;
		if (now_fps < update_fps) continue;
		now_fps = 0;
		dtl::CellularAutomatonMixIsland<shape_t>(200, 0, 1, 2, 3, 4).draw(matrix);

		dtl::OutputView<shape_t, int>(length).draw(matrix, [](const shape_t value_, const int x_, const int y_, const int w_, const int h_) {
			const int a{ dtl::random::mt32bit.get<int>(20) - 10 };
			const int b{ dtl::random::mt32bit.get<int>(20) - 10 };
			const int c{ dtl::random::mt32bit.get<int>(20) - 10 };
			unsigned int color{};
			switch (value_) {
			case 0:color = DxLib::GetColor(41 + a, 40 + b, 159 + c); break;
			case 1:color = DxLib::GetColor(101 + a, 163 + b, 56 + c); break;
			case 2:color = DxLib::GetColor(223 + a, 203 + b, 140 + c); break;
			case 3:color = DxLib::GetColor(9, 100 + b, 5); break;
			case 4:color = DxLib::GetColor(164 + a, 143 + b, 50 + c); break;
			}
			DxLib::DrawBox(x_ * w_, y_ * h_, x_ * w_ + w_, y_ * h_ + h_, color, TRUE);
			});
	}
}

ri

DiamondSquareAverageIsland

#include <DTL.hpp>
#include <DxLib.h>

namespace System {
	bool Update() noexcept { return (DxLib::ScreenFlip() != -1 && DxLib::ProcessMessage() != -1); }
}

void Main();

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
	DxLib::SetOutApplicationLogValidFlag(FALSE);
	DxLib::ChangeWindowMode(TRUE);
	DxLib::SetGraphMode(512, 512, 32);
	if (DxLib::DxLib_Init() == -1) return -1;
	DxLib::SetDrawScreen(DX_SCREEN_BACK);
	DxLib::SetMainWindowText("Sample");
	Main();
	return DxLib::DxLib_End();
}

constexpr int hachi{ 2 };
template<typename Matrix_>
void output(const Matrix_& matrix_) {

	constexpr int color_sub{ 1 };
	constexpr int deep_max_value{ 80 };
	constexpr int sea_max_value{ 120 };
	constexpr int sand_max_value{ 142 };
	constexpr int land_max_value{ 160 };

	int a{}, b{}, c{};
	for (std::size_t y{}; y < matrix_.size(); ++y)
		for (std::size_t x{}; x < matrix_[y].size(); ++x) {

			a = dtl::random::mt32bit.get<int>(10) - 5;
			b = dtl::random::mt32bit.get<int>(10) - 5;
			c = dtl::random::mt32bit.get<int>(10) - 5;

			if (matrix_[y][x] <= deep_max_value) {
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi,
					GetColor(30 + a, 88 + b, 126 + c), TRUE);
			}
			else if (matrix_[y][x] <= sea_max_value) {
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi,
					GetColor((30 + 135 * (matrix_[y][x] - deep_max_value) / (sea_max_value - deep_max_value)) / color_sub * color_sub + a,
					(88 + 133 * (matrix_[y][x] - deep_max_value) / (sea_max_value - deep_max_value)) / color_sub * color_sub,
						(126 + 84 * (matrix_[y][x] - deep_max_value) / (sea_max_value - deep_max_value)) / color_sub * color_sub + c), TRUE);
			}
			else if (matrix_[y][x] <= sand_max_value) {
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi,
					GetColor((244 - 20 * (matrix_[y][x] - sea_max_value) / (sand_max_value - sea_max_value)) / color_sub * color_sub + a,
					(236 - 27 * (matrix_[y][x] - sea_max_value) / (sand_max_value - sea_max_value)) / color_sub * color_sub + b,
						(215 - 25 * (matrix_[y][x] - sea_max_value) / (sand_max_value - sea_max_value)) / color_sub * color_sub + c), TRUE);
			}
			else if (matrix_[y][x] <= sand_max_value + 2) {
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi,
				GetColor(224 / 2 + 166 / 2 + a,
					209 / 2 + 193 / 2 + b,
					190 / 2 + 98 / 2 + c), TRUE);
			}
			else {
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi,
				GetColor((166 - 30 * (matrix_[y][x] - sand_max_value) / (land_max_value - sand_max_value)) / color_sub * color_sub,
					(193 + 12 * (matrix_[y][x] - sand_max_value) / (land_max_value - sand_max_value)) / color_sub * color_sub,
					(98 + 1 * (matrix_[y][x] - sand_max_value) / (land_max_value - sand_max_value)) / color_sub * color_sub), TRUE);
			}
		}
}

void Main() {

	using shape_t = std::uint_fast8_t;
	constexpr std::size_t width{ 257 };
	constexpr std::size_t height{ 257 };
	std::array<std::array<shape_t, width>, height> matrix{ {} };

	constexpr int update_fps{ 30 };
	int now_fps{ update_fps };
	while (System::Update()) {
		++now_fps;
		if (now_fps < update_fps) continue;
		now_fps = 0;
		dtl::shape::DiamondSquareAverageIsland<shape_t>(0, 165, 85).draw(matrix);
		//dtl::CellularAutomatonMixIsland<shape_t>(60, 0, 1, 2, 3, 4).draw(matrix);
		output(matrix);
	}

}

sdsai

潮の満ち引き(DiamondSquareAverageIsland)

#include <DTL.hpp>
#include <DxLib.h>

namespace System {
	bool Update() noexcept { return (DxLib::ScreenFlip() != -1 && DxLib::ProcessMessage() != -1); }
}

void Main();

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
	DxLib::SetOutApplicationLogValidFlag(FALSE);
	DxLib::ChangeWindowMode(TRUE);
	DxLib::SetGraphMode(512, 512, 32);
	if (DxLib::DxLib_Init() == -1) return -1;
	DxLib::SetDrawScreen(DX_SCREEN_BACK);
	DxLib::SetMainWindowText("Sample");
	Main();
	return DxLib::DxLib_End();
}

constexpr int hachi{ 2 };
template<typename Matrix_>
void output(const Matrix_& matrix_,const int add_) {

	constexpr int color_sub{ 1 };
	const int deep_max_value{ 80 + add_ };
	const int sea_max_value{ 120 + add_ };
	constexpr int sand_max_value{ 142 };
	constexpr int land_max_value{ 160 };

	int a{}, b{}, c{};
	for (std::size_t y{}; y < matrix_.size(); ++y)
		for (std::size_t x{}; x < matrix_[y].size(); ++x) {

			a = dtl::random::mt32bit.get<int>(10) - 5;
			b = dtl::random::mt32bit.get<int>(10) - 5;
			c = dtl::random::mt32bit.get<int>(10) - 5;

			if (matrix_[y][x] <= deep_max_value) {
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi,
					GetColor(30 + a, 88 + b, 126 + c), TRUE);
			}
			else if (matrix_[y][x] <= sea_max_value) {
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi,
					GetColor((30 + 135 * (matrix_[y][x] - deep_max_value) / (sea_max_value - deep_max_value)) / color_sub * color_sub + a,
					(88 + 133 * (matrix_[y][x] - deep_max_value) / (sea_max_value - deep_max_value)) / color_sub * color_sub,
						(126 + 84 * (matrix_[y][x] - deep_max_value) / (sea_max_value - deep_max_value)) / color_sub * color_sub + c), TRUE);
			}
			else if (matrix_[y][x] <= sand_max_value) {
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi,
					GetColor((244 - 20 * (matrix_[y][x] - sea_max_value) / (sand_max_value - sea_max_value)) / color_sub * color_sub + a,
					(236 - 27 * (matrix_[y][x] - sea_max_value) / (sand_max_value - sea_max_value)) / color_sub * color_sub + b,
						(215 - 25 * (matrix_[y][x] - sea_max_value) / (sand_max_value - sea_max_value)) / color_sub * color_sub + c), TRUE);
			}
			else if (matrix_[y][x] <= sand_max_value + 2) {
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi,
				GetColor(224 / 2 + 166 / 2 + a,
					209 / 2 + 193 / 2 + b,
					190 / 2 + 98 / 2 + c), TRUE);
			}
			else {
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi,
				GetColor((166 - 30 * (matrix_[y][x] - sand_max_value) / (land_max_value - sand_max_value)) / color_sub * color_sub,
					(193 + 12 * (matrix_[y][x] - sand_max_value) / (land_max_value - sand_max_value)) / color_sub * color_sub,
					(98 + 1 * (matrix_[y][x] - sand_max_value) / (land_max_value - sand_max_value)) / color_sub * color_sub), TRUE);
			}
		}
}

void Main() {

	using shape_t = std::uint_fast8_t;
	constexpr std::size_t width{ 257 };
	constexpr std::size_t height{ 257 };
	std::array<std::array<shape_t, width>, height> matrix{ {} };
	dtl::shape::DiamondSquareAverageIsland<shape_t>(0, 165, 85).draw(matrix);

	constexpr int update_water{ 24 };
	int now_water{ update_water };
	bool is_minus{ false };

	while (System::Update()) {
		++now_water;

		output(matrix, (now_water) / ((is_minus) ? -4 : 4));

		if (now_water < update_water) continue;
		now_water = 0;
		now_water = -update_water;
		is_minus = !is_minus;
	}

}

潮の満ち引き(FractalLoopIsland)

#include <DTL.hpp>
#include <DxLib.h>

namespace System {
	bool Update() noexcept { return (DxLib::ScreenFlip() != -1 && DxLib::ProcessMessage() != -1); }
}

void Main();

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
	DxLib::SetOutApplicationLogValidFlag(FALSE);
	DxLib::ChangeWindowMode(TRUE);
	DxLib::SetGraphMode(512, 512, 32);
	if (DxLib::DxLib_Init() == -1) return -1;
	DxLib::SetDrawScreen(DX_SCREEN_BACK);
	DxLib::SetMainWindowText("Sample");
	Main();
	return DxLib::DxLib_End();
}

constexpr int hachi{ 2 };
template<typename Matrix_>
void output(const Matrix_& matrix_, const int add_) {

	constexpr int color_sub{ 1 };
	const int deep_max_value{ 100 + add_ };
	const int sea_max_value{ 130 + add_ };
	constexpr int sand_max_value{ 152 };
	constexpr int land_max_value{ 230 };

	int a{}, b{}, c{};
	for (std::size_t y{}; y < matrix_.size(); ++y)
		for (std::size_t x{}; x < matrix_[y].size(); ++x) {

			a = dtl::random::mt32bit.get<int>(10) - 5;
			b = dtl::random::mt32bit.get<int>(10) - 5;
			c = dtl::random::mt32bit.get<int>(10) - 5;

			if (matrix_[y][x] <= deep_max_value) {
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi,
					GetColor(30 + a, 88 + b, 126 + c), TRUE);
			}
			else if (matrix_[y][x] <= sea_max_value) {
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi,
					GetColor((30 + 135 * (matrix_[y][x] - deep_max_value) / (sea_max_value - deep_max_value)) / color_sub * color_sub + a,
					(88 + 133 * (matrix_[y][x] - deep_max_value) / (sea_max_value - deep_max_value)) / color_sub * color_sub,
						(126 + 84 * (matrix_[y][x] - deep_max_value) / (sea_max_value - deep_max_value)) / color_sub * color_sub + c), TRUE);
			}
			else if (matrix_[y][x] <= sand_max_value) {
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi,
					GetColor((244 - 20 * (matrix_[y][x] - sea_max_value) / (sand_max_value - sea_max_value)) / color_sub * color_sub + a,
					(236 - 27 * (matrix_[y][x] - sea_max_value) / (sand_max_value - sea_max_value)) / color_sub * color_sub + b,
						(215 - 25 * (matrix_[y][x] - sea_max_value) / (sand_max_value - sea_max_value)) / color_sub * color_sub + c), TRUE);
			}
			else if (matrix_[y][x] <= sand_max_value + 2) {
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi,
					GetColor(224 / 2 + 166 / 2 + a,
						209 / 2 + 193 / 2 + b,
						190 / 2 + 98 / 2 + c), TRUE);
			}
			else {
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi,
					GetColor((166 - 30 * (matrix_[y][x] - sand_max_value) / (land_max_value - sand_max_value)) / color_sub * color_sub,
					(193 + 12 * (matrix_[y][x] - sand_max_value) / (land_max_value - sand_max_value)) / color_sub * color_sub,
						(98 + 1 * (matrix_[y][x] - sand_max_value) / (land_max_value - sand_max_value)) / color_sub * color_sub), TRUE);
			}
		}
}

void Main() {

	using shape_t = std::uint_fast8_t;
	constexpr std::size_t width{ 256 };
	constexpr std::size_t height{ 256 };
	std::array<std::array<shape_t, width>, height> matrix{ {} };
	dtl::shape::FractalLoopIsland<shape_t>(0, 165, 85).draw(matrix);

	constexpr int update_water{ 24 };
	int now_water{ update_water };
	bool is_minus{ false };

	while (System::Update()) {
		++now_water;

		output(matrix, (now_water) / ((is_minus) ? -4 : 4));

		if (now_water < update_water) continue;
		now_water = 0;
		now_water = -update_water;
		is_minus = !is_minus;
	}

}

FractalLoopIsland

#include <DTL.hpp>
#include <DxLib.h>

namespace System {
	bool Update() noexcept { return (DxLib::ScreenFlip() != -1 && DxLib::ProcessMessage() != -1); }
}

void Main();

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
	DxLib::SetOutApplicationLogValidFlag(FALSE);
	DxLib::ChangeWindowMode(TRUE);
	DxLib::SetGraphMode(512, 512, 32);
	if (DxLib::DxLib_Init() == -1) return -1;
	DxLib::SetDrawScreen(DX_SCREEN_BACK);
	DxLib::SetMainWindowText("Sample");
	Main();
	return DxLib::DxLib_End();
}

constexpr int hachi{ 2 };
template<typename Matrix_>
void output(const Matrix_& matrix_) {

	constexpr int color_sub{ 24 };
	const int deep_max_value{ 100 };
	const int sea_max_value{ 130 };
	constexpr int sand_max_value{ 152 };
	constexpr int land_max_value{ 230 };

	int a{}, b{}, c{};
	for (std::size_t y{}; y < matrix_.size(); ++y)
		for (std::size_t x{}; x < matrix_[y].size(); ++x) {

			a = dtl::random::mt32bit.get<int>(10) - 5;
			b = dtl::random::mt32bit.get<int>(10) - 5;
			c = dtl::random::mt32bit.get<int>(10) - 5;

			DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi,
				GetColor(0,
				(matrix_[y][x]) / color_sub * color_sub,
					(matrix_[y][x]) / color_sub * color_sub), TRUE);
		}
}

void Main() {

	using shape_t = std::uint_fast8_t;
	constexpr std::size_t width{ 256 };
	constexpr std::size_t height{ 256 };
	std::array<std::array<shape_t, width>, height> matrix{ {} };
	dtl::shape::FractalLoopIsland<shape_t> fil(0, 200, 50);
	fil.draw(matrix);

	constexpr int update_timer{ 30 };
	int now_timer{ update_timer };

	while (System::Update()) {
		if (now_timer >= update_timer) {
			now_timer = 0;
			fil.draw(matrix);
			output(matrix);
		}
		++now_timer;
	}

}

RandomVoronoi

#include <DTL.hpp>
#include <DxLib.h>

namespace System {
	bool Update() noexcept { return (DxLib::ScreenFlip() != -1 && DxLib::ProcessMessage() != -1); }
}

void Main();

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
	DxLib::SetOutApplicationLogValidFlag(FALSE);
	DxLib::ChangeWindowMode(TRUE);
	DxLib::SetGraphMode(512, 512, 32);
	if (DxLib::DxLib_Init() == -1) return -1;
	DxLib::SetDrawScreen(DX_SCREEN_BACK);
	DxLib::SetMainWindowText("Sample");
	Main();
	return DxLib::DxLib_End();
}

constexpr int hachi{ 2 };
template<typename Matrix_>
void output(const Matrix_& matrix_) {

	constexpr int color_sub{ 24 };
	const int deep_max_value{ 100 };
	const int sea_max_value{ 130 };
	constexpr int sand_max_value{ 152 };
	constexpr int land_max_value{ 230 };

	for (std::size_t y{}; y < matrix_.size(); ++y)
		for (std::size_t x{}; x < matrix_[y].size(); ++x) {
			DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi,
				(matrix_[y][x]) ? GetColor(255, 255, 255) : GetColor(0, 0, 0), TRUE);
		}
}

void Main() {

	using shape_t = std::uint_fast8_t;
	constexpr std::size_t width{ 256 };
	constexpr std::size_t height{ 256 };
	std::array<std::array<shape_t, width>, height> matrix{ {} };
	dtl::shape::RandomVoronoi<shape_t> fil(300, 0.3, 1);
	fil.draw(matrix);

	constexpr int update_timer{ 30 };
	int now_timer{ update_timer };

	while (System::Update()) {
		if (now_timer >= update_timer) {
			now_timer = 0;
			dtl::Init<shape_t>().draw(matrix);
			fil.draw(matrix);
			output(matrix);
		}
		++now_timer;
	}

}

PerlinNoise

#include <DTL.hpp>
#include <DxLib.h>

namespace System {
	bool Update() noexcept { return (DxLib::ScreenFlip() != -1 && DxLib::ProcessMessage() != -1); }
}

void Main();

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
	DxLib::SetOutApplicationLogValidFlag(FALSE);
	DxLib::ChangeWindowMode(TRUE);
	DxLib::SetGraphMode(1280/2, 720/2, 32);
	if (DxLib::DxLib_Init() == -1) return -1;
	DxLib::SetDrawScreen(DX_SCREEN_BACK);
	DxLib::SetMainWindowText("Sample");
	Main();
	return DxLib::DxLib_End();
}

constexpr std::size_t size_x{ 1280/2 };
constexpr std::size_t size_y{ 720/2 };

constexpr int hachi{ 1 };
template<typename Matrix_, typename Matrix2_>
void output(const Matrix_& matrix_, const Matrix2_& elevation_) {
	float a{ 1 }, b{ 1 }, c{ 1 };
	for (std::size_t y{}; y < size_y; ++y)
		for (std::size_t x{}; x < size_x; ++x) {
			a = ((elevation_[y][x] < 50) ? 1.1f : (elevation_[y][x] < 90) ? 0.9f : ((elevation_[y][x] < 110) ? 1.0f : 1.3f));
			b = ((elevation_[y][x] < 50) ? 1.1f : (elevation_[y][x] < 90) ? 0.9f : ((elevation_[y][x] < 110) ? 1.0f : 1.3f));
			c = ((elevation_[y][x] < 50) ? 1.1f : (elevation_[y][x] < 90) ? 0.9f : ((elevation_[y][x] < 110) ? 1.0f : 1.3f));
			switch (matrix_[y][x]) {
			case 0:
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi, GetColor(int(41 / a), int(40 / b), int(159 / c)), TRUE);
				break;
			case 1:
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi, GetColor(int(218 / a), int(217 / b), int(225 / c)), TRUE);
				break;
			case 2:
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi, GetColor(int(223 / a), int(203 / b), int(140 / c)), TRUE);
				break;
			case 3:
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi, GetColor(int(188 / a), int(205 / b), int(146 / c)), TRUE);
				break;
			case 4:
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi, GetColor(int(164 / a), int(143 / b), int(50 / c)), TRUE);
				break;
			case 5:
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi, GetColor(int(97 / a), int(154 / b), int(96 / c)), TRUE);
				break;
			case 6:
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi, GetColor(int(101 / a), int(163 / b), int(56 / c)), TRUE);
				break;
			case 7:
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi, GetColor(9, int(100 / b), 5), TRUE);
				break;
			case 8:
			case 9:
			case 10:
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi, GetColor(int(43 / a), int(84 / b), int(41 / c)), TRUE);
				break;
			case 11:
				DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi, GetColor(int(120 / a), int(120 / b), int(190 / c)), TRUE);//81/80/159
				break;
			}
		}
}

void Main() {

	using shape_t = std::uint_fast8_t;

	constexpr double frequency{ 400 };
	constexpr std::size_t octaves{ 8 };
	constexpr std::uint_fast32_t seed{ 1 };

	constexpr double frequency_x{ frequency };
	constexpr double frequency_y{ frequency };

	constexpr std::size_t start_x{};
	constexpr std::size_t start_y{};


	//温度
	std::unique_ptr<float[][size_x] > temperature(new(std::nothrow) float[size_y][size_x]);


	//降水量
	std::unique_ptr<std::int_fast16_t[][size_x] > amount_of_rainfall(new(std::nothrow) std::int_fast16_t[size_y][size_x]);


	std::unique_ptr<std::uint_fast8_t[][size_x] > elevation(new(std::nothrow) std::uint_fast8_t[size_y][size_x]);
	std::unique_ptr<shape_t[][size_x] > biome(new(std::nothrow) shape_t[size_y][size_x]);

	std::size_t now_fps{ start_x };

	const dtl::utility::PerlinNoise perlin(seed);
	const dtl::utility::PerlinNoise perlin2(seed + 12345);
	const dtl::utility::PerlinNoise perlin3(seed + 3456789);

	const dtl::utility::PerlinNoise perlin4(seed + 6543210);

	for (std::size_t row{}; row < size_y; ++row)
		for (std::size_t col{}; col < size_x; ++col) {
			temperature[row][col] = static_cast<float>(80.0 * perlin.octaveNoise(octaves, (col + now_fps) / frequency_x, (row) / frequency_y)) - 20.0f;
			amount_of_rainfall[row][col] = static_cast<std::int_fast16_t>(4500.0 * perlin2.octaveNoise(octaves, (col + now_fps) / frequency_x, (row) / frequency_y));
			elevation[row][col] = static_cast<std::uint_fast8_t>(50.0 * perlin3.octaveNoise(octaves, (col + now_fps) / frequency_x, (row) / frequency_y));

			elevation[row][col] += static_cast<std::uint_fast8_t>(120.0 * perlin4.octaveNoise(octaves, (col + now_fps) / (frequency_x * 20), (row) / (frequency_y * 20)));
		}

	for (std::size_t row{}; row < size_y; ++row)
		for (std::size_t col{}; col < size_x; ++col) {

			if (elevation[row][col] < 80) {
				if (temperature[row][col] < -5.0f && elevation[row][col] >= 80) biome[row][col] = 11;
				else biome[row][col] = 0;
			}

			//ツンドラ
			else if (temperature[row][col] < -5.0f) biome[row][col] = 1;
			//砂漠
			else if (amount_of_rainfall[row][col] < 500) biome[row][col] = 2;
			else if (amount_of_rainfall[row][col] < 1500) {
				//ステップ
				if (temperature[row][col] < 20.0f) biome[row][col] = 3;
				//サバンナ
				else biome[row][col] = 4;
			}
			//針葉樹林
			else if (temperature[row][col] < 3.0f) biome[row][col] = 5;
			//夏緑樹林
			else if (temperature[row][col] < 12.0f) biome[row][col] = 6;
			//照葉樹林
			else if (temperature[row][col] < 20.0f) biome[row][col] = 7;
			//雨緑樹林
			else if (amount_of_rainfall[row][col] < 2500) biome[row][col] = 8;
			//亜熱帯多雨林
			else if (temperature[row][col] < 24.0f) biome[row][col] = 9;
			//熱帯多雨林
			else biome[row][col] = 10;
		}

	while (System::Update()) {
		++now_fps;

		for (std::size_t row{}; row < size_y; ++row) {
			for (std::size_t col{ 1 }; col < size_x; ++col) {
				temperature[row][col - 1] = temperature[row][col];
				amount_of_rainfall[row][col - 1] = amount_of_rainfall[row][col];
				elevation[row][col - 1] = elevation[row][col];
				biome[row][col - 1] = biome[row][col];
			}
			for (std::size_t col{ size_x - 1 }; col < size_x; ++col) {
				temperature[row][col] = static_cast<float>(80.0 * perlin.octaveNoise(octaves, (col + now_fps) / frequency_x, (row) / frequency_y)) - 20.0f;
				amount_of_rainfall[row][col] = static_cast<std::int_fast16_t>(4500.0 * perlin2.octaveNoise(octaves, (col + now_fps) / frequency_x, (row) / frequency_y));
				elevation[row][col] = static_cast<std::uint_fast8_t>(50.0 * perlin3.octaveNoise(octaves, (col + now_fps) / frequency_x, (row) / frequency_y));

				elevation[row][col] += static_cast<std::uint_fast8_t>(120.0 * perlin4.octaveNoise(octaves, (col + now_fps) / (frequency_x * 20), (row) / (frequency_y * 20)));

				if (elevation[row][col] < 80) {
					if (temperature[row][col] < -5.0f && elevation[row][col] >= 80) biome[row][col] = 11;
					else biome[row][col] = 0;
				}

				//ツンドラ
				else if (temperature[row][col] < -5.0f) biome[row][col] = 1;
				//砂漠
				else if (amount_of_rainfall[row][col] < 500) biome[row][col] = 2;
				else if (amount_of_rainfall[row][col] < 1500) {
					//ステップ
					if (temperature[row][col] < 20.0f) biome[row][col] = 3;
					//サバンナ
					else biome[row][col] = 4;
				}
				//針葉樹林
				else if (temperature[row][col] < 3.0f) biome[row][col] = 5;
				//夏緑樹林
				else if (temperature[row][col] < 12.0f) biome[row][col] = 6;
				//照葉樹林
				else if (temperature[row][col] < 20.0f) biome[row][col] = 7;
				//雨緑樹林
				else if (amount_of_rainfall[row][col] < 2500) biome[row][col] = 8;
				//亜熱帯多雨林
				else if (temperature[row][col] < 24.0f) biome[row][col] = 9;
				//熱帯多雨林
				else biome[row][col] = 10;
			}
		}
		output(biome, elevation);
	}

}

Clone this wiki locally