-
-
Notifications
You must be signed in to change notification settings - Fork 82
dtl::utility::PerlinNoise (実用クラス)
Kasugaccho edited this page May 17, 2019
·
12 revisions
<DTL/Utility/PerlinNoise.hpp>
namespace dtl::utility {
class PerlinNoise;
}
PerlinNoise
とは "パーリンノイズを生成・ノイズ値を取得する" 機能を持つクラスである。
#include <DTL.hpp>
#include <DTL/ImageWrite.hpp>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <new>
int main() {
constexpr std::size_t size_x{ 256 };
constexpr std::size_t size_y{ 256 };
using shape_t = double;
std::unique_ptr<shape_t[][size_x]> matrix(new(std::nothrow) shape_t[size_y][size_x]);
constexpr double frequency{ 6.0 };
constexpr std::uint_fast8_t octaves{ 16 };
constexpr std::uint_fast32_t seed{ 1 };
const dtl::utility::PerlinNoise perlin(seed);
constexpr double frequency_x{ size_x / frequency };
constexpr double frequency_y{ size_y / frequency };
for (std::size_t row{}; row < size_y; ++row)
for (std::size_t col{}; col < size_x; ++col)
matrix[row][col] = static_cast<shape_t>(50.0 * perlin.octaveNoise(octaves, col / frequency_x, row / frequency_y));
dtl::storage::FileTerrainOBJ<shape_t>("sample_perlin.obj").write(matrix, size_x, size_y);
dtl::storage::FilePNG<shape_t>("sample_perlin.png", 3).write(matrix, size_x, size_y, [](const shape_t value, unsigned char* const color) {
if (value > 25.0) {
color[0] = 41;
color[1] = 40;
color[2] = 159;
}
else {
color[0] = 101;
color[1] = 163;
color[2] = 56;
}
});
}
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)