Perlin Noise Algoritm¶
Ken Perlin is the creator of perlin noise algoritm used in generating textures and terrain-like images to name a few applications of this smooth noise. This arcticle is about application of it and not so much about the algorithms steps.
Perlin in Python¶
In Python in 2023 there is no built-in implementation of the Perlin noise algorithm. Since I can't quickly (time isn't a key factor) refactor this implementation from java to python https://mrl.cs.nyu.edu/~perlin/noise/ I have to rely on external dependency: pip install perlin-noise
And now you are ten lines away from generating some cloudy organic looking textrure...
Usecase 1¶
To begin with I would like to generate y values from perlin noise for x values within an interval (1,100).
In [2]:
import numpy as np
from perlin_noise import PerlinNoise
import matplotlib.pyplot as plt
scale = 10.0
octaves = 6
noise = PerlinNoise(octaves=octaves)
num_points = 100
x_interval = (1, 100)
x_values = np.linspace(x_interval[0], x_interval[1], num_points) # [1,2,3...100]
In [7]:
y_values = [noise([i/10]) for i in range(num_points)]
print(len(y_values))
plt.plot(x_values, y_values)
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Perlin Noise')
plt.show()
In [8]:
y_values[:10]
Out[8]:
In [ ]: