This repository contains python and cython codes that can generate noise images, which can be used for texture and heightmap to visualize the terrain in 3D. In the python modules, numpy, and in the Cython modules, C array is mainly used. Those modules have the same functions, which return the array to be converted to an image. Their difference is speed. See speed comparison result below.
- Cython 3.0.11
- numpy 2.1.2
- opencv-contrib-python 4.10.0.84
- opencv-python 4.10.0.84
- Python 3.11
- Windows11
python setup.py build_ext --inplace
from cynoise.perlin import Perlin
# from pynoise.perlin import Perlin
from create_image import create_image_8bit, create_image_16bit
maker = Perlin()
arr = maker.pnoise3()
create_image_8bit(arr)
create_image_16bit(arr)
# change the number of lattices and the image size. The grid default is 4, size default is 256.
maker = Perlin(grid=8, size=257)
A noise image will be output as png file.
For more details of methods and parameters, please see source codes.
The execution time of each methods were measured like this.
maker = Voroni()
reslt = %timeit -o maker.noise2()
print(reslt.best, reslt.loops, reslt.repeat)
python | cython | |||||
---|---|---|---|---|---|---|
method | best(s) | loops | repeat | best(s) | loops | repeat |
Perlin.noise2 | 1.210008 | 1 | 7 | 0.017233 | 100 | 7 |
Perlin.noise3 | 2.081957 | 1 | 7 | 0.023179 | 10 | 7 |
Perlin.wrap | 4.889988 | 1 | 7 | 0.043762 | 10 | 7 |
FBM.noise2 | 3.849672 | 1 | 7 | 0.041291 | 10 | 7 |
FBM.wrap | 15.43603 | 1 | 7 | 0.139114 | 10 | 7 |
Cellular.noise2 | 1.420607 | 1 | 7 | 0.036839 | 10 | 7 |
Cellular.noise3 | 3.434327 | 1 | 7 | 0.090029 | 10 | 7 |
Cellular.noise24 | 4.833801 | 1 | 7 | 0.099891 | 10 | 7 |
Cellular.cnoise2 | 4.860955 | 1 | 7 | 0.153122 | 10 | 7 |
Cellular.cnoise3 | 13.82344 | 1 | 7 | 0.332647 | 1 | 7 |
Periodic.noise2 | 1.494618 | 1 | 7 | 0.021754 | 10 | 7 |
Periodic.noise3 | 2.582619 | 1 | 7 | 0.031351 | 10 | 7 |
Voronoi.noise2 | 1.464140 | 1 | 7 | 0.097766 | 10 | 7 |
Voronoi.noise3 | 3.533389 | 1 | 7 | 0.158923 | 10 | 7 |