Perlin Noise

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()
100
In [8]:
y_values[:10]
Out[8]:
[0.0,
 0.30141067191693366,
 -0.06253742022687327,
 0.11229297784986855,
 -0.16520280398891557,
 0.0,
 -0.24773174485269436,
 0.16862088673286366,
 0.1161273263136697,
 -0.24751411284841163]
In [ ]:
 

links

social