gpt-3.5-turbo-0301· OpenAI
WildChat-4.8M (AI2)
用python实现一个可传参frequency、lacunarity、persistence、octaves、seed的柏林噪声
- User
用python实现一个可传参frequency、lacunarity、persistence、octaves、seed的柏林噪声
- Assistant
以下是一个使用python实现的柏林噪声函数,可以通过传递参数来控制频率、缺口、持续性、八度和种子等参数。
import numpy as np from numpy.random import default_rng def noise(x, y, frequency, lacunarity, persistence, octaves, seed): rng = default_rng(seed) total = 0.0 amplitude = 1.0 for i in range(octaves): sx = x * frequency sy = y * frequency ix, iy = int(sx), int(sy) u, v = sx - ix, sy - iy a = rng.random((2, 2)) a[a < persistence] = 0.0 a[a >= persistence] = 1.0 b = np.array([[ a[0, 0], a[0, 1] ], [ a[1, 0], a[1, 1] ]]) z = (1 - smoothstep(0, 1, u)) * (1 - smoothstep(0, 1, v)) * b[0, 0] + ( smoothstep(0, 1, u)) * (1 - smoothstep(0, 1, v)) * b[0, 1] + ( 1 - smoothstep(0, 1, u)) * (smoothstep(0, 1, v)) * b[1, 0] + ( smoothstep(0, 1, u)) * (smoothstep(0, 1, v)) * b[1, 1] total += z * amplitude frequency *= lacunarity amplitude *= persistence return total def smoothstep(start, end, val): x = np.clip((val - start) / (end - start), 0.0, 1.0) return x * x * (3 - 2 * x) def main(): import matplotlib.pyplot as plt X, Y = np.meshgrid(np.linspace(-0.5, 0.5, 200), np.linspace(-0.5, 0.5, 200)) Z = np.zeros((200, 200)) for i in range(200): for j in range(200): Z[i, j] = noise(X[i, j], Y[i, j], frequency=1.0, lacunarity=2.0, persistence=0.5, octaves=6, seed=42) plt.imshow(Z, cmap='gray') plt.show() if __name__ == '__main__': main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.