gpt-3.5-turbo-0301· OpenAI
WildChat-4.8M (AI2)
用python实现一个可传参frequency、lacunarity、persistence、octaves、seed的2D柏林噪声
- User
用python实现一个可传参frequency、lacunarity、persistence、octaves、seed的2D柏林噪声
- Assistant
下面是一个Python实现的2D柏林噪声函数,可以通过传递frequency、lacunarity、persistence、octaves和seed参数来自定义生成的噪声图像。
import numpy as np import random from math import floor def perlin2d(width, height, frequency=16, lacunarity=2, persistence=0.5, octaves=1, seed=None): if seed is not None: random.seed(seed) result = np.zeros((height, width)) amplitude = 1.0 total_amplitude = 0.0 for octave in range(octaves): sx = np.linspace(0, frequency * width / 100.0, width, endpoint=False) sy = np.linspace(0, frequency * height / 100.0, height, endpoint=False) x, y = np.meshgrid(sx, sy) noise = np.zeros((height, width)) for i in range(height): for j in range(width): n = floor(x[i][j]) + floor(y[i][j]) * 57 n = (n << 13) ^ n k = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff k = 1.0 - 2.0 * (k & 0x7fffffff) / 0x7fffffff noise[i][j] = k result += noise * amplitude frequency *= lacunarity total_amplitude += amplitude amplitude *= persistence result = ((result / total_amplitude) + 1) / 2 return result
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.