Question

I seem to be having a bit of an issue understanding this Perlin Noise article. I need some help understanding how calculating the pseudorandom gradients for each bounding point works. The author gives the function:

g(xgrid, ygrid) = (gx, gy)

Then he gives the image:

4 pseudorandom gradients?

I understand the rest of the article, but I have no idea how he generates these random gradients from each bounding point. Assistance would be greatly appreciated. Thanks!

Was it helpful?

Solution

but I have no idea how he generates these random gradients from each bounding point.

From the article, it uses a pseudorandom number generator with always the same seed, and calculates it always on the same grid, so that

we mean that g has the appearance of randomness, but with the important consideration that it always returns the same gradient for the same grid point, every time it's calculated. It's also important that every direction has an equal chance of being picked.

So probably it does something like

srand(CONSTANT_VALUE);

for (y = 0; y < GridHeight; y++)
{
    for (x = 0; x < GridWidth; x++)
    {
        r1 = rand();
        r2 = rand();
        gradient[y][x] = some_function(r1, r2);
    }
}

so that in each point the gradient is pseudorandom, it is always the same for the same x and y, and is distributed evenly. It then accesses the matrix gradient to run the rest of the calculations.

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