Skip to content

Commit

Permalink
[orx-noise] Add tools for functional composition
Browse files Browse the repository at this point in the history
  • Loading branch information
edwinRNDR committed Jul 25, 2021
1 parent c388cbe commit 454affb
Show file tree
Hide file tree
Showing 15 changed files with 535 additions and 77 deletions.
21 changes: 21 additions & 0 deletions orx-noise/README.md
Expand Up @@ -26,6 +26,27 @@ val v4ur = Vector4.uniformRing(0.5, 1.0)
val ringSamples = List(500) { Vector2.uniformRing() }
```

## Noise function composition

Since ORX 0.4 the orx-noise module comes with functional composition tooling that allow one to create complex noise
functions.

```kotlin
// create an FBM version of 1D linear perlin noise
val myNoise0 = perlinLinear1D.fbm(octaves=3)
val noiseValue0 = myNoise0(431, seconds)

// create polar version of 2D simplex noise
val myNoise1 = simplex2D.withPolarInput()
val noiseValue1 = myNoise1(5509, Polar(seconds*60.0, 0.5))

// create value linear noise with squared outputs which is then billowed
val myNoise2 = valueLinear1D.mapOutput { it * it }.billow()
val noiseValue2 = myNoise2(993, seconds * 0.1)
```



## Multi-dimensional noise

These are a mostly straight port from FastNoise-Java but have a slightly different interface.
Expand Down
6 changes: 5 additions & 1 deletion orx-noise/src/commonMain/kotlin/CubicNoise1D.kt
Expand Up @@ -7,4 +7,8 @@ fun cubicHermite(seed: Int, x: Double) = cubic(seed, x, ::hermite)

fun cubic(seed: Int, x: Double, interpolator: (Double) -> Double = ::linear): Double {
return cubic(seed, x, 0.0, interpolator)
}
}

val cubicLinear1D: (Int, Double) -> Double = ::cubicLinear
val cubicQuintic1D: (Int, Double) -> Double = ::cubicQuintic
val cubicHermite1D: (Int, Double) -> Double = ::cubicHermite
6 changes: 5 additions & 1 deletion orx-noise/src/commonMain/kotlin/CubicNoise2D.kt
Expand Up @@ -38,4 +38,8 @@ fun cubic(seed: Int, x: Double, y: Double, interpolator: (Double) -> Double = ::
cubic(valCoord2D(seed, x0, y3), valCoord2D(seed, x1, y3), valCoord2D(seed, x2, y3), valCoord2D(seed, x3, y3),
xs),
ys) * CUBIC_2D_BOUNDING
}
}

val cubicLinear2D: (Int, Double, Double) -> Double = ::cubicLinear
val cubicQuintic2D: (Int, Double, Double) -> Double = ::cubicQuintic
val cubicHermite2D: (Int, Double, Double) -> Double = ::cubicHermite
6 changes: 5 additions & 1 deletion orx-noise/src/commonMain/kotlin/CubicNoise3D.kt
Expand Up @@ -59,4 +59,8 @@ fun cubic(seed: Int, x: Double, y: Double, z: Double, interpolator: (Double) ->
cubic(valCoord3D(seed, x0, y3, z3), valCoord3D(seed, x1, y3, z3), valCoord3D(seed, x2, y3, z3), valCoord3D(seed, x3, y3, z3), xs),
ys),
zs) * CUBIC_3D_BOUNDING
}
}

val cubicLinear3D: (Int, Double, Double, Double) -> Double = ::cubicLinear
val cubicQuintic3D: (Int, Double, Double, Double) -> Double = ::cubicQuintic
val cubicHermite3D: (Int, Double, Double, Double) -> Double = ::cubicHermite

0 comments on commit 454affb

Please sign in to comment.