1

我正在尝试了解 Perlin Noise 和程序生成。我正在阅读有关生成具有噪音的景观的在线教程,但我不理解作者关于制作高海拔区域的部分解释。

在“岛屿”部分下的此网页上,有文字

设计一个与您想要的岛屿形状相匹配的形状。使用下部形状将地图向上推,使用上部形状将地图向下推。这些形状是从距离 d 到海拔 0-1 的函数。设置 e = 下 (d) + e * (上 (d) - 下 (d))。

我想这样做,但我不确定作者在谈论上下形状时的意思。

作者所说的“使用下部形状将地图向上推,上部形状将地图向下推”是什么意思?

代码示例:

from __future__ import division
import numpy as np
import math
import noise


def __noise(noise_x, noise_y, octaves=1, persistence=0.5, lacunarity=2):
    """
    Generates and returns a noise value.

    :param noise_x: The noise value of x
    :param noise_y: The noise value of y
    :return: numpy.float32
    """

    value = noise.pnoise2(noise_x, noise_y,
                          octaves, persistence, lacunarity)

    return np.float32(value)


def __elevation_map():
    elevation_map = np.zeros([900, 1600], np.float32)

    for y in range(900):

        for x in range(1600):

            noise_x = x / 1600 - 0.5
            noise_y = y / 900 - 0.5

            # find distance from center of map
            distance = math.sqrt((x - 800)**2 + (y - 450)**2)
            distance = distance / 450

            value = __noise(noise_x, noise_y,  8, 0.9, 2)
            value = (1 + value - distance) / 2

            elevation_map[y][x] = value

    return elevation_map
4

1 回答 1

3

作者的意思是,您应该根据与中心的距离 来描述点的最终高程 ,以及可能由噪声产生的初始高程 。fede

因此,例如,如果您希望地图看起来像一个碗,但要保持最初生成的地形的嘈杂特征,您可以使用以下函数:

def lower(d):
    # the lower elevation is 0 no matter how near you are to the centre
    return 0

def upper(d):
    # the upper elevation varies quadratically with distance from the centre
    return d ** 2

def modify(d, initial_e):
    return lower(d) + initial_e * (upper(d) - lower(d))

特别注意以“这是如何工作的?”开头的段落,我觉得这很有启发性。

于 2019-03-23T00:24:30.153 回答