Skip to content

DxLib View

Kasugaccho edited this page Oct 13, 2019 · 5 revisions

Rect

#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, 256, 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{ 14 };
constexpr std::size_t size_y{ 11 };

void Main() {

	using shape_t = std::uint_fast8_t;

	shape_t draw_value{};

	std::unique_ptr<shape_t[][size_x] > matrix(new(std::nothrow) shape_t[size_y][size_x]);
	for (std::size_t row{}; row < size_y; ++row)
		for (std::size_t col{}; col < size_x; ++col)
			matrix[row][col] = 0;

	WaitKey();

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

		ClearDrawScreen();
		clsDx();
		dtl::shape::Rect<shape_t>(draw_value).draw(matrix, size_x, size_y);
		printfDx("\n dtl::shape::Rect<shape_t>(%02d).draw(matrix);\n\n ", (int)draw_value);
		for (std::size_t row{}; row < size_y; ++row) {
			for (std::size_t col{}; col < size_x; ++col) {
				printfDx("%02d,", (int)matrix[row][col]);
			}
			printfDx("\n ");
		}
		++draw_value;
	}
}

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, 582, 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 len{ 70 };
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] < 60) ? 1.1f : ((elevation_[y][x] < 80) ? 1.0f : (elevation_[y][x] < 110) ? 0.9f : ((elevation_[y][x] < 140) ? 1.0f : 1.3f));
			b = (elevation_[y][x] < 60) ? 1.1f : ((elevation_[y][x] < 80) ? 1.0f : (elevation_[y][x] < 110) ? 0.9f : ((elevation_[y][x] < 140) ? 1.0f : 1.3f));
			c = (elevation_[y][x] < 60) ? 1.1f : ((elevation_[y][x] < 80) ? 1.0f : (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, len + static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, len + 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, len + static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, len + 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, len + static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, len + 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, len + static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, len + 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, len + static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, len + 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, len + static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, len + 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, len + static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, len + 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, len + static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, len + 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, len + static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, len + 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_fast32_t;

	double draw_value{ 0.01 };

	//ๆธฉๅบฆ
	std::unique_ptr<float[][size_x] > temperature(new(std::nothrow) float[size_y][size_x]);
	std::unique_ptr<std::int_fast32_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]);



	WaitKey();

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

		ClearDrawScreen();
		clsDx();
		//dtl::shape::PointGrid<shape_t>(draw_value).draw(matrix, size_x, size_y);
		printfDx("\n dtl::shape::PerlinIsland<shape_t>\n (%f, 6, 200).draw(matrix);\n\n ", draw_value);

		DTL_RANDOM_ENGINE.seed(1);
		dtl::shape::PerlinIsland<float>(4.0, 2, -20.0f, 60.0f).draw(temperature, size_x, size_y);
		dtl::shape::PerlinIsland<std::int_fast16_t>(4.0, 4, 0, 4500).draw(amount_of_rainfall, size_x, size_y);
		dtl::shape::PerlinIsland<shape_t>(draw_value, 6, 200).draw(elevation, size_x, size_y);

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

				temperature[row][col] -= (elevation[row][col] - 130.0f) * 0.5f;

				if (elevation[row][col] < 100) 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);

		draw_value += 0.01;
	}
}

PerlinSolitaryIsland

#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, 582, 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 len{ 70 };
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] < 60) ? 1.1f : ((elevation_[y][x] < 80) ? 1.0f : (elevation_[y][x] < 110) ? 0.9f : ((elevation_[y][x] < 140) ? 1.0f : 1.3f));
			b = (elevation_[y][x] < 60) ? 1.1f : ((elevation_[y][x] < 80) ? 1.0f : (elevation_[y][x] < 110) ? 0.9f : ((elevation_[y][x] < 140) ? 1.0f : 1.3f));
			c = (elevation_[y][x] < 60) ? 1.1f : ((elevation_[y][x] < 80) ? 1.0f : (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, len + static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, len + 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, len + static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, len + 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, len + static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, len + 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, len + static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, len + 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, len + static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, len + 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, len + static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, len + 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, len + static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, len + 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, len + static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, len + 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, len + static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, len + 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_fast32_t;

	shape_t draw_value{ 1 };

		//ๆธฉๅบฆ
	std::unique_ptr<float[][size_x] > temperature(new(std::nothrow) float[size_y][size_x]);
	std::unique_ptr<std::int_fast32_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]);



	WaitKey();

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

		ClearDrawScreen();
		clsDx();
		//dtl::shape::PointGrid<shape_t>(draw_value).draw(matrix, size_x, size_y);
		printfDx("\n dtl::shape::PerlinSolitaryIsland<shape_t>\n (0.9, 0.45, 6.0, 6, 200, %d).draw(matrix);\n\n ", draw_value);

		dtl::random::mt32bit.seed(1);

		dtl::shape::PerlinIsland<float>(4.0, 2, -20.0f, 60.0f).draw(temperature, size_x, size_y);
		dtl::shape::PerlinIsland<std::int_fast16_t>(4.0, 4, 0, 4500).draw(amount_of_rainfall, size_x, size_y);
		dtl::shape::PerlinSolitaryIsland<shape_t>(0.9, 0.45, 6.0, 6, 200, draw_value).draw(elevation, size_x, size_y);

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

				temperature[row][col] -= (elevation[row][col] - 130.0f) * 0.5f;

				if (elevation[row][col] < 100) 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);

		++draw_value;
	}
}

AscendingOrder

#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, 256, 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{ 12 };
constexpr std::size_t size_y{ 10 };

void Main() {

	using shape_t = std::uint_fast32_t;

	shape_t draw_value{};

	std::unique_ptr<shape_t[][size_x] > matrix(new(std::nothrow) shape_t[size_y][size_x]);
	for (std::size_t row{}; row < size_y; ++row)
		for (std::size_t col{}; col < size_x; ++col)
			matrix[row][col] = 0;

	WaitKey();

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

		ClearDrawScreen();
		clsDx();
		dtl::shape::AscendingOrder<shape_t>(draw_value).draw(matrix, size_x, size_y);
		printfDx("\n dtl::shape::AscendingOrder<shape_t>(%02d)\n .draw(matrix);\n\n ", (int)draw_value);
		for (std::size_t row{}; row < size_y; ++row) {
			for (std::size_t col{}; col < size_x; ++col) {
				printfDx("%03d,", (int)matrix[row][col]);
			}
			printfDx("\n ");
		}
		++draw_value;
	}
}
Clone this wiki locally