gpt-3.5-turbo-0301· openai
Suzhen/CodeChat
用python实现一个可传参frequency、lacunarity、persistence、octaves、seed的2D柏林噪声
- User
用python实现一个可传参frequency、lacunarity、persistence、octaves、seed的2D柏林噪声
- Assistant
下面是一个使用Python实现可传递不同参数的2D柏林噪声的代码:
import random import math def interpolate(a, b, x): ft = x * math.pi f = (1 - math.cos(ft)) * 0.5 return a * (1 - f) + b * f def noise(x, y, seed): n = x + y * 57 + seed n = (n<<13) ^ n nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff return 1.0 - float(nn) / 1073741824.0 def octave_noise(x, y, octaves, frequency, persistence, lacunarity, seed): total = 0 amplitude = 1 max_value = 0 for i in range(octaves): n = noise(x * frequency, y * frequency, seed) total += n * amplitude frequency *= lacunarity max_value += amplitude amplitude *= persistence return total / max_value def perlin_noise(x_range, y_range, frequency=0.05, lacunarity=2, persistence=0.5, octaves=6, seed=0): grid = [] for x in range(x_range): row = [] for y in range(y_range): row.append(0) grid.append(row) for y in range(x_range): for x in range(y_range): grid[x][y] = octave_noise(x, y, octaves, frequency, persistence, lacunarity, seed) return grid这里有一些可配置的参数:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.