Skip to content

Commit

Permalink
Version 1.1.1: better documentation, rust fix "f64" feature flag brok…
Browse files Browse the repository at this point in the history
…en compilation (#133)

FastNoiseLite -> FastNoise Lite in various places
  • Loading branch information
Keavon authored Mar 5, 2024
1 parent 9b7d6a9 commit 4603b31
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 78 deletions.
2 changes: 1 addition & 1 deletion JavaScript/FastNoiseLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
//

/**
* @description FastNoiseLite Lite is an extremely portable open source noise generation library with a large selection of noise algorithms
* @description FastNoise Lite is an extremely portable open source noise generation library with a large selection of noise algorithms
* @author Jordan Peck, snowfoxsh
* @version 1.1.0
* @copyright Copyright(c) 2023 Jordan Peck, Contributors
Expand Down
4 changes: 2 additions & 2 deletions JavaScript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ FastNoise Lite is an extremely portable open source noise generation library wit

## Getting Started

### Using FastNoiseLite with npm
### Using FastNoise Lite with npm

To begin install the npm package **fastnoise-lite** with


Note FastNoiseLite does **not** support the node.js require(''); function.
Note FastNoise Lite does **not** support the node.js require(''); function.
Instead, enable ES6 modules and **import**.

```javascript
Expand Down
2 changes: 1 addition & 1 deletion JavaScript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "fastnoise-lite",
"type": "module",
"version": "1.1.0",
"description": "FastNoiseLite is an extremely portable open source noise generation library with a large selection of noise algorithms",
"description": "FastNoise Lite is an extremely portable open source noise generation library with a large selection of noise algorithms",
"main": "FastNoiseLite.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down
6 changes: 3 additions & 3 deletions Rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 5 additions & 11 deletions Rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "fastnoise-lite"
version = "1.1.0"
version = "1.1.1"
edition = "2021"
license = "MIT"
description = "FastNoiseLite is an extremely portable open source noise generation library with a large selection of noise algorithms"
description = "FastNoise Lite is an extremely portable open source noise generation library with a large selection of noise algorithms"
repository = "https://github.com/Auburn/FastNoiseLite"
readme = "README.md"
authors = ["Jordan Peck", "Keavon Chambers"]
Expand All @@ -14,19 +14,13 @@ categories = [
"multimedia::images",
"rendering",
]
keywords = [
"noise",
"simplex",
"perlin",
"procedural",
"terrain",
]
keywords = ["noise", "simplex", "perlin", "procedural", "terrain"]

[features]
default = ["std"]
f64 = []
std = ["num-traits/std"]
libm = ["num-traits/libm"]
default = ["std"]

[dependencies]
num-traits = { version = "0.2.16", optional = true, default-features = false }
num-traits = { version = "0.2.18", optional = true, default-features = false }
57 changes: 38 additions & 19 deletions Rust/README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,66 @@
[![crates.io](https://img.shields.io/crates/v/fastnoise-lite?logo=rust "crates.io")](https://crates.io/crates/fastnoise-lite)[docs.rs](https://docs.rs/fastnoise-lite/latest/fastnoise_lite/)[GitHub](https://github.com/Auburn/FastNoiseLite)
[![GitHub](https://img.shields.io/github/v/release/Auburn/FastNoiseLite?logo=github&label=GitHub&color=blue
"GitHub")](https://github.com/Auburn/FastNoiseLite) [![crates.io](https://img.shields.io/crates/v/fastnoise-lite?logo=rust&color=blue "crates.io")](https://crates.io/crates/fastnoise-lite) [![docs.rs](https://img.shields.io/docsrs/fastnoise-lite/latest?logo=docs.rs&label=docs.rs&color=blue "docs.rs")](https://docs.rs/fastnoise-lite/latest/fastnoise_lite/)

# FastNoise Lite

FastNoise Lite is an extremely portable open source noise generation library with a large selection of noise algorithms. This library focuses on high performance while avoiding platform/language specific features, allowing for easy ports to as many possible languages.

## Features

- 2D & 3D
- OpenSimplex2 Noise
- OpenSimplex2S Noise
- Cellular (Voronoi) Noise
- Perlin Noise
- Value Noise
- Value Cubic Noise
- OpenSimplex2-based Domain Warp
- Basic Grid Gradient Domain Warp
- 2D & 3D sampling
- OpenSimplex2 noise
- OpenSimplex2S noise
- Cellular (Voronoi) noise
- Perlin noise
- Value noise
- Value Cubic noise
- OpenSimplex2-based domain warp
- Basic Grid Gradient domain warp
- Multiple fractal options for all of the above
- Supports floats and/or doubles
- Switch from `f32` to `f64` position inputs with the `"f64"` feature flag in your `Cargo.toml`
- Supports `f32` or `f64` precision floats for X/Y sampling positions (see "Feature Flags" below)
- `no_std` (see "Feature Flags" below)

## Feature Flags

Optionally enable these in your `Cargo.toml` file with your `fastnoise-lite` dependency.

- `"f64"`: Uses `f64`, instead of the default `f32`, X/Y coordinate sampling inputs.
- `"std"`: Uses Rust's standard library for floating point operations (`sqrt()`, `trunc()`, and `abs()`). Either this or `"libm"` must be enabled. This is enabled by default if no feature flags are specified (but note that specifying `"f64"` will mean this is no longer default, and must be specified too).
- `"libm"`: Enables `no_std` support. Either this or `"std"` must be enabled. Uses the [libm](https://crates.io/crates/libm) optional dependency (through the [num-traits](https://crates.io/crates/num-traits) optional dependency) to allow floating point operations (`sqrt()`, `trunc()`, and `abs()`) without relying on the Rust standard library's implementations. FNL is dependency-free except when using this feature flag, which pulls in these optional dependencies.

## Getting Started

Below is an example for creating a 128x128 array of OpenSimplex2 noise.
- First, construct a [`FastNoiseLite` struct](https://docs.rs/fastnoise-lite/latest/fastnoise_lite/struct.FastNoiseLite.html) using [`FastNoiseLite::new()`](https://docs.rs/fastnoise-lite/latest/fastnoise_lite/struct.FastNoiseLite.html#method.new) or [`FastNoiseLite::with_seed(seed)`](https://docs.rs/fastnoise-lite/latest/fastnoise_lite/struct.FastNoiseLite.html#method.with_seed).
- Next, you may call the various setter functions to configure the object's noise generation settings to your needs from their defaults.
- Optionally, you may use [`domain_warp_2d(x, y)`](https://docs.rs/fastnoise-lite/latest/fastnoise_lite/struct.FastNoiseLite.html#method.domain_warp_2d) and [`domain_warp_3d(x, y, z)`](https://docs.rs/fastnoise-lite/latest/fastnoise_lite/struct.FastNoiseLite.html#method.domain_warp_3d) to translate your original sampling coordinates into domain-warped coordinates before using them to sample the noise in the next step.
- Finally, sample the noise value at X/Y(/Z) coordinates for each pixel of your output data by calling [`get_noise_2d(x, y)`](https://docs.rs/fastnoise-lite/latest/fastnoise_lite/struct.FastNoiseLite.html#method.get_noise_2d) or [`get_noise_3d(x, y, z)`](https://docs.rs/fastnoise-lite/latest/fastnoise_lite/struct.FastNoiseLite.html#method.get_noise_3d). You may need to remap the output range from -1..1 to your desired range.

Additional documentation is available in the project's [Getting Started](https://github.com/Auburn/FastNoiseLite/wiki#getting-started) and [Documentation](https://github.com/Auburn/FastNoiseLite/wiki/Documentation) pages from its GitHub wiki.

Additional documentation is available at [docs.rs](https://docs.rs/fastnoise-lite/latest/fastnoise_lite/) and the project's [Getting Started](https://github.com/Auburn/FastNoiseLite/wiki#getting-started) and [Documentation](https://github.com/Auburn/FastNoiseLite/wiki/Documentation) pages from its GitHub wiki.
Below is an example for creating a 128x128 array of OpenSimplex2 noise.

```rs
use fastnoise_lite::*;

// Create and configure FastNoise object
// Create and configure the FastNoise object
let mut noise = FastNoiseLite::new();
noise.set_noise_type(Some(NoiseType::OpenSimplex2));

const WIDTH: usize = 128;
const HEIGHT: usize = 128;
let mut noise_data = [[0.; HEIGHT]; WIDTH];

// Gather noise data
// Sample noise pixels
for x in 0..WIDTH {
for y in 0..HEIGHT {
// Assuming `noise.get_noise_2d(x, y)` returns a float, and takes f32 parameters.
// Adapt accordingly if the function signature is different.
noise_data[x][y] = noise.get_noise_2d(x as f32, y as f32);
// Domain warp can optionally be employed to transform the coordinates before sampling:
// let (x, y) = noise.domain_warp_2d(x as f32, y as f32);

let negative_1_to_1 = noise.get_noise_2d(x as f32, y as f32);
// You may want to remap the -1..1 range data to the 0..1 range:
noise_data[x][y] = (neg_1_to_1 + 1.) / 2.;

// (Uses of `as f32` above should become `as f64` if you're using FNL with the "f64" feature flag)
}
}

Expand Down
Loading

0 comments on commit 4603b31

Please sign in to comment.