Skip to content

Instantly share code, notes, and snippets.

@AlexiyOrlov
Created February 24, 2024 19:24
Show Gist options
  • Save AlexiyOrlov/5ccde8f0063974ab0b52d2818c4bd64f to your computer and use it in GitHub Desktop.
Save AlexiyOrlov/5ccde8f0063974ab0b52d2818c4bd64f to your computer and use it in GitHub Desktop.
Noise generation at an arbitrary position for terrain
void GenerateNoise(int width, int height, float scale, int octaves, int positionX, int positionY)
{
for (int y = positionY; y < positionY + height; y++)
{
for (int x = positionX; x < positionX + width; x++)
{
float sampleX = (float)x / width * scale;
float sampleY = (float)y / height * scale;
float noise = 0.0f;
float frequency = 0.0f;
for (int oct = 1; oct < octaves; oct *= 2)
{
frequency += 1.0f / oct;
noise += (1.0f / oct) * perlin.noise2D_01(oct * sampleX /*+ randomInt*/, oct * sampleY /*+ randomInt*/);
}
noise = noise / frequency;
//do something based on noise
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment