我在为项目生成Perlin噪声时遇到问题。当我想了解如何正确使用库时,我尝试逐步遵循此页面:https://medium.com/@yvanscher/playing-with-perlin-noise-generating-realistic-archipelagos-b59f004d8401在第一部分中,有代码:
import noise
import numpy as np
from scipy.misc import toimage
shape = (1024,1024)
scale = 100.0
octaves = 6
persistence = 0.5
lacunarity = 2.0
world = np.zeros(shape)
for i in range(shape[0]):
for j in range(shape[1]):
world[i][j] = noise.pnoise2(i/scale,
j/scale,
octaves=octaves,
persistence=persistence,
lacunarity=lacunarity,
repeatx=1024,
repeaty=1024,
base=0)
toimage(world).show()
我复制并粘贴了最后的少量内容(图像已过时,所以我有:]]
import noise import numpy as np from PIL import Image shape = (1024,1024) scale = 100 octaves = 6 persistence = 0.5 lacunarity = 2.0 seed = np.random.randint(0,100) world = np.zeros(shape) for i in range(shape[0]): for j in range(shape[1]): world[i][j] = noise.pnoise2(i/scale, j/scale, octaves=octaves, persistence=persistence, lacunarity=lacunarity, repeatx=1024, repeaty=1024, base=seed) Image.fromarray(world, mode='L').show()
我尝试了很多衍射模式,但是这种噪声甚至不接近相干噪声。我的结果是类似this(mode ='L')。有人可以解释一下,我在做什么错?
我在为项目生成Perlin噪声时遇到问题。当我想了解如何正确使用库时,我尝试逐步遵循此页面:https://medium.com/@yvanscher/playing -...
这里是工作代码。我随意清洗了一下。有关详细信息,请参见评论。作为最终建议:测试代码时,请使用matplotlib进行可视化。它的imshow()
功能比PIL
更健壮。