-
-
Notifications
You must be signed in to change notification settings - Fork 83
dtl::shape::PerlinSolitaryIsland (形状クラス)
Kasugaccho edited this page Aug 7, 2020
·
12 revisions
<DTL/Shape/PerlinSolitaryIsland.hpp>
// v0.4.12.0 - v0.4.13.0
namespace dtl::shape {
template <typename T>
class PerlinSolitaryIsland;
}
// v0.4.14.0 -
namespace dtl::shape {
template <typename T, typename Random_Engine = DTL_RANDOM_DEFAULT_RANDOM>
class PerlinSolitaryIsland;
}
※ T
は1bit以上の型
※ Random_Engine
は乱数生成クラス
(デフォルトでDTL_RANDOM_DEFAULT_RANDOM
が入っている)
機能名 | 対応 |
---|---|
非長方形Matrix | 可能✅ |
PerlinSolitaryIsland
とは "Matrixの描画範囲にパーリンノイズを使用して地形を生成する" 機能を持つクラスである。
描画範囲の全てを必ず塗りつぶす。
名前 | 説明 | 対応バージョン |
---|---|---|
draw | Matrixに描画する | v0.4.12 |
drawArray | Matrixに描画する | v0.4.12 |
create | Matrixに描画してMatrixを返す | v0.4.12 |
createArray | Matrixに描画してMatrixを返す | v0.4.12 |
名前 | 説明 | 対応バージョン |
---|---|---|
getPointX | 描画始点座標Xを取得 | v0.4.12 |
getPointY | 描画始点座標Yを取得 | v0.4.12 |
getWidth | 描画横幅Wを取得 | v0.4.12 |
getHeight | 描画縦幅Hを取得 | v0.4.12 |
getValue | 描画値を取得 | v0.4.12 |
名前 | 説明 | 対応バージョン |
---|---|---|
setPointX | 描画始点座標Xを指定 | v0.4.12 |
setPointY | 描画始点座標Yを指定 | v0.4.12 |
setWidth | 描画横幅Wを指定 | v0.4.12 |
setHeight | 描画縦幅Hを指定 | v0.4.12 |
setPoint | 描画始点座標(X,Y)を指定 | v0.4.12 |
setRange | 描画範囲(X,Y,W,H)を指定 | v0.4.12 |
setValue | 描画値を指定 | v0.4.12 |
名前 | 説明 | 対応バージョン |
---|---|---|
clearPointX | 描画始点座標Xを消去 | v0.4.12 |
clearPointY | 描画始点座標Yを消去 | v0.4.12 |
clearWidth | 描画横幅Wを消去 | v0.4.12 |
clearHeight | 描画縦幅Hを消去 | v0.4.12 |
clearPoint | 描画始点座標(X,Y)を消去 | v0.4.12 |
clearRange | 描画範囲(X,Y,W,H)を消去 | v0.4.12 |
clearValue | 描画値を消去 | v0.4.12 |
dtl::shape::PerlinSolitaryIsland<shape_t>(truncated_proportion_, mountain_proportion_, frequency, octaves, max_height, min_height).draw(matrix, width, height);
#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::PerlinSolitaryIsland<shape_t>(0.8, 0.4, 6.0, 8, 60).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;
}
18,25,27,28,27,23,23,22,18,12,13,15,18,20,22,20,18,13,11,14,13,14,16,17,18,16,19,21,22,22,19,18,18,17,13,14,13,16,21,21,18,14,18,21,18,16,18,18,
18,25,30,33,32,28,28,28,24,18,16,16,17,21,26,26,23,19,14,14,11,11,14,13,13,13,17,21,23,24,23,21,20,19,17,16,14,15,18,17,15,11,13,18,16,14,16,16,
18,23,28,33,32,31,32,31,26,21,21,22,24,26,30,30,26,22,18,17,16,14,14,12,12,13,16,21,25,27,26,24,24,22,20,19,16,15,17,15,12,11,13,17,15,12,11,11,
19,24,27,31,31,32,33,31,27,22,21,26,31,31,31,31,27,24,22,22,20,16,15,15,16,15,16,23,28,31,29,26,25,24,23,21,16,16,18,17,14,14,18,19,17,13,9,6,
18,22,24,26,29,30,32,30,27,25,26,28,32,33,33,32,27,23,20,21,20,18,22,22,23,22,22,26,29,32,31,28,27,26,25,24,20,21,24,24,23,19,19,19,16,13,8,6,
17,21,24,24,25,28,29,27,27,26,28,31,32,32,34,33,27,23,19,18,18,20,26,29,30,29,25,25,26,29,30,29,28,25,24,25,25,28,29,30,28,24,21,18,14,11,9,8,
20,22,25,25,26,29,30,28,28,27,29,34,34,33,33,32,28,24,20,16,18,21,24,28,32,33,28,28,29,30,31,31,28,25,26,26,27,31,31,31,29,25,21,19,15,13,11,10,
20,23,24,25,27,28,29,29,27,27,32,34,35,33,31,28,26,24,21,19,19,19,22,25,29,32,31,30,32,33,30,29,27,24,24,25,25,27,29,30,29,23,17,18,19,17,14,12,
18,22,22,22,23,22,24,27,28,27,31,34,37,37,33,29,28,26,23,24,23,21,24,25,28,29,29,29,32,37,34,30,28,24,23,24,23,24,28,29,26,22,19,20,21,21,19,17,
17,20,18,19,21,19,20,24,26,27,30,33,34,35,34,31,30,28,25,25,27,27,26,25,26,29,28,29,34,39,37,32,27,24,24,24,22,21,26,25,20,20,21,21,21,22,21,22,
17,21,21,22,24,22,22,23,24,27,31,36,35,34,33,31,31,30,26,24,27,29,27,25,27,30,29,30,35,39,37,34,31,27,27,27,23,21,21,20,18,17,19,23,25,26,26,28,
20,21,23,24,26,27,27,25,26,31,36,40,39,36,35,35,33,31,27,24,26,27,28,29,28,30,31,32,36,40,40,38,35,32,31,29,26,22,20,18,17,16,18,21,22,25,27,28,
22,21,23,25,27,28,28,28,32,36,40,43,44,40,39,40,37,35,30,29,30,30,34,35,33,32,31,32,37,40,41,40,37,36,34,30,26,21,18,19,17,15,18,19,18,20,21,22,
21,23,25,26,26,25,27,31,35,38,39,43,46,44,40,40,38,35,31,31,34,35,35,35,36,32,30,31,35,38,37,36,37,37,35,29,24,21,19,20,18,16,16,16,17,15,15,19,
22,24,24,26,27,26,31,34,36,39,41,43,46,46,44,41,36,33,32,33,36,38,36,33,35,34,34,34,34,36,34,31,34,37,35,31,29,27,24,23,20,17,15,13,12,11,15,19,
19,21,22,24,26,26,29,32,35,37,38,39,43,45,44,41,36,33,33,34,34,37,37,35,37,39,39,35,33,34,34,32,34,36,34,34,34,33,31,28,23,18,14,13,11,13,17,18,
18,19,22,22,23,24,25,26,28,29,31,31,37,41,41,39,38,32,31,34,33,34,34,34,38,41,40,38,38,36,35,34,36,37,36,34,31,31,31,30,26,20,18,17,16,16,14,15,
17,19,21,18,16,19,22,22,22,24,27,29,33,36,38,37,36,33,30,30,31,33,32,31,34,38,39,38,39,38,37,36,36,37,36,30,27,30,32,35,32,26,24,22,20,17,12,13,
16,17,17,14,14,15,18,22,25,25,24,26,28,29,34,35,34,34,31,28,31,34,32,30,32,35,36,37,40,40,38,39,37,37,36,31,31,32,33,36,34,30,29,26,22,19,15,15,
15,17,18,15,15,16,18,23,28,28,24,24,26,26,31,32,32,32,30,28,31,34,34,31,29,30,31,36,39,36,34,39,38,37,36,34,34,31,29,31,31,31,32,28,23,20,15,13,
13,17,18,16,18,21,21,22,28,30,27,28,30,29,31,31,29,29,29,28,33,35,36,34,33,30,31,35,34,32,35,39,36,35,36,33,31,26,26,29,30,31,31,27,23,21,15,12,
14,16,18,18,21,23,21,22,27,31,30,33,36,33,30,28,27,27,30,30,33,35,36,38,37,33,33,33,30,32,36,39,36,34,33,30,25,24,24,27,29,29,29,27,23,23,18,15,
16,16,16,15,19,23,23,24,28,31,33,36,36,34,30,27,28,29,34,36,40,40,41,40,36,32,31,33,33,35,36,36,34,32,34,32,26,24,22,24,25,24,24,24,22,22,18,15,
16,16,13,11,16,22,24,25,30,33,34,35,35,34,33,33,33,34,37,41,45,44,43,41,38,33,30,34,37,39,39,37,35,34,37,34,26,23,24,26,25,22,20,23,22,24,23,16,
18,18,13,12,18,23,23,23,28,31,32,31,33,32,32,36,38,39,43,45,46,45,46,45,42,37,35,36,36,38,39,38,36,34,34,34,26,22,24,27,26,23,23,27,25,25,24,18,
15,16,13,16,22,24,23,22,24,25,26,27,30,30,32,38,42,44,47,47,48,49,49,47,43,42,40,37,36,36,37,38,34,31,31,32,27,23,25,26,25,25,25,26,25,25,24,20,
15,18,17,19,22,23,24,25,25,23,24,26,29,33,37,41,43,44,46,46,46,47,47,47,47,44,40,37,35,34,37,39,34,30,31,31,25,22,26,28,29,30,28,25,23,21,19,19,
17,22,23,22,22,24,26,25,26,25,26,27,32,38,41,42,44,44,46,49,50,48,46,48,50,48,44,41,38,36,37,37,32,29,30,30,25,23,26,31,31,31,31,27,21,15,11,12,
18,22,22,21,23,25,27,25,28,27,26,29,37,43,45,44,47,48,51,54,52,50,49,49,50,49,47,45,43,41,39,35,31,28,27,29,26,23,27,32,30,28,31,27,21,15,11,11,
18,21,22,20,22,25,28,28,30,30,29,32,38,44,47,46,46,49,55,55,51,51,51,49,48,50,48,47,44,43,41,36,29,27,28,29,28,25,27,31,28,28,30,28,22,16,12,13,
15,17,20,20,23,26,28,29,30,30,30,33,37,40,43,46,47,47,50,50,49,46,44,44,46,48,47,47,44,40,40,37,32,30,28,29,30,30,31,32,27,27,28,27,23,16,14,16,
15,16,17,21,26,27,29,29,29,28,29,32,33,35,39,43,44,39,41,44,43,39,35,36,40,43,44,43,41,37,39,38,33,30,27,26,27,31,35,33,26,26,27,23,19,17,17,19,
18,20,21,25,27,27,28,28,28,26,30,33,33,32,35,38,36,32,36,39,36,33,31,32,36,40,41,41,40,36,37,38,36,32,27,24,26,29,32,31,26,24,22,18,16,15,12,15,
20,22,25,28,29,28,27,24,23,24,28,33,34,31,30,31,30,29,30,33,30,27,28,30,33,36,40,42,42,37,36,39,38,34,27,23,24,26,26,27,24,21,18,17,13,9,8,12,
21,22,25,30,30,28,24,19,20,23,25,30,33,30,30,28,26,28,28,30,29,25,28,31,30,31,33,35,38,38,38,38,35,34,32,27,26,27,26,26,25,24,23,22,15,10,9,12,
22,24,26,29,29,26,21,16,16,18,21,26,28,28,31,30,29,31,31,30,28,25,28,29,28,26,26,30,35,38,38,36,32,35,37,35,31,29,27,25,27,29,28,25,18,14,12,12,
22,23,25,27,27,25,20,18,19,16,19,24,24,24,29,31,31,31,29,26,24,20,23,23,22,21,21,26,33,35,36,36,35,37,37,35,31,26,24,22,26,29,28,24,18,12,10,10,
22,24,26,27,27,26,22,21,22,19,21,22,21,22,28,33,33,34,30,24,22,19,18,18,19,19,20,25,30,34,36,35,37,38,37,33,28,25,23,23,24,28,28,24,20,14,9,7,
22,25,28,28,30,30,24,21,22,20,21,22,21,21,27,32,33,35,31,23,21,20,18,16,19,19,20,25,30,34,34,31,33,34,34,34,31,27,26,27,26,29,29,25,23,21,14,9,
17,24,29,29,31,33,28,23,24,22,22,24,22,21,24,27,28,31,32,27,22,21,20,20,23,23,20,25,31,34,33,29,28,29,30,33,33,28,24,28,29,28,28,28,27,24,18,13,
18,24,27,28,32,33,28,24,26,26,26,26,21,19,20,24,26,27,29,26,21,19,21,22,26,27,25,25,30,34,31,26,26,25,26,27,26,23,21,24,26,25,27,27,25,23,20,18,
18,22,23,25,31,32,27,26,30,29,28,25,20,19,19,21,23,24,24,24,21,21,24,25,27,31,30,30,31,32,29,25,24,22,20,20,19,18,17,19,22,23,26,23,20,21,23,25,
17,22,24,24,30,33,29,27,28,27,25,20,17,16,14,15,19,22,24,26,23,24,29,31,33,34,30,29,27,26,23,19,18,18,18,20,20,18,16,15,19,19,20,20,20,22,24,27,
15,22,26,24,27,29,27,22,23,25,23,17,15,13,11,14,19,21,23,25,24,27,31,32,33,31,27,26,23,20,18,16,12,13,16,19,20,20,19,16,18,18,18,19,21,24,24,22,
18,21,22,22,23,22,19,16,21,25,22,16,16,15,12,13,16,18,21,22,23,27,29,29,30,27,27,26,21,15,14,15,12,10,12,15,18,19,18,18,21,22,21,21,23,26,23,18,
18,19,20,20,19,15,12,12,17,22,21,18,17,16,14,14,17,22,24,21,20,26,29,28,27,27,27,25,20,16,13,13,14,11,10,13,18,18,18,21,24,25,25,22,22,25,20,16,
16,17,19,18,13,8,9,11,14,19,19,18,16,14,13,15,19,23,24,21,24,26,25,24,24,24,22,21,19,19,17,14,15,14,13,14,17,18,19,21,21,21,20,17,19,22,19,15,
16,18,19,15,11,9,8,10,14,19,19,19,16,11,11,16,19,21,21,23,27,25,23,22,21,19,16,15,14,17,19,15,17,17,16,17,18,19,20,19,18,18,16,16,17,19,18,16,
////////////////////////////////////////////////////////////////////////////////////////////////
//////####//////////////////////////////////////////////////////////////////////////////////////
//////##########////////////////////////////////////////////////////////////////////////////////
//////##########////////########//////////////////////////##////////////////////////////////////
////////////##//////////########//////////////////////////####//////////////////////////////////
//////////////////////##########////////////////////////////////////////////////////////////////
//////////////////////##########////////////////####////////####//////////######////////////////
////////////////////##########////////////////////####//####////////////////////////////////////
////////////////////##########//////////////////////////######//////////////////////////////////
//////////////////////##########////////////////////////########////////////////////////////////
////////////////////##############//////////////////////##########//////////////////////////////
//////////////////##################////////////////##################//////////////////////////
////////////////####################////////##########################//////////////////////////
//////////////######################################//################//////////////////////////
////////////############################################################////////////////////////
//////////////################################################################//////////////////
////////////////////##########################################################//////////////////
////////////////////////############////##############################//////######//////////////
////////////////////////////##########//######//##################################//////////////
////////////////////////////########////########////########################//########//////////
////////////////////////////####////////##########//######################////////####//////////
//////////////////##//######////////////################//############//////////////////////////
//////////////////##########////////####################################////////////////////////
//////////////////##################################//##################////////////////////////
//////////////////######################################################////////////////////////
////////////////////////////############################################////////////////////////
//////////////////////////########################################//####////////////////////////
////////////////////////##########################################////////////########//////////
////////////////////////##########################################////////////##////##//////////
//////////////////////##########################################//////////////##////////////////
//////////////////////############################################//////////####////////////////
//////////////////////############################################////////######////////////////
//////////////////////##############################################////////####////////////////
//////////////////////######//##//////##////////####################////////////////////////////
////////////////////////##////////////////////##//####################//////////////////////////
////////////////////////////##////####//////////////////##################//////////////////////
//////////////////////////////######////////////////////##################//////////////////////
//////////////////////////////######//////////////////////##############////////////////////////
//////////////////////////////########////////////////////################//////////////////////
////////####//////////////////////####//////////////////######////////####//////////////////////
////////####//////////////////////////////////////////////####//////////////////////////////////
////////####//////////////////////////////////////##////####////////////////////////////////////
//////////##//////////////////////////////////######////////////////////////////////////////////
////////////////////////////////////////////########////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
#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::PerlinIsland<float>(3.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::PerlinIsland<std::uint_fast16_t>(3.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::PerlinSolitaryIsland<shape_t>(0.8, 0.45, 3.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) {
temperature[row][col] -= (elevation[row][col] - 100.0f) * 0.3f;
//海
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_solitary.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;
}
Copyright (c) 2018-2021 As Project.
Distributed under the Boost Software License, Version 1.0.(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)