Giter Site home page Giter Site logo

steo85it / perlin-numpy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pvigier/perlin-numpy

0.0 0.0 0.0 6.34 MB

A fast and simple perlin noise generator using numpy

Home Page: https://pvigier.github.io/2018/06/13/perlin-noise-numpy.html

License: MIT License

Python 100.00%

perlin-numpy's Introduction

perlin-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!

Description

A fast and simple perlin noise generator using numpy.

Installation

You can install this package via:

pip3 install git+https://github.com/pvigier/perlin-numpy

Usage

from perlin_numpy import (
    generate_fractal_noise_2d, generate_fractal_noise_3d,
    generate_perlin_noise_2d, generate_perlin_noise_3d
)

2D noise

The function generate_perlin_noise_2d generates a 2D texture of perlin noise. Its parameters are:

  • shape: shape of the generated array (tuple of 2 ints)
  • res: number of periods of noise to generate along each axis (tuple of 2 ints)
  • tileable: if the noise should be tileable along each axis (tuple of 2 bools)

Note: shape must be a multiple of res

The function generate_fractal_noise_2d combines several octaves of 2D perlin noise to make 2D fractal noise. Its parameters are:

  • shape: shape of the generated array (tuple of 2 ints)
  • res: number of periods of noise to generate along each axis (tuple of 2 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 2 bools)

Note: shape must be a multiple of lacunarity^(octaves-1)*res

3D noise

The function generate_perlin_noise_3d generates a 3D texture of perlin noise. Its parameters are:

  • shape: shape of the generated array (tuple of 3 ints)
  • res: number of periods of noise to generate along each axis (tuple of 3 ints)
  • tileable: if the noise should be tileable along each axis (tuple of 3 bools)

Note: shape must be a multiple of res

The function generate_fractal_noise_2d combines several octaves of 3D perlin noise to make 3D fractal noise. Its parameters are:

  • shape: shape of the generated array (tuple of 3 ints)
  • res: number of periods of noise to generate along each axis (tuple of 3 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 3 bools)

Note: shape must be a multiple of lacunarity^(octaves-1)*res

Recipes

Note these snippets require matplotlib.

2D Perlin and Fractal Noise

import matplotlib.pyplot as plt
import numpy as np
from perlin_numpy import (
    generate_perlin_noise_2d, generate_fractal_noise_2d
)

np.random.seed(0)
noise = generate_perlin_noise_2d((256, 256), (8, 8))
plt.imshow(noise, cmap='gray', interpolation='lanczos')
plt.colorbar()

np.random.seed(0)
noise = generate_fractal_noise_2d((256, 256), (8, 8), 5)
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 perlin_numpy import generate_fractal_noise_3d

np.random.seed(0)
noise = generate_fractal_noise_3d(
    (32, 256, 256), (1, 4, 4), 4, tileable=(True, False, False)
)

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 perlin_numpy import generate_perlin_noise_3d

np.random.seed(0)
noise = generate_perlin_noise_3d(
    (32, 256, 256), (1, 4, 4), tileable=(True, False, False)
)

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 Perlin noise

perlin-numpy's People

Contributors

pvigier avatar laurencewarne avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.