Skip to content

Cloud Generater

Kasugaccho edited this page Jul 28, 2019 · 1 revision
#include <DTL.hpp>
#include <DTL/ImageWrite.hpp>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <new>

constexpr float cloud_p{ 0.75f };
constexpr float sky_p{ 0.25f };

int main() {

	using shape_t = std::uint_fast16_t;
	std::unique_ptr<shape_t[][512]> matrix(new(std::nothrow) shape_t[512][512]);

	for (std::size_t row{}; row < 512; ++row)
		for (std::size_t col{}; col < 512; ++col)
			matrix[row][col] = (shape_t)row;

	dtl::storage::FilePNG<shape_t>("file_clo2.png", 3).write(matrix,512,512, [](const shape_t value, unsigned char* const color) {
		if (value > 255) {
			color[0] = static_cast<char>((230 + ((39 - 244) * (value - 256.0f) / 523.0f)) * cloud_p + 16 * sky_p);
			color[1] = static_cast<char>((235 + ((45 - 244) * (value - 256.0f) / 523.0f)) * cloud_p + 123 * sky_p);
			color[2] = static_cast<char>((245 + ((57 - 244) * (value - 256.0f) / 523.0f)) * cloud_p + 219 * sky_p);
		}
		else {
			color[0] = static_cast<char>((16 + ((255 - 16) * value / 255.0f)) * (1.0f - value / (255.0f * 12)) * cloud_p + 16 * sky_p);
			color[1] = static_cast<char>((123 + ((255 - 123) * value / 255.0f)) * (1.0f - value / (255.0f * 12)) * cloud_p + 123 * sky_p);
			color[2] = static_cast<char>((219 + ((255 - 219) * value / 255.0f)) * (1.0f - value / (255.0f * 12)) * cloud_p + 219 * sky_p);
		}
		});

	return 0;
}

PN512

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

int main() {

	constexpr std::size_t size_x{ 512 };
	constexpr std::size_t size_y{ 512 };
	constexpr float cloud_p{ 0.75f };
	constexpr float sky_p{ 0.25f };

	constexpr double frequency{ 500 };
	constexpr std::size_t octaves{ 8 };
	constexpr std::uint_fast32_t seed{ 4 };

	constexpr double frequency_x{ frequency };
	constexpr double frequency_y{ frequency };

	std::unique_ptr<float[][size_x] > elevation(new(std::nothrow) float[size_y][size_x]);
	const dtl::utility::PerlinNoise perlin3(seed);

	for (std::size_t row{}; row < size_y; ++row)
		for (std::size_t col{}; col < size_x; ++col)
			elevation[row][col] = static_cast<float>(1000.0 * perlin3.octaveNoise(octaves, (col) / frequency_x, (row) / frequency_y)) - 500.0f;

	dtl::storage::FilePNG<float>("file_clo4.png", 3).write(elevation, 512, 512, [](float value, unsigned char* const color) {
		if (value < 0) value = 0;
		if (value > 255) {
			color[0] = static_cast<char>((230 + ((39 - 244) * (value - 256.0f) / 523.0f)) * cloud_p + 16 * sky_p);
			color[1] = static_cast<char>((235 + ((45 - 244) * (value - 256.0f) / 523.0f)) * cloud_p + 123 * sky_p);
			color[2] = static_cast<char>((245 + ((57 - 244) * (value - 256.0f) / 523.0f)) * cloud_p + 219 * sky_p);
		}
		else {
			color[0] = static_cast<char>((16 + ((255 - 16) * value / 255.0f)) * (1.0f - value / (255.0f * 12)) * cloud_p + 16 * sky_p);
			color[1] = static_cast<char>((123 + ((255 - 123) * value / 255.0f)) * (1.0f - value / (255.0f * 12)) * cloud_p + 123 * sky_p);
			color[2] = static_cast<char>((219 + ((255 - 219) * value / 255.0f)) * (1.0f - value / (255.0f * 12)) * cloud_p + 219 * sky_p);
		}
		});
}

PN512

Clone this wiki locally