2016-12-03 2 views
1

저는 최근 게임을 위해 절차 적으로 생성 된 지형을 만들기 위해 노력해 왔습니다. 나는 Perlin 소음이 이것을 위해 유용하다는 것을 알았고, 그래서 나는 그것을 한방에 줬다. 지금까지 지형은 아름답게 생성됩니다. 그러나 프로그램을 여러 번 실행할 때마다 지형은 똑같습니다. 생성 된 Perlin 노이즈를 무작위로 추출 할 수있는 방법이 있습니까?Perlin 노이즈를위한 파이썬 랜덤 시드

코드 :

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

답변

1

OpenSimplex 클래스 defaults to using seed=0. 다른 지형을 생성하려면 다른 시드 값을 입력하십시오.

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