-
-
Notifications
You must be signed in to change notification settings - Fork 81
dtl::utility::PerlinNoise::octaveNoise (形状描画)
Kasugaccho edited this page May 17, 2019
·
5 revisions
// (1)
double octaveNoise(const std::size_t octaves) const noexcept;
// (2)
double octaveNoise(const std::size_t octaves, double x) const noexcept;
// (3)
double octaveNoise(const std::size_t octaves, double x, double y) const noexcept;
// (4)
double octaveNoise(const std::size_t octaves, double x, double y, double z) const noexcept;
オクターブ有りパーリンノイズを生成・ノイズ値を取得する。
戻り値の型は全てにおいて double
である。
戻り値 | 説明 |
---|---|
0.0 < value < 1.0 | 値(2次元の場合は標高データ)が返る |
投げない
不明
#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::size_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)