Skip to content

Simple Python3 wrapper for the opensimplex-go module

License

Notifications You must be signed in to change notification settings

O-X-L/opensimplex

Repository files navigation

OpenSimplex Noise

Lint Test

This repository contains a simple Python3-wrapper around the opensimplex-go module.

It should be an alternative to the full Python3-implementation of opensimplex.


Benchmarks

50 x 50

Implementation Time
opensimplex-go CLI 0.047
opensimplex python 0.673
opensimplex-go CGO 8.371

200 x 200

Implementation Time
opensimplex-go CLI 0.209
opensimplex python 10.808
opensimplex-go CGO 139.539

1000 x 1000

Implementation Time
opensimplex-go CLI 3.535
opensimplex python 248.498
opensimplex-go CGO LOOONG...

Example Map


Usage

You first need to either download or build the golang binaries.

Build

  1. Golang download/install

  2. Build them: bash scripts/build_cli.sh and/or bash scripts/build_cgo.sh


CLI Implementation

  1. Install example requirements: pip install -r examples/requirements.txt

  2. Test it: python3 examples/generate_map_cli.py

  3. How to use it: Example | Practical Example of Terrain-Generation

This way it basically calls the standalone golang binary in a subprocess and loads the resulting data from a temporary file.

It currently only supports generating whole 2D noise-maps.

Raw CLI Usage

Export data example:

{
  "data": [0, 0, 43.49935, 0, 1, 39.84343],  // x, y, height
  "max": 43.49935,
  "min": 39.84343
}

Usage:

Usage of noise_cli:
  -size int
        Map size (default 1000)
  -x float
        Map offset dimension-X
  -y float
        Map offset dimension-Y
  -out string
        Map output file (default "/tmp/map.json")
  -dimensions int
        Dimensions (default 2)
  -seed int
        Seed
  -exponentiation float
        Exponentiation (default 5)
  -height float
        Height (default 135)
  -lacunarity float
        Lacunarity (default 1.5)
  -octaves int
        Octaves (default 10)
  -persistence float
        Persistence (default 0.7)
  -scale float
        Scale (default 50)
  -silent
        Do not show output
  -no-coords
        If enabled the coords will be omitted from the data-export
  -sink
        If the whole noise-map should be sunk-down so the lowest point is 0
  -lower float
        Lower each height by this value - negatives are clamped to 0
  -mirror string
        To mirror the values set this to one of: 'x', 'y', 'xy', 'reverse'
  -rotate string
        To rotate the values set this to one of: '90cw', '90ccw', '180'

CGO Implementation

  1. Install example requirements: pip install -r examples/requirements.txt

  2. Test it: python3 examples/minimal_cgo.py or python3 examples/generate_map_cgo.py

  3. How to use it: Example

The CGO implementation is very slow. Not yet sure why that is..


Credits

Thanks to @ojrac for the golang module, to @KdotJPG for the original OpenSimplex and to @simondevyoutube for the implementation-example.

License

MIT