Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you sample it sparsely enough, though, you might as well use rand. There wouldn't really be any gain from using a noise function in this application, however.

I think it was worth pointing out in the context of this post, though, as he took the time to directly address the part of his audience who apparently seems to think all "procedural" content should descend from a noise function, which is probably common with beginners. Often a simple random number generator will do just fine.



That misses the point completely.

You can trivially create a race track by following a route of a certain height in a perlin noise map. No algorithm needed at all. All you need is 2d perlin noise and a single if block:

    for x, y in range():
        if lower < perlin[x][y] < higher:
            map[x][y] = brown
        else:
            map[x][y] = green
The author just decided to take a different approach.


This algorithm is not sufficient. There's no requirement for the contour line to be simple, connected, or even closed within the domain you specify (the higher the frequency the more likely it will be closed, but the more likely it won't be connected).

One approach would be to then walk the line from the start and connect neighboring points that aren't too close to previous points and don't cause a turn tighter than some given angle (non-simple curves should only happen if you're unlucky enough to run into a saddle point of your desired value), but that solution starts looking a whole lot like taking the convex hull of clusters of random points...you could have just taken fewer points and then smoothed the curve that fits around them :)


That piece of code is an algorithm just fine.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: