python - 使用柏林噪声按程序生成海拔明显较高的区域

标签 python procedural-generation perlin-noise noise-generator

我正在尝试了解柏林噪声和程序生成。我正在阅读有关生成带有噪声的景观的在线教程,但我不明白作者关于创建更高海拔区域的部分解释。

关于this webpage在“岛屿”部分下有文字

Design a shape that matches what you want from islands. Use the lower shape to push the map up and the upper shape to push the map down. These shapes are functions from distance d to elevation 0-1. Set e = lower(d) + e * (upper(d) - lower(d)).

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

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

代码示例:

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

最佳答案

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

因此,例如,如果您希望 map 看起来像碗,但保持原始生成地形的噪声特征,则可以使用以下函数:

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))

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

关于python - 使用柏林噪声按程序生成海拔明显较高的区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55308940/

相关文章:

javascript - 什么可能是 javascript 中 iteritems() [来自 python] 的替代品

Python 任务栏小程序

c# - 二维程序世界生成的动态多维数组

algorithm - 使用另一种算法修复 Perlin 噪声产生的方向性伪影

c++ - 柏林噪声和 FBM 生成的图像太灰

java - Perlin噪声的输出范围

python - 如何将类中的函数应用到 Pandas Dataframe 中

python - 匹配同一对象的两个不同图像

javascript - 从种子/ key 创建大型数组/数据

随机生成推箱子游戏的关卡?