GithubHelp home page GithubHelp logo

noisy's Introduction

Noisy

Github Actions

nimble install noisy

Noisy is a SIMD-accelerated Nim implementation of Simplex (Perlin) noise. The goal of this library is to be easy to use, performant and dependency-free.

Noisy works well using Nim's relatively new --gc:arc and --gc:orc as well as the default garbage collector. This library also works using both nim c and nim cpp, in addition to --cc:vcc on Windows.

I have also verified that Noisy builds with --experimental:strictFuncs on Nim 1.4.0.

2D Simplex Noise

Example

import noisy, strformat

var simplex = initSimplex(1988)
simplex.frequency = 0.1

# Starting at (0, 0) generate a 16x16 grid of 2D noise values.
let values = simplex.grid((0, 0), (16, 16))
for x in 0 ..< 16:
  for y in 0 ..< 16:
    let value = values[x, y]
    echo &"({x},{y}): {value}"

Performance

Benchmarks can be run comparing methods for generating noise values. Check the performance yourself by running tests/benchmark.nim.

nim c -d:release -r .\tests\benchmark.nim (256 x 256 x 256 cube of 3D simplex noise with 3 octaves, lower time is better)

Method Time
Point by point using value(x, y, z) 1.6066s
Using grid() (SIMD accelerated, GCC default) 1.0281s
Using grid() (SIMD accelerated, --passC:"-mavx") 0.7476s

Testing

nimble test

API: noisy

import noisy

type Simplex

Simplex = object
 octaves*: int
 amplitude*, frequency*, lacunarity*, gain*: float32

type Grid

Grid = ref object
 width*, height*, depth*: int
 values*: seq[float32]

type NoisyError

NoisyError = object of ValueError

func initSimplex

func initSimplex(seed: int): Simplex

func []

Returns the noise value at (x, y) or (x, y, z).

func `[]`(g: Grid; x, y: int; z = 0): float32 {.inline.}

func value

Generates the 2D noise value at (x, y) based on the Simplex parameters.

func value(simplex: Simplex; x, y: float32): float32 {.raises: [NoisyError], tags: [].}

func value

Generates the 3D noise value at (x, y, z) based on the Simplex parameters.

func value(simplex: Simplex; x, y, z: float32): float32 {.raises: [NoisyError], tags: [].}

func value

Helper for working with ints.

func value(simplex: Simplex; x, y: int): float32 {.inline, raises: [NoisyError], tags: [].}

func value

Helper for working with ints

func value(simplex: Simplex; x, y, z: int): float32 {.inline, raises: [NoisyError].}

func grid

Beginning at position start, generate a grid of 2D noise based on the Simplex parameters. The width and height of the grid is set by the dimens parameter.

func grid(simplex: Simplex; start: (float32, float32); dimens: (int, int)): Grid {.raises: [NoisyError].}

func grid

Helper for working with ints.

func grid(simplex: Simplex; start: (int, int); dimens: (int, int)): Grid {. inline, raises: [NoisyError].}

func grid

Beginning at position start, generate a grid of 3D noise based on the Simplex parameters. The width, depth, and height of the grid is set by the dimens parameter.

func grid(simplex: Simplex; start: (float32, float32, float32);
 dimens: (int, int, int)): Grid {.raises: [NoisyError].}

func grid

Helper for working with ints.

func grid(simplex: Simplex; start: (int, int, int); dimens: (int, int, int)): Grid {. inline, raises: [NoisyError].}

noisy's People

Contributors

guzba avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

noisy's Issues

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.