gpt-3.5-turbo-0301· OpenAI
WildChat-4.8M (AI2)
python实现2d柏林噪声
- User
python实现2d柏林噪声
- Assistant
以下是Python中实现2D柏林噪声的示例代码:
import random def generate_noise(width, height): noise = [[0 for y in range(height)] for x in range(width)] for i in range(width): for j in range(height): noise[i][j] = random.choice([-1, 1]) return noise def smooth(noise, width, height, smooth_factor): for i in range(width): for j in range(height): top = noise[i][j-1] if j>0 else noise[i][j+1] bottom = noise[i][j+1] if j<(height-1) else noise[i][j-1] left = noise[i-1][j] if i>0 else noise[i+1][j] right = noise[i+1][j] if i<(width-1) else noise[i-1][j] noise[i][j] = (noise[i][j] + top + bottom + left + right) / smooth_factor return noise def normalize(noise, width, height, min_val, max_val): for i in range(width): for j in range(height): noise[i][j] = (noise[i][j] - min_val) / (max_val - min_val) return noise def generate_perlin_noise(width, height, scale, octaves, persistence): noise = [[0 for y in range(height)] for x in range(width)] for octave in range(octaves): octave_noise = generate_noise(width, height) for i in range(width): for j in range(height): noise[i][j] += octave_noise[i][j] * (persistence ** octave) width *= scale height *= scale return normalize(smooth(noise, width, height, 16), width, height, -1, 1)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.