OpenSimplex noise generation problems (just seems random, is my function wrong?)

1.6k Views Asked by At

I'm working on a 2d tile based game in pygame and I'm trying to use a noise map to generate my map.

I've installed the OpenSimplex library and everything works fine there. Problem is that I don't seem to be getting a smooth random gradient, it looks more like random noise.

Here's the function I'm using to generate my image:

def generate_noise(seed,game):
size = int(WIDTH/TILESIZE)
tmp = OpenSimplex(seed)
for x in range(size):
    for y in range(size):
        val = (tmp.noise2d(x,y)+1)/2
        Tile(game,x,y,val)

The Tile then gets added to a sprite group and is drawn on the screen. I'm sure there are better ways of doing this but it seems like it should work. The val is used to colorize the tile when it's drawn, mapping it between 0 and 1 and multiplying by 255.

Here's the image I've been getting (I get similar images when I try different seeds): open simplex noise gen

Here's that image normalized so that all values >0.5 go to 1 and all values less than 0.4 go to 0, with everything between set to 0.5. This was done in an attempt to draw out any hidden gradient that maybe I couldn't see but all it did was this: enter image description here

As you can see, it just looks totally random. What am i doing wrong?? Thanks

1

There are 1 best solutions below

0
On

OpenSimplex is used with floating non-integers. What you see is a kind of zoomed out version of the noise. You should decide a scale variable to easily fix this. A scale of about 100 would work really well with your example. Feel free to change it around.

def generate_noise(seed,game):
    scale = 100
    size = int(WIDTH/TILESIZE)
    tmp = OpenSimplex(seed)
    for x in range(size):
        for y in range(size):
        val = (tmp.noise2d(x/scale, y/scale)+1)/2
        Tile(game,x,y,val)