-
-
Notifications
You must be signed in to change notification settings - Fork 82
๐
Kasugaccho edited this page Aug 23, 2019
·
1 revision
#include <DTL.hpp>
#include <DxLib.h>
namespace System {
bool Update() noexcept { return (DxLib::ScreenFlip() != -1 && DxLib::ProcessMessage() != -1); }
}
void Main();
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
DxLib::SetOutApplicationLogValidFlag(FALSE);
DxLib::ChangeWindowMode(TRUE);
DxLib::SetGraphMode(512, 512, 32);
if (DxLib::DxLib_Init() == -1) return -1;
DxLib::SetDrawScreen(DX_SCREEN_BACK);
DxLib::SetMainWindowText("Island");
Main();
return DxLib::DxLib_End();
}
constexpr std::size_t size_x{ 512 };
constexpr std::size_t size_y{ 512 };
constexpr int hachi{ 1 };
template<typename Matrix_, typename Matrix2_>
void output(const Matrix_& matrix_, const Matrix2_& elevation_) {
for (std::size_t y{}; y < size_y; ++y)
for (std::size_t x{}; x < size_x; ++x) {
if (matrix_[y][x] == 20) continue;
float a{ (elevation_[y][x] < 60) ? 1.1f : ((elevation_[y][x] < 80) ? 1.0f : (elevation_[y][x] < 110) ? 0.9f : ((elevation_[y][x] < 140) ? 1.0f : 1.3f)) };
float b{ a };
float c{ a };
if (x > size_x*3 / 5) {
c = b = a *= (x - size_x*3 / 5.0f) * 8.0f / float(size_x*3 / 5.0f) + 1.0f;
}
unsigned int color{};
switch (matrix_[y][x]) {
case 0:color = GetColor(int(41 / a), int(40 / b), int(159 / c)); break;
case 1:color = GetColor(int(218 / a), int(217 / b), int(225 / c)); break;
case 2:color = GetColor(int(223 / a), int(203 / b), int(140 / c)); break;
case 3:color = GetColor(int(188 / a), int(205 / b), int(146 / c)); break;
case 4:color = GetColor(int(164 / a), int(143 / b), int(50 / c)); break;
case 5:color = GetColor(int(97 / a), int(154 / b), int(96 / c)); break;
case 6:color = GetColor(int(101 / a), int(163 / b), int(56 / c)); break;
case 7:color = GetColor(9, int(100 / b), 5);
case 8:case 9:case 10:
color = GetColor(int(43 / a), int(84 / b), int(41 / c));
break;
case 20:color = GetColor(0,0,0);
break;
default:
color = GetColor(int(97 / a), int(154 / b), int(96 / c)); break;
break;
}
DrawBox(static_cast<int>(x) * hachi, static_cast<int>(y) * hachi, static_cast<int>(x + 1) * hachi, static_cast<int>(y + 1) * hachi, color, TRUE);
}
}
template<typename Matrix_>
void earth(Matrix_& matrix,const double r_) {
using shape_t = std::uint_fast8_t;
constexpr double frequency{ 6.0 };
constexpr std::size_t octaves{ 6 };
std::uint_fast32_t seed{ DTL_RANDOM_ENGINE.get<std::uint_fast32_t>() };
const dtl::utility::PerlinNoise perlin(seed);
constexpr double frequency_x{ size_x / frequency };
constexpr double frequency_y{ size_y / frequency };
int x0{ (int)(size_x / 2) };
int y0{ (int)(size_y / 2) };
int r{ (int)(size_x * 2 / 5) };
int x{ r };
int y{};
int F{ -2 * r + 3 };
while (x >= y) {
for (int xx{ x0 - x }; xx <= x0 + x; ++xx) {
matrix[y0 + y][xx] = 1+static_cast<shape_t>(r_ * perlin.octaveNoise(octaves,
std::sin((xx - (x - r)) / float(2 * r) * 3.1416) * r / frequency_x,
(y0 + y) / frequency_y));
matrix[y0 - y][xx] = 1+static_cast<shape_t>(r_ * perlin.octaveNoise(octaves,
std::sin((xx - (x - r)) / float(2 * r) * 3.1416) * r / frequency_x,
(y0 - y) / frequency_y));
}
for (int xx{ x0 - y }; xx <= x0 + y; ++xx) {
matrix[y0 + x][xx] = 1+static_cast<shape_t>(r_ * perlin.octaveNoise(octaves,
std::sin((xx - (x - r)) / float(2 * r) * 3.1416) * r / frequency_x,
(y0 + x) / frequency_y));
matrix[y0 - x][xx] = 1+static_cast<shape_t>(r_ * perlin.octaveNoise(octaves,
std::sin((xx - (x - r)) / float(2 * r) * 3.1416) * r / frequency_x,
(y0 - x) / frequency_y));
}
if (F >= 0) {
x--;
F -= 4 * x;
}
y++;
F += 4 * y + 2;
}
}
void Main() {
using shape_t = std::uint_fast8_t;
std::unique_ptr<float[][size_x] > temperature(new(std::nothrow) float[size_y][size_x]);
std::unique_ptr<std::int_fast16_t[][size_x] > amount_of_rainfall(new(std::nothrow) std::int_fast16_t[size_y][size_x]);
std::unique_ptr<std::uint_fast8_t[][size_x] > elevation(new(std::nothrow) std::uint_fast8_t[size_y][size_x]);
std::unique_ptr<shape_t[][size_x] > biome(new(std::nothrow) shape_t[size_y][size_x]);
constexpr int update_fps{ 30 };
int now_fps{ update_fps };
while (System::Update()) {
++now_fps;
if (now_fps < update_fps) continue;
now_fps = 0;
for (std::size_t row{}; row < size_y; ++row)
for (std::size_t col{}; col < size_x; ++col) {
elevation[row][col] = 0;
amount_of_rainfall[row][col] = 0;
if (row < size_y / 2) temperature[row][col] = -60.0f + (row / float(size_y/2)) * 120.0f;
else temperature[row][col] = 60.0f - ((row - size_y / 2) / float(size_y/2)) * 120.0f;
}
//dtl::shape::PerlinIsland<float>(4.0, 2, -20.0f, 60.0f).draw(temperature, size_x, size_y);
dtl::shape::PerlinIsland<std::int_fast16_t>(4.0, 4, 4500).draw(amount_of_rainfall, size_x, size_y);
//dtl::shape::PerlinSolitaryIsland<shape_t>(0.9, 0.45, 6.0, 6, 200).draw(elevation, size_x, size_y);
earth(elevation, 180);
//earth(amount_of_rainfall, 4500);
for (std::size_t row{}; row < size_x; ++row)
for (std::size_t col{}; col < size_y; ++col) {
temperature[row][col] -= (elevation[row][col] - 130.0f) * 0.5f;
if (elevation[row][col] == 0) biome[row][col] = 20;
else if (elevation[row][col] < 100) biome[row][col] = 0;
//else biome[row][col] = 5;
//ใใณใใฉ
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;
}
//int x0{ (int)(size_x / 2) };
//int y0{ (int)(size_y / 2) };
//int r{ (int)(size_x * 41 / 100) };
//DrawCircle(x0, y0, r, GetColor(30, 40, 70), TRUE);
output(biome, elevation);
}
}
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)