Skip to content

dtl::shape::PerlinLoopIsland (形状クラス)

Kasugaccho edited this page Oct 12, 2019 · 6 revisions

バージョン:0.4.10.0以降

<DTL/Shape/PerlinLoopIsland.hpp>

// v0.4.10.0 - v0.4.13.0
namespace dtl::shape {
  template <typename T>
  class PerlinLoopIsland;
}

// v0.4.14.0 -
namespace dtl::shape {
  template <typename T, typename Random_Engine = DTL_RANDOM_DEFAULT_RANDOM>
  class PerlinLoopIsland;
}

T は1bit以上の型

Random_Engineは乱数生成クラス (デフォルトでDTL_RANDOM_DEFAULT_RANDOMが入っている)

対応機能

機能名 対応
非長方形Matrix 可能✅

概要

PerlinLoopIslandとは "Matrixの描画範囲にパーリンノイズを使用して地形を生成する" 機能を持つクラスである。

描画範囲の全てを必ず塗りつぶす。

メンバ関数

描画

名前 説明 対応バージョン
draw Matrixに描画する v0.4.10
drawArray Matrixに描画する v0.4.10
create Matrixに描画してMatrixを返す v0.4.10
createArray Matrixに描画してMatrixを返す v0.4.10

描画範囲取得/描画値取得

名前 説明 対応バージョン
getPointX 描画始点座標Xを取得 v0.4.10
getPointY 描画始点座標Yを取得 v0.4.10
getWidth 描画横幅Wを取得 v0.4.10
getHeight 描画縦幅Hを取得 v0.4.10
getValue 描画値を取得 v0.4.10

描画範囲指定/描画値指定

名前 説明 対応バージョン
setPointX 描画始点座標Xを指定 v0.4.10
setPointY 描画始点座標Yを指定 v0.4.10
setWidth 描画横幅Wを指定 v0.4.10
setHeight 描画縦幅Hを指定 v0.4.10
setPoint 描画始点座標(X,Y)を指定 v0.4.10
setRange 描画範囲(X,Y,W,H)を指定 v0.4.10
setValue 描画値を指定 v0.4.10

描画範囲消去/描画値消去

名前 説明 対応バージョン
clearPointX 描画始点座標Xを消去 v0.4.10
clearPointY 描画始点座標Yを消去 v0.4.10
clearWidth 描画横幅Wを消去 v0.4.10
clearHeight 描画縦幅Hを消去 v0.4.10
clearPoint 描画始点座標(X,Y)を消去 v0.4.10
clearRange 描画範囲(X,Y,W,H)を消去 v0.4.10
clearValue 描画値を消去 v0.4.10

例 (C++11)

#include <DTL.hpp>
#include <cstdint>
#include <array>

int main() {

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

	dtl::shape::PerlinLoopIsland<shape_t>(6.0, 8, 63).draw(matrix);

	dtl::console::OutputNumber<shape_t>(",").draw(matrix);
	dtl::console::OutputStringBool<shape_t>("##", "//").drawOperator(matrix, [](const shape_t value) {return value > 30; });

	return 0;
}

出力

31,27,25,22,23,25,24,29,31,35,36,32,31,33,34,32,31,29,32,37,31,24,26,30,31,37,40,43,43,39,36,32,31,29,27,30,35,40,37,32,31,29,30,25,24,27,25,28,
18,16,17,15,17,20,18,25,34,37,34,30,30,33,37,37,35,35,36,37,30,22,20,22,24,30,34,42,43,40,37,33,32,26,25,32,36,37,31,27,27,25,24,19,17,18,16,17,
14,9,11,12,16,21,17,18,26,33,33,29,26,27,34,40,43,42,42,40,34,27,26,26,29,32,37,44,43,41,37,34,31,26,27,33,33,36,33,25,25,22,20,16,13,14,13,15,
16,10,9,13,19,23,17,17,26,33,35,31,23,18,22,34,39,42,44,44,40,31,28,28,28,32,38,43,43,43,40,37,34,32,33,34,36,39,36,29,28,22,18,17,11,13,17,17,
15,12,8,9,15,22,21,21,31,39,40,37,27,18,21,30,31,35,37,37,35,27,26,26,23,24,28,34,38,41,42,42,42,39,35,34,37,39,36,29,26,22,22,24,18,14,18,18,
22,14,7,10,17,22,25,29,36,41,40,38,28,20,22,27,29,31,32,31,30,27,26,26,21,15,16,23,26,31,37,43,46,42,35,34,39,42,39,33,28,23,25,28,23,18,20,24,
29,23,20,18,21,23,29,35,40,44,43,38,24,15,15,20,26,32,37,37,39,37,32,30,20,12,14,21,24,29,39,42,42,42,38,36,39,41,40,35,28,22,24,31,29,28,31,34,
27,28,29,24,21,24,29,32,36,43,43,35,23,15,14,20,26,36,45,46,49,46,42,39,26,18,16,21,27,30,38,38,32,32,35,35,34,38,41,37,30,23,24,32,35,35,32,29,
31,31,28,26,23,22,25,27,31,37,36,30,23,18,16,24,31,39,44,44,47,44,44,43,31,23,18,20,26,28,36,37,31,26,30,35,35,37,40,38,31,24,23,27,31,35,32,27,
33,30,25,22,19,19,23,26,31,35,34,31,26,21,19,24,33,41,46,43,42,45,48,46,36,27,20,22,27,30,34,34,30,27,29,31,32,33,35,34,29,22,20,25,29,34,33,31,
41,34,30,25,19,19,22,25,30,31,29,27,24,23,24,25,34,41,43,43,45,48,47,43,36,30,26,26,30,34,33,32,30,28,25,25,28,31,35,33,28,24,21,25,28,35,39,42,
47,42,40,36,32,27,26,26,29,30,25,21,20,23,27,28,38,43,42,47,50,49,45,38,30,29,28,25,27,30,29,28,28,27,24,26,31,33,36,34,29,27,25,28,32,42,50,52,
47,41,41,41,39,35,33,29,31,31,25,26,27,30,31,29,39,45,48,52,51,50,49,38,31,25,20,18,21,24,24,24,26,26,25,28,31,34,39,39,36,34,32,34,38,44,48,49,
44,43,43,45,43,42,38,29,27,28,25,29,34,32,28,26,34,44,48,52,51,51,48,38,31,23,15,14,18,21,25,25,26,26,27,32,35,38,44,46,44,41,40,38,36,39,40,42,
33,40,42,47,48,46,38,28,28,29,25,25,27,26,27,25,33,43,48,54,54,52,46,38,30,24,20,18,20,19,26,27,26,27,30,37,37,38,43,46,45,41,40,36,34,32,30,30,
27,39,40,41,46,46,41,34,34,31,22,19,21,23,24,24,33,45,50,54,54,52,46,39,33,28,21,21,24,25,30,33,31,29,33,37,36,35,36,41,41,37,37,34,30,24,20,22,
31,41,38,33,39,40,37,33,31,31,25,20,23,27,24,23,31,41,44,46,47,45,41,35,31,29,23,19,21,23,29,34,31,28,32,34,31,29,29,32,31,28,32,31,26,19,19,23,
30,36,31,28,34,33,30,29,29,29,24,21,25,29,28,27,31,38,40,43,44,42,38,34,32,30,24,18,18,20,25,30,29,27,29,27,24,24,22,24,24,23,26,29,25,18,17,22,
26,30,28,25,26,26,26,24,21,22,21,21,24,26,28,34,37,43,46,49,48,47,45,39,36,32,25,20,20,21,23,26,28,29,29,24,25,26,20,18,19,20,24,25,21,17,19,23,
26,25,23,22,20,20,20,18,15,14,18,23,22,22,30,39,40,43,46,47,45,44,47,41,34,34,30,24,20,21,20,22,26,28,28,24,24,23,17,13,15,18,21,22,20,20,24,25,
31,27,25,25,23,23,21,19,15,11,16,25,23,21,29,39,39,41,42,41,39,33,37,35,31,29,25,26,24,22,20,21,26,27,26,22,19,19,17,13,15,19,22,25,25,28,30,29,
38,34,29,28,29,30,30,25,20,18,22,28,27,23,27,37,40,40,41,38,30,23,27,26,21,20,19,24,28,23,20,23,28,30,24,20,18,17,16,15,17,20,26,31,32,36,41,39,
36,34,29,27,30,32,31,29,29,27,25,26,25,24,28,33,34,34,36,36,27,20,22,24,19,20,24,26,27,22,22,23,28,32,24,17,15,16,20,23,23,26,32,37,41,41,42,39,
34,30,26,24,26,26,26,30,31,28,26,27,27,28,30,31,34,37,36,35,30,22,22,27,27,27,29,31,29,25,24,23,26,32,29,24,20,21,27,31,30,31,37,41,41,39,41,39,
31,26,20,19,23,26,29,33,31,27,31,33,31,30,27,26,31,36,32,27,23,22,28,33,31,34,36,37,31,23,19,20,31,38,37,36,35,35,34,32,31,31,34,30,27,24,21,26,
28,23,18,18,22,25,28,29,30,31,35,37,31,25,22,20,24,29,24,18,15,18,32,40,39,42,44,41,33,25,19,21,30,37,38,37,35,37,38,35,32,32,35,32,29,29,26,29,
31,28,25,25,24,28,30,27,30,32,35,40,35,25,22,19,20,25,22,19,17,17,31,42,43,42,39,35,30,24,19,21,29,36,38,36,36,35,33,30,27,26,30,31,32,35,35,38,
26,28,31,31,30,32,36,34,33,33,34,41,37,25,20,18,18,20,20,22,19,16,26,37,37,36,33,29,27,23,18,24,34,40,40,36,34,33,32,28,22,18,22,28,30,33,41,48,
21,23,27,27,26,25,32,37,38,38,41,42,33,23,19,19,21,22,24,26,20,17,25,32,31,31,31,28,30,28,25,28,34,42,43,39,39,37,36,33,26,22,26,31,31,31,40,47,
22,22,23,24,25,24,29,36,40,41,43,43,33,27,25,26,28,31,30,28,24,21,22,25,22,25,30,31,33,32,30,30,33,41,42,42,43,40,40,36,30,26,28,32,35,33,37,43,
20,26,31,29,28,27,26,30,35,37,40,42,37,33,30,29,32,36,32,25,22,22,21,22,22,24,29,30,29,27,25,28,35,43,45,45,42,39,41,38,33,30,30,30,30,31,37,42,
24,32,40,34,28,25,21,22,28,34,38,39,39,35,29,27,30,35,32,26,24,26,27,25,26,29,29,27,24,24,22,24,31,37,42,44,43,39,39,36,32,31,33,30,26,27,34,40,
31,35,37,32,28,25,22,25,31,35,35,34,36,34,31,28,31,38,35,32,31,31,29,28,31,36,38,35,30,28,23,24,31,35,40,40,39,37,38,36,31,29,31,32,31,28,31,35,
33,34,31,27,26,23,22,28,35,35,32,29,31,32,31,28,28,36,38,36,35,34,33,34,39,41,42,39,33,31,24,25,34,39,38,35,36,36,36,35,33,31,31,35,35,28,28,28,
28,33,31,23,21,20,22,28,34,35,32,29,30,29,26,27,28,31,35,36,34,33,34,36,38,42,44,40,36,33,27,24,29,36,33,30,35,37,35,32,31,33,36,38,36,28,26,24,
27,34,32,26,24,25,27,29,33,34,34,32,31,29,22,23,28,30,32,33,33,32,31,33,36,41,45,40,38,35,29,26,29,32,31,29,32,36,36,32,31,34,38,37,34,31,26,23,
31,36,32,28,27,28,30,32,35,33,33,32,31,31,24,19,23,27,31,31,33,35,32,32,39,39,37,33,33,36,35,34,34,32,31,29,33,36,33,30,31,32,35,36,35,36,31,28,
35,35,32,27,25,30,31,33,37,36,32,31,31,32,27,21,25,30,31,29,32,34,33,30,36,34,32,30,32,38,42,40,36,33,30,28,30,32,32,30,31,31,32,35,35,37,37,38,
36,32,29,24,25,32,32,31,37,41,36,32,30,27,23,21,26,33,31,28,32,31,30,29,33,27,26,28,32,38,42,42,36,33,30,28,27,26,28,30,31,33,32,34,33,35,39,43,
35,30,25,21,21,28,31,30,34,41,40,33,26,23,22,22,26,33,32,32,35,35,33,31,35,24,20,23,30,38,40,35,31,31,31,30,28,24,26,28,30,31,31,36,37,38,39,40,
31,26,21,21,23,25,29,28,31,36,37,34,28,24,23,25,31,37,40,42,42,40,36,34,31,21,17,18,24,34,37,31,31,30,28,29,27,23,27,29,31,33,34,40,39,40,38,35,
26,22,19,22,27,27,26,24,27,33,35,35,32,27,22,23,32,40,46,49,46,41,37,36,28,19,12,14,19,26,32,34,33,29,29,31,31,29,30,31,31,32,38,41,40,42,39,29,
30,27,24,26,27,26,25,22,25,32,34,32,29,28,25,24,33,38,45,51,48,42,42,43,32,25,17,17,18,23,31,36,32,30,32,32,33,34,34,36,33,29,34,38,38,39,35,30,
34,28,24,26,29,29,25,23,29,34,33,29,27,28,25,25,33,39,42,46,44,41,40,43,33,26,20,17,16,22,28,29,28,32,35,33,34,36,40,43,39,33,32,35,38,37,33,34,
31,25,24,24,24,28,24,24,34,43,42,33,31,30,25,26,34,41,43,42,42,40,36,34,23,19,16,18,19,24,25,25,28,33,34,35,39,41,45,46,42,37,35,35,38,39,38,36,
32,28,29,24,22,26,24,27,36,46,46,39,35,32,29,28,34,41,41,42,43,39,32,29,16,18,19,19,22,26,24,24,30,33,34,39,42,45,51,49,45,41,37,37,37,38,39,37,
35,31,29,26,28,32,27,28,36,44,44,38,34,30,27,25,28,34,36,38,38,37,31,29,24,26,23,20,23,26,23,23,29,36,41,48,50,49,49,45,44,44,40,39,38,37,39,40,
37,33,30,27,29,32,29,28,32,40,42,36,32,31,30,27,27,29,31,34,31,31,34,33,31,30,26,23,23,24,26,28,33,39,44,48,49,46,41,37,36,38,39,36,34,35,37,38,
##//////////////##################//######//////##################//////##########//////////////
////////////////######////##############////////////##############////########//////////////////
//////////////////####//////##############////////################////########//////////////////
//////////////////######//////##############//////############################//////////////////
////////////////########////////##########////////////########################//////////////////
////////////////########//////////######//////////////////######################////////////////
//////////////##########//////////############//////////////####################//////##////####
//////////////##########//////////##############////////////####################//////########//
####////////////######//////////##################//////////######////############//////######//
##//////////////########////////##################//////////####//////##########//////////######
####//////////////##////////////##################////////######//////////######//////////######
##########//////////////////////################////////////////////////########////////########
##############//####////////##//##################//////////////////////########################
##############//////////####////##################////////////////////##########################
##############//////////////////################//////////////////////######################////
//##################////////////##################////////////####//####################////////
####################////////////##################////////////####//######////####//####////////
//####//####////////////////////##################//////////////////////////////////////////////
//////////////////////////////######################////////////////////////////////////////////
//////////////////////////////######################////////////////////////////////////////////
##////////////////////////////####################//////////////////////////////////////////////
####//////////////////////////##########//////////////////////////////////////////////##########
####//////####////////////////##########//////////////////////////##////////////////############
##//////////////##////////////##########//////////////##//////////##//////////##//##############
##////////////####//######//////######////////############//////######################//////////
//////////////////########//////////////////##############////////######################////////
##////////////////########//////////////////############//////////############////////##########
////####//################////////////////////########//////////##############////////////######
////////////##############////////////////////########//////////################//////##########
//////////////############////////##//////////////////######////################//////##########
////##//////////############////######//////////////////////////##################////////######
//######//////////##########//////####//////////////////////////######################//////####
########////////##############//############////########////////##################//######//####
######//////////######//######////##########################////##########################//////
//####//////////######////////////##########################//////####//##################//////
//####//////////##########//////////########################//////####//####################////
######////////##############////////##################################//######//##############//
######//////################////////##//######//######//############//////####//################
####//////##############//////////####//####////##//////############////////////################
##//////////##//########//////////################////////############////////////##############
##//////////////########////////##################////////########//////////////################
//////////////////########//////################////////////######////####////################//
//////////////////######////////##################//////////######//##############//##########//
##////////////////####//////////##################////////////////##############################
##//////////////##########//////################//////////////////##############################
##//////////////############////##############////////////////////##############################
####//////##////##########////////############////////////////////##############################
####//////##////############////////##############//////////////################################

例 (C++11)

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

int main() {

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

	//温度
	std::unique_ptr<float[][size_x] > temperature(new(std::nothrow) float[size_y][size_x]);
	dtl::shape::PerlinLoopIsland<float>(6.0, 8, -20.0f, 60.0f).draw(temperature, size_x, size_y);

	//降水量
	std::unique_ptr<std::uint_fast16_t[][size_x] > amount_of_rainfall(new(std::nothrow) std::uint_fast16_t[size_y][size_x]);
	dtl::shape::PerlinLoopIsland<std::uint_fast16_t>(6.0, 8, 0, 4500).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::PerlinLoopIsland<shape_t>(6.0, 8, 200).draw(elevation, size_x, size_y);

	//バイオーム
	std::unique_ptr<shape_t[][size_x] > biome(new(std::nothrow) shape_t[size_y][size_x]);

	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;
			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;
		}

	dtl::storage::FilePNG<shape_t>("file_sample_biome.png", 3).write(biome, size_x, size_y, [](const shape_t value, unsigned char* const color) {
		switch (value) {
			//
		case 0:
			color[0] = 41;
			color[1] = 40;
			color[2] = 159;
			break;
			//ツンドラ
		case 1:
			color[0] = 218;
			color[1] = 217;
			color[2] = 225;
			break;
			//砂漠
		case 2:
			color[0] = 223;
			color[1] = 203;
			color[2] = 140;
			break;
			//ステップ
		case 3:
			color[0] = 188;
			color[1] = 205;
			color[2] = 146;
			break;
			//サバンナ
		case 4:
			color[0] = 164;
			color[1] = 143;
			color[2] = 50;
			break;
			//針葉樹林
		case 5:
			color[0] = 97;
			color[1] = 154;
			color[2] = 96;
			break;
			//夏緑樹林
		case 6:
			color[0] = 101;
			color[1] = 163;
			color[2] = 56;
			break;
			//照葉樹林
		case 7:
			color[0] = 9;
			color[1] = 100;
			color[2] = 5;
			break;
			//雨緑樹林
		case 8:
			//亜熱帯多雨林
		case 9:
			//熱帯多雨林
		case 10:
			color[0] = 43;
			color[1] = 84;
			color[2] = 41;
			break;

		}
		});

	return 0;
}

出力

pim

画像

pim

関連項目

dtl::utility::PerlinNoise

dtl::shape::PerlinIsland

Clone this wiki locally