python - 单纯形噪声的随机种子

标签 python terrain procedural-generation simplex-noise

我正在按程序生成游戏地形。我尝试了 Simplex 噪音。地形生成得很漂亮。然而,当我多次运行该程序时,地形是完全相同的。如何随机化单纯形噪声?

from opensimplex import OpenSimplex
import random
from time import time

height = 40
width = height
scale = height / 10
value = [[0 for x in range(width)] for y in range(height)]
gen = OpenSimplex()

def noise(nx, ny):
    # Rescale from -1.0:+1.0 to 0.0:1.0
    return gen.noise2d(nx, ny) / 2.0 + 0.5

def printBiome(y, x):
  if value[y][x] <= 2:
    print('O', end = " ")
  elif value[y][x] >= 8:
    print('M', end = " ")
  else:
    print('L', end = " ")

for y in range(height):
    for x in range(width):
        nx = x/width - 0.5
        ny = y/height - 0.5
        value[y][x] = 10 * noise(1 * scale * nx, 1 * scale * ny) +  0.5 * noise(2 * scale * nx, 2 * scale* ny) + 0.25 * noise(4 * scale * nx, 4 * scale * ny)

for y in range(height):
    for x in range(width):
        printBiome(y, x)
    print()

最佳答案

OpenSimplex 类 defaults to using seed=0 。要生成不同的地形,请输入不同的种子值:

import uuid
# http://stackoverflow.com/a/3530326/190597
seed = uuid.uuid1().int>>64
gen = OpenSimplex(seed=seed)

关于python - 单纯形噪声的随机种子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40952572/

相关文章:

javascript - Cesium - 使用相机 Lat-Lon-Alt 位置绘制多边形

javascript - 将姓氏更改为数字,从而关联并显示图像

python - 将字符串文件转换为所需格式 : replace/with _ except the ones before comma

python - View 中缺少 "pass"

javascript - 在 Flask/JavaScript 中返回两个响应

python - 如何使用 perlin 噪声 python 制作二维 map

python - Django filter_horizo​​ntal 形式

python - 什么是可以从 Python 访问的简单、快速的 3D 引擎?

procedural-generation - 如何开始程序生成?

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