我正在关注 Amit 的精彩教程: http://www.redblobgames.com/maps/terrain-from-noise/#demo
这段代码:
from opensimplex import OpenSimplex
def simplex_noise(size):
def noise(nx, ny):
gen = OpenSimplex()
# Rescale from -1.0:+1.0 to 0.0:1.0
return gen.noise2d(nx, ny) / 2.0 + 0.5
value = np.zeros((size,size),dtype=np.float16)
for y in range(size):
for x in range(size):
nx = x/size - 0.5
ny = y/size - 0.5
value[y,x] = noise(nx, ny) #(dont ask why flips x-y)
return value.reshape(size * size).tolist();
向我呈现这个(以 3d 形式制作):
而不是像这样的更随机噪音的东西(在 2D 中,来自 Amit 的网站):
我已经用 Diamond Square 算法做了这个,但想试试这个库,但很奇怪。输出介于 0 和 1 之间。
我迷路了!谢谢!
最佳答案
你的代码对我来说有点吵。是值(value)矩阵的 reshape 数组!? 为什么 ?试试这个例子得到相同的结果,也许这对你有帮助。
from opensimplex import OpenSimplex
from PIL import Image
height = int(input("Enter in the map height: "))
width = int(input("Enter in the map width: "))
def main():
simplex = OpenSimplex()
im = Image.new('L', (width, height))
for y in range(0, height):
for x in range(0, width):
value = simplex.noise2d(x , y )
color = int((value + 1) * 128)
im.putpixel((x, y), color)
im.save('noise2d_output.png')
im.show()
if __name__ == '__main__':
main()
关于python - OpenSimplex 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40894473/