Question

I have an infinite 2D grid, and I need to randomly assign a value to each grid location. There is a finite number of integer values. I need the locations near each other to have similar values, creating 'globs' of locations with generally equal values. I previously tried to use a Perlin noise algorithm, but the values given to me are not distributed evenly, resulting in certain possible values being far more common than others.

Currently, my algorithm looks somewhat like this:

n = perlin(x/scale,y/scale) (scale is for coherence)
n = abs(n) / amplitude of Perlin function (as to make it between 0 and 1)
return floor(n*(max value))

However, this has created extremely uneven values no matter how I tweak the function. Is there a better way to created values like so?

Was it helpful?

Solution

To get some coherence on your grid you need to sample the perlin noise off the integer grid. For example: n = perlin(x/10.0, y/10.0).

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