Question

I read up on this article about Perlin Noise and have a few questions if anyone has the answers because I seem to be having some issues. In the pseudo code 2D section near the bottom, it shows he randomly generates numbers but instead of one variable as a parameter in the 1D code, he now uses an 'x' and a 'y'. Is this required in 2 dimensional noise or no? Also, his PerlinNoise_2D Function takes 2 float parameters now instead of 1 like in the 1 dimensional example. What are these float values supposed to be and where do they come from because I cannot find how to get them for the life of me. So if anyone knows the answers to any of my questions, I would greatly appreciate some help. Thanks.

EDIT: Ok simpler question, where do I get the 2 float values taken as parameters for the PerlinNoise_2D function?

Was it helpful?

Solution

A 2-dimensional pattern needs 2 parameters. Think of them as representing the Cartesian x and y coordinates of the pattern, in whatever way best fits your application.

So if, for example, you wanted to generate a W×H noise map in C++, you could do something like:

float noise[H][W];
for (int y = 0; y < H; ++y)
    for (int x = 0; x < W; ++x)
        noise[y][x] = PerlinNoise_2D(x, y);

You could then use the noise values to modulate the colour values of pixels in a bitmap, for instance.

(In this example the x and y parameters don’t need to be floats, but in the general case you might want them to be.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top