Skip to main content
GameDev.net gamedev.net
🔒 Locked

Need a noise algorithm

Started by Vendayan May 10, 2006 at 7:11 AM 4 replies 1.6k views
Original Post
Vendayan
Vendayan
I have specific need for an algorithm that can generate noise for terrain heightmaps which should be extremely flexible in the patterns it would create. The tricky part is that is must be constrained to predefined values along the top and left sides of the map. I'd prefer to use the same algorithm for creating all different sorts of terrain from an arid desert, grassy plains or acrtic tundra to mountains, hills or cliffside shores. Although if I must I have no problem with using different algorithms for different terrain types, so long as they can still blend in with surrounding patches which have a different terrain type.
"Never have a battle of wits with an unarmed man. He will surely attempt to disarm you as well"~Vendayan
bigryanjoel
bigryanjoel
What I would do is this
for all points
height(x,y) = random * (max - min) + min
reset edges (of the corners that you want to be set

for (number of blur itterations
{
run lowpass blur filter (if you want the terrain to be smoother, see gaussian blur for some examples)
then reset edges again.
}

seems like an easy problem. This method would give you a fairly nice terrain.
PERECil
PERECil
Look for an implementation of fractal brownian motion perhaps?
Vendayan
Vendayan
I don't really know what exactly I'm looking for but the problem is that as i said I need it to smoothly transition and be "intelligently" designed. If patch 1,8 (x,y in terms of its worldmap position) is along a coast and patch 2,8 is said to be mountainous, the coastal patch should be able to blend itself so that it's terrain gets rougher upon getting closer to that neighboring patch. Rough transitions are extremely noticeable and ugly. For my particular project bad transitions could also potentially allow exploitation which I'd prefer to avoid.
"Never have a battle of wits with an unarmed man. He will surely attempt to disarm you as well"~Vendayan
Zahlman
Zahlman
Here's some awful random hacking that might give you some useful ideas:

import randomfrom PIL import Imagefrom math import sqrtgen = random.Random()map = [0.0] * 65536img = Image.new('L', (256, 256))def test():    min = 0    max = 0    for value in map:        if min > value: min = value        if max < value: max = value    print min, max    scale = max    if -min > scale: scale = -min        for (i,value) in enumerate(map):        map = int(127 * (1 + (value / scale)))    img.putdata(map)    img.show()def mapsum(x, y, amount):    map[y * 256 + x] += amountdef hill(height, x, y, k):    if x < 1 or x > 254 or y < 1 or y > 254: return    xpct = 0    ypct = 0    for xi in range(256):        if xi < x:            xpct = xi / x        else:            xpct = (255 - xi) / (255 - x)        for yi in range(256):            if yi < y:                ypct = yi / y            else:                ypct = (255 - yi) / (255 - y)            pct = 1 - sqrt((1 - xpct)**2 + (1 - ypct)**2)            if pct < 0: pct = 0            #pct = min(xpct, ypct)            mapsum(xi, yi, height * (pct ** ((1 - pct) * k)))for x in range(1, 100):    hill(gen.normalvariate((1.0 / x) * [-1, 1][x % 2], sqrt(.0001 / x)),         gen.normalvariate(128.0, sqrt(x)*16), gen.normalvariate(128.0, sqrt(x)*16), x*2)test()

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.