#include "raylib.h"
// #define STB_PERLIN_IMPLEMENTATION
#include "stb_perlin.h"
int main(void)
{
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "Raylib Perlin Noise");
int currentTexture = 0;
SetTargetFPS(60);
// Main game loop
while (!WindowShouldClose())
{
BeginDrawing();
ClearBackground(RAYWHITE);
// void DrawText(const char *text, int posX, int posY, int fontSize, Color color);
DrawText("PERLIN NOISE", 640, 10, 20, RED);
// Generate and display Perlin noise
for (int y = 0; y < screenHeight; y++) {
for (int x = 0; x < screenWidth; x++) {
// Scale coordinates for Perlin noise function
float nx = x / (float)screenWidth, ny = y / (float)screenHeight;
// float stb_perlin_noise3(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap)
float noiseValue = stb_perlin_noise3(nx * 10, ny * 10, 0, 0, 0, 0);
/*
typedef struct Color {
unsigned char r; // Color red value
unsigned char g; // Color green value
unsigned char b; // Color blue value
unsigned char a; // Color alpha value
} Color;
*/
// Map noise value to grayscale color
int color = (unsigned char)((noiseValue + 1) * 127);
Color c = { color, color, color, 255 };
DrawPixel(x, y, c);
}
}
EndDrawing();
}
CloseWindow(); // Close window and OpenGL context
return 0;
}
/*
run:
*/