more noise

This commit is contained in:
Tobias Berger 2021-11-15 23:20:38 +01:00
parent 9163942d94
commit a56e05f1bd
3 changed files with 3161 additions and 7 deletions

3124
include/FastNoiseLite.h Normal file

File diff suppressed because it is too large Load diff

View file

@ -18,12 +18,12 @@ int inline _fastFloor(double x)
return x < xi ? xi - 1 : xi;
}
Grad2 *_newGrad2Arr(unsigned int size)
Grad2 inline *_newGrad2Arr(unsigned int size)
{
return (Grad2 *)malloc(sizeof(Grad2) * size);
}
short *_newShortArr(unsigned int size)
short inline *_newShortArr(unsigned int size)
{
return (short *)malloc(sizeof(short) * size);
}

View file

@ -1,5 +1,7 @@
#include "raylib.h"
#include "OpenSimplex2F.h"
#define FNL_IMPL
#include "FastNoiseLite.h"
#define initialScreenWidth 900
#define initialScreenHeight 900
@ -9,22 +11,50 @@ int main(void)
// Initialization
//--------------------------------------------------------------------------------------
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT);
InitWindow(initialScreenWidth, initialScreenHeight, "raylib [core] example - basic window");
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
OpenSimplexEnv *simplexEnv = initOpenSimplex();
OpenSimplexGradients *simplexGradiants = newOpenSimplexGradients(simplexEnv, 0);
fnl_state state = fnlCreateState();
state.seed = 0;
state.octaves = 1;
state.noise_type = FNL_NOISE_PERLIN;
//--------------------------------------------------------------------------------------
TraceLog(LOG_INFO, TextFormat("%i", GetScreenWidth()));
double offset = 0.0;
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
if (IsKeyPressed(KEY_SPACE))
{
state.noise_type++;
state.noise_type %= (FNL_NOISE_VALUE + 1);
TraceLog(LOG_INFO, TextFormat("Noisetype: %i", state.noise_type));
}
if (IsKeyPressed(KEY_UP))
{
state.octaves++;
}
if (IsKeyPressed(KEY_DOWN))
{
state.octaves--;
}
if (IsKeyPressed(KEY_UP) || IsKeyPressed(KEY_DOWN))
{
TraceLog(LOG_INFO, TextFormat("Octaves: %i", state.octaves));
}
float frameTime = GetFrameTime();
offset += (double)frameTime * 10.0;
TraceLog(LOG_INFO, TextFormat("fps: %f (%fms ; total %fs)", 1.0 / frameTime, frameTime * 1000.0, offset / 10.0));
//----------------------------------------------------------------------------------
// Draw
@ -37,7 +67,7 @@ int main(void)
{
for (int y = 0; y < GetScreenHeight(); y++)
{
int noise = (noise2(simplexEnv, simplexGradiants, x / 64.0, y / 64.0) + 1.0) / 2 * 255;
int noise = (fnlGetNoise2D(&state, ((double)x) + offset, ((double)y) + offset / 2.0) + 1.0) / 2.0 * 255.0; //(noise2(simplexEnv, simplexGradiants, x / 64.0 + offset, y / 64.0 + offset / 2.0) + 1.0) / 2 * 255;
DrawPixel(x, y, (Color){noise, noise, noise, 255});
}