Skip to content

RPG World Map Cliff

Kasugaccho edited this page Aug 22, 2020 · 3 revisions

ใƒใƒผใ‚ธใƒงใƒณ๏ผš0.4.12.0ไปฅ้™

ๅฎŸ่ฃ…ไพ‹ (C++11)

้ซ˜ใ•ๆƒ…ๅ ฑใ‚’ๅๆ˜ ใ—ใŸ๏ผˆๅด–ใŒ่ฟฝๅŠ ใ•ใ‚ŒใŸ๏ผ‰RPGใฎใƒฏใƒผใƒซใƒ‰ใƒžใƒƒใƒ—ใ‚’็”ปๅƒๅ‡บๅŠ›ใ™ใ‚‹ใƒ—ใƒญใ‚ฐใƒฉใƒ ใงใ™ใ€‚

#include <DTL.hpp>
#include <DTL/ImageWrite.hpp>
#include <cstddef>
#include <cstdint>
#include <new>
#include <memory>

int main() {

	using shape_t = std::uint_fast16_t;
	constexpr std::size_t size_x{ 512 };
	constexpr std::size_t size_y{ 512 };

	//ๆธฉๅบฆ
	std::unique_ptr<shape_t[][size_x] > temperature(new(std::nothrow) shape_t[size_y][size_x]);
	dtl::shape::PerlinIsland<shape_t>(12.0, 6, 240, 100).draw(temperature, size_x, size_y);

	//้™ๆฐด้‡
	std::unique_ptr<shape_t[][size_x] > amount_of_rainfall(new(std::nothrow) shape_t[size_y][size_x]);
	dtl::shape::PerlinIsland<shape_t>(12.0, 6, 225).draw(amount_of_rainfall, size_x, size_y);

	//ๆจ™้ซ˜
	std::unique_ptr<shape_t[][size_x] > elevation(new(std::nothrow) shape_t[size_y][size_x]);
	dtl::shape::PerlinSolitaryIsland<shape_t>(0.3, 0.4, 7.0, 6, 155).draw(elevation, size_x, size_y);

	std::unique_ptr<shape_t[][size_x] > land(new(std::nothrow) shape_t[size_y][size_x]);

	//ใƒใ‚คใ‚ชใƒผใƒ 
	std::unique_ptr<shape_t[][size_x] > biome(new(std::nothrow) shape_t[size_y][size_x]);

	//ๅด–
	std::unique_ptr<shape_t[][size_x] > elevation2(new(std::nothrow) shape_t[size_y][size_x]);

	enum : std::size_t {
		field_sea, //ๆตท
		field_lake, //ๆน–
		field_mountain, //ๅฑฑ
		field_desert, //็ ‚ๆผ 
		field_forest, //ๆฃฎๆž—
		field_rock, //ๅฒฉๅฑฑ
		field_hill, //ไธ˜
		field_savannah, //ใ‚ตใƒใƒณใƒŠ
		field_grass, //่‰ๅŽŸ
		field_cliff, //ๅด–
		field, //้€šๅธธใฎๅœฐ้ข
		field_num
	};

	//ใƒใ‚คใ‚ชใƒผใƒ ใฎๅˆ†้กžๅˆ†ใ‘
	for (std::size_t row{}; row < size_y; ++row)
		for (std::size_t col{}; col < size_x; ++col) {

			temperature[row][col] -= elevation[row][col] / 2;
			land[row][col] = 1;
			if (elevation[row][col] < 110) {
				biome[row][col] = field_sea;
				land[row][col] = 0;
			}
			else if (temperature[row][col] < 45) biome[row][col] = field_rock;
			else if (amount_of_rainfall[row][col] < 25) biome[row][col] = field_savannah;
			else if (amount_of_rainfall[row][col] < 75) {
				if (temperature[row][col] < 120) biome[row][col] = field_desert;
				else biome[row][col] = field_desert;
			}
			else if (temperature[row][col] < 69) biome[row][col] = field_grass;
			else if (temperature[row][col] < 96) biome[row][col] = field;
			else if (temperature[row][col] < 120) biome[row][col] = field_forest;
			else if (amount_of_rainfall[row][col] < 125) biome[row][col] = field_mountain;
			else if (temperature[row][col] < 132) biome[row][col] = field_mountain;
			else biome[row][col] = field_mountain;

			if (elevation[row][col] < 110) {
				elevation2[row][col] = 0;
			}
			else {
				if (elevation[row][col] < 110 + 5) elevation2[row][col] = 0;
				else elevation2[row][col] = (elevation[row][col] - 110 + 15) / 12;
			}
		}

	dtl::retouch::Bucket<shape_t>(1, 0, 0).draw(land, size_x, size_y);

	for (std::size_t row{}; row < size_y; ++row)
		for (std::size_t col{}; col < size_x; ++col) {
			if (elevation[row][col] < 110 && land[row][col] == 0) biome[row][col] = field_lake;
		}

	for (std::size_t col{}; col < size_x; ++col) {
		//for (std::size_t row{ size_y - 1 };; --row) {
		for (std::size_t row{}; row < size_y; ++row) {
			//ๅด–ใฎๅ ดๅˆ
			if (elevation2[row][col] >= 1) {
				const auto ev = elevation2[row][col];
				const bool is_over{ (ev > row) };
				if(!is_over) biome[row - ev][col] = biome[row][col] + field_num * elevation2[row][col];

				for (std::size_t row2{ row }, row_min{ (((ev - 1) >= row) ? 0 : (row - (ev - 1))) };; --row2) {
					biome[row2][col] = field_cliff;
					if (row2 <= row_min) break;
				}
			}
		}
	}

	dtl::storage::FilePNG<shape_t>("file_sample_rpg_world_map_cliff.png", 3).write(biome, size_x, size_y, [](const shape_t value, unsigned char* const color) {
		const double height = 1.0 / (value / (field_num * 8.0) + 1.0);
		const auto value2 = value % field_num;

		switch (value2) {
		case field_sea:
			color[0] = 33;
			color[1] = 97;
			color[2] = 124;
			break;
		case field_lake:
			color[0] = 88;
			color[1] = 124;
			color[2] = 139;
			break;
		case field_mountain:
			color[0] = 101;
			color[1] = 100;
			color[2] = 60;
			break;
		case field_desert:
			color[0] = 217;
			color[1] = 195;
			color[2] = 143;
			break;
		case field_forest:
			color[0] = 110;
			color[1] = 149;
			color[2] = 59;
			break;
		case field_rock:
			color[0] = 120;
			color[1] = 125;
			color[2] = 108;
			break;
		case field_hill:
			color[0] = 145;
			color[1] = 177;
			color[2] = 113;
			break;
		case field_savannah:
			color[0] = 144;
			color[1] = 140;
			color[2] = 73;
			break;
		case field_grass:
			color[0] = 90;
			color[1] = 128;
			color[2] = 63;
			break;
		case field_cliff:
			color[0] = 111*2/3;
			color[1] = 102*2/3;
			color[2] = 68*2/3;
			break;
		case field:
			color[0] = 139;
			color[1] = 181;
			color[2] = 59;
			break;
		}
		color[0] = static_cast<unsigned char>(color[0] * height);
		color[1] = static_cast<unsigned char>(color[1] * height);
		color[2] = static_cast<unsigned char>(color[2] * height);
		});

	return 0;
}

ๅ‡บๅŠ›

ๅ‡บๅŠ›็”ปๅƒ(512ร—512px)

wm512

็”ปๅƒ

ใƒ‰ใƒƒใƒˆ็ตต(40ร—40px, 1ใƒžใ‚น)ใฎใƒฏใƒผใƒซใƒ‰ใƒžใƒƒใƒ—(8000ร—8000px, 200ใƒžใ‚น)ใฎใ‚ตใƒณใƒ—ใƒซ็”ปๅƒใงใ™ใ€‚

wm8000 wm8000 wm8000 wm8000

้–ข้€ฃ้ …็›ฎ

dtl::shape::PerlinSolitaryIsland

dtl::shape::PerlinIsland

dtl::utility::PerlinNoise

dtl::shape::PerlinLoopIsland

RPG World Map

RPG World Map Cliff Planet

Clone this wiki locally