Perlin noise in python - seamlessly tile in any dimensions
Project description
PythonPerlin
Perlin noise in python - seamlessly tile in any dimensions
Installation
pip install pythonperlin
Generate Perlin noise with octaves
import pylab as plt
from pythonperlin import perlin
# Set grid shape for randomly seeded gradients
shape = (8,8)
# Set density - output shape will be shape * dens = (256,256)
dens = 32
# Generate noise
x = perlin(shape, dens=dens, seed=0)
plt.figure(figsize=(6,6))
plt.imshow(x, cmap=plt.get_cmap('viridis'))
plt.axis('off')
plt.show()
# Generate noise array with 2 additional octaves
x = perlin(shape, dens=dens, seed=0, octaves=2)
plt.figure(figsize=(6,6))
plt.imshow(x, cmap=plt.get_cmap('viridis'))
plt.axis('off')
plt.show()
Generate water caustics
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
dens = 32
shape = (8,8)
x = perlin(shape, dens=dens)
# Take absolute values of Perlin noise
x = np.abs(x)
# Log-scale colormap
logscale = np.logspace(0,-3,5)
colors = plt.cm.get_cmap('GnBu_r')(logscale)
cmap = LinearSegmentedColormap.from_list('caustics', colors)
plt.figure(figsize=(6,6))
plt.imshow(x, cmap=cmap)
plt.axis('off')
plt.show()
Generate flower petals
dens = 32
shape = (8,8)
x = perlin(shape, dens=dens)
n = 8
delta = dens
plt.figure(figsize=(6,6))
for i in range(n):
r = x[delta * i] + 1
r = np.concatenate([r, (r[0],)])
phi = 2 * np.pi * np.linspace(0, 1, len(r))
scale = 1 - i / n
z = scale * r * np.exp(1j * phi)
ax = plt.gca()
zorder = max([ch.zorder for ch in ax.get_children()])
plt.fill(z.real, z.imag, c='dodgerblue', zorder=zorder+1)
plt.plot(z.real, z.imag, c='blue', lw=2, zorder=zorder+2)
plt.axis('off')
plt.show()
Generate vector field
dens = 6
shape = (3,3)
x = perlin(shape, dens=dens)
z = np.exp(2j * np.pi * x)
shape = z.shape
plt.figure(figsize=(6,6))
for i in range(shape[0]):
for j in range(shape[1]):
di = 0.5 * z[i,j].real
dj = 0.5 * z[i,j].imag
plt.arrow(i, j, di, dj, color='dodgerblue', width=0.1)
plt.axis('off')
plt.show()
Documentation
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pythonperlin-0.0.1.tar.gz
(4.8 kB
view hashes)
Built Distribution
Close
Hashes for pythonperlin-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 353fe7fe87821a64dfa4c0b2f0e35a73ddfb9fff611e48cd26595daa35bb418f |
|
MD5 | 59dfa53c63b4c6e3d79af917a4a8e2b2 |
|
BLAKE2b-256 | 9ea67b50b8e9181ee18c37ad64cfae002f5248a77c7decf5fe6a6ca5568f5ec4 |