Thanks to visit codestin.com
Credit goes to github.com

Skip to content

skyl4b/perlyn

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Perlyn: a Perlin noise generator using numpy

I wrote two articles on my blog about this project, the first one is about the generation of 2D noise while the second one is about the generation of 3D noise, feel free to read them!

You can find implementations using numba here.

Description

A fast and simple perlin noise generator using numpy.

Installation

You can install this package via:

pip install git+https://github.com/skyl4b/perlyn.git

Usage

from perlyn import (
    generate_fractal_noise,
    generate_perlin_noise,
)

Noise generation functions

The function generate_perlin_noise generates a N dimensional texture of Perlin noise. Its parameters are:

  • shape: shape of the generated array (tuple of N ints)
  • resolution: number of periods of noise to generate along each axis (tuple of N ints)
  • tileable: if the noise should be tileable along each axis (tuple of N bools, defaults to False)
  • seed : seed / Generator for RNG reproducibility.

Note: shape must be a multiple of resolution in each axis.

The function generate_fractal_noise combines several octaves of Perlin noise to make fractal noise. Its parameters are:

  • shape: shape of the generated array (tuple of N ints)
  • res: number of periods of noise to generate along each axis (tuple of N ints)
  • octaves: number of octaves in the noise (int)
  • persistence: scaling factor between two octaves (float)
  • lacunarity: frequency factor between two octaves (float)
  • tileable: if the noise should be tileable along each axis (tuple of N bools)
  • seed : seed / Generator for RNG reproducibility.

Note: shape must be a multiple of lacunarity^(octaves-1)*resolution in each axis.

Recipes

Note these snippets require matplotlib.

2D Perlin and Fractal Noise

import matplotlib.pyplot as plt
import numpy as np
from perlyn import (
    generate_perlin_noise,
    generate_fractal_noise,
)

noise = generate_perlin_noise((256, 256), (8, 8), seed=42)
plt.imshow(noise, cmap='gray', interpolation='lanczos')
plt.colorbar()

noise_fractal = generate_fractal_noise((256, 256), (8, 8), 5, seed=42)
plt.figure()
plt.imshow(noise, cmap='gray', interpolation='lanczos')
plt.colorbar()
plt.show()

2D Perlin noise 2D fractal noise

3D Fractal Noise

import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
from perlyn import generate_fractal_noise


noise = generate_fractal_noise(
    (32, 256, 256),
    (1, 4, 4),
    4,
    tileable=(True, False, False),
    seed=42,
)

fig = plt.figure()
images = [
    [plt.imshow(
        layer, cmap='gray', interpolation='lanczos', animated=True
    )]
    for layer in noise
]
animation_3d = animation.ArtistAnimation(fig, images, interval=50, blit=True)
plt.show()

3D fractal noise

3D Perlin Noise

import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
from perlyn import generate_perlin_noise


noise = generate_perlin_noise(
    (32, 256, 256), (1, 4, 4), tileable=(True, False, False), seed=42,
)

fig = plt.figure()
plt.axis("off")
images = [
    [plt.imshow(
        layer, cmap='gray', interpolation='lanczos', animated=True
    )]
    for layer in noise
]
animation_3d = animation.ArtistAnimation(fig, images, interval=50, blit=True)
plt.show()

3D Perlin noise

About

A fast and simple perlin noise generator using numpy

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%