[orx-noise] Replace hash functions
This commit is contained in:
@@ -29,13 +29,13 @@ fun cubic(seed: Int, x: Double, y: Double, interpolator: (Double) -> Double = ::
|
||||
val ys = interpolator(y - y1.toDouble())
|
||||
|
||||
return cubic(
|
||||
cubic(valCoord2D(seed, x0, y0), valCoord2D(seed, x1, y0), valCoord2D(seed, x2, y0), valCoord2D(seed, x3, y0),
|
||||
cubic(fshash2D(seed, x0, y0), fshash2D(seed, x1, y0), fshash2D(seed, x2, y0), fshash2D(seed, x3, y0),
|
||||
xs),
|
||||
cubic(valCoord2D(seed, x0, y1), valCoord2D(seed, x1, y1), valCoord2D(seed, x2, y1), valCoord2D(seed, x3, y1),
|
||||
cubic(fshash2D(seed, x0, y1), fshash2D(seed, x1, y1), fshash2D(seed, x2, y1), fshash2D(seed, x3, y1),
|
||||
xs),
|
||||
cubic(valCoord2D(seed, x0, y2), valCoord2D(seed, x1, y2), valCoord2D(seed, x2, y2), valCoord2D(seed, x3, y2),
|
||||
cubic(fshash2D(seed, x0, y2), fshash2D(seed, x1, y2), fshash2D(seed, x2, y2), fshash2D(seed, x3, y2),
|
||||
xs),
|
||||
cubic(valCoord2D(seed, x0, y3), valCoord2D(seed, x1, y3), valCoord2D(seed, x2, y3), valCoord2D(seed, x3, y3),
|
||||
cubic(fshash2D(seed, x0, y3), fshash2D(seed, x1, y3), fshash2D(seed, x2, y3), fshash2D(seed, x3, y3),
|
||||
xs),
|
||||
ys) * CUBIC_2D_BOUNDING
|
||||
}
|
||||
|
||||
@@ -35,28 +35,28 @@ fun cubic(seed: Int, x: Double, y: Double, z: Double, interpolator: (Double) ->
|
||||
|
||||
return cubic(
|
||||
cubic(
|
||||
cubic(valCoord3D(seed, x0, y0, z0), valCoord3D(seed, x1, y0, z0), valCoord3D(seed, x2, y0, z0), valCoord3D(seed, x3, y0, z0), xs),
|
||||
cubic(valCoord3D(seed, x0, y1, z0), valCoord3D(seed, x1, y1, z0), valCoord3D(seed, x2, y1, z0), valCoord3D(seed, x3, y1, z0), xs),
|
||||
cubic(valCoord3D(seed, x0, y2, z0), valCoord3D(seed, x1, y2, z0), valCoord3D(seed, x2, y2, z0), valCoord3D(seed, x3, y2, z0), xs),
|
||||
cubic(valCoord3D(seed, x0, y3, z0), valCoord3D(seed, x1, y3, z0), valCoord3D(seed, x2, y3, z0), valCoord3D(seed, x3, y3, z0), xs),
|
||||
cubic(fshash3D(seed, x0, y0, z0), fshash3D(seed, x1, y0, z0), fshash3D(seed, x2, y0, z0), fshash3D(seed, x3, y0, z0), xs),
|
||||
cubic(fshash3D(seed, x0, y1, z0), fshash3D(seed, x1, y1, z0), fshash3D(seed, x2, y1, z0), fshash3D(seed, x3, y1, z0), xs),
|
||||
cubic(fshash3D(seed, x0, y2, z0), fshash3D(seed, x1, y2, z0), fshash3D(seed, x2, y2, z0), fshash3D(seed, x3, y2, z0), xs),
|
||||
cubic(fshash3D(seed, x0, y3, z0), fshash3D(seed, x1, y3, z0), fshash3D(seed, x2, y3, z0), fshash3D(seed, x3, y3, z0), xs),
|
||||
ys),
|
||||
cubic(
|
||||
cubic(valCoord3D(seed, x0, y0, z1), valCoord3D(seed, x1, y0, z1), valCoord3D(seed, x2, y0, z1), valCoord3D(seed, x3, y0, z1), xs),
|
||||
cubic(valCoord3D(seed, x0, y1, z1), valCoord3D(seed, x1, y1, z1), valCoord3D(seed, x2, y1, z1), valCoord3D(seed, x3, y1, z1), xs),
|
||||
cubic(valCoord3D(seed, x0, y2, z1), valCoord3D(seed, x1, y2, z1), valCoord3D(seed, x2, y2, z1), valCoord3D(seed, x3, y2, z1), xs),
|
||||
cubic(valCoord3D(seed, x0, y3, z1), valCoord3D(seed, x1, y3, z1), valCoord3D(seed, x2, y3, z1), valCoord3D(seed, x3, y3, z1), xs),
|
||||
cubic(fshash3D(seed, x0, y0, z1), fshash3D(seed, x1, y0, z1), fshash3D(seed, x2, y0, z1), fshash3D(seed, x3, y0, z1), xs),
|
||||
cubic(fshash3D(seed, x0, y1, z1), fshash3D(seed, x1, y1, z1), fshash3D(seed, x2, y1, z1), fshash3D(seed, x3, y1, z1), xs),
|
||||
cubic(fshash3D(seed, x0, y2, z1), fshash3D(seed, x1, y2, z1), fshash3D(seed, x2, y2, z1), fshash3D(seed, x3, y2, z1), xs),
|
||||
cubic(fshash3D(seed, x0, y3, z1), fshash3D(seed, x1, y3, z1), fshash3D(seed, x2, y3, z1), fshash3D(seed, x3, y3, z1), xs),
|
||||
ys),
|
||||
cubic(
|
||||
cubic(valCoord3D(seed, x0, y0, z2), valCoord3D(seed, x1, y0, z2), valCoord3D(seed, x2, y0, z2), valCoord3D(seed, x3, y0, z2), xs),
|
||||
cubic(valCoord3D(seed, x0, y1, z2), valCoord3D(seed, x1, y1, z2), valCoord3D(seed, x2, y1, z2), valCoord3D(seed, x3, y1, z2), xs),
|
||||
cubic(valCoord3D(seed, x0, y2, z2), valCoord3D(seed, x1, y2, z2), valCoord3D(seed, x2, y2, z2), valCoord3D(seed, x3, y2, z2), xs),
|
||||
cubic(valCoord3D(seed, x0, y3, z2), valCoord3D(seed, x1, y3, z2), valCoord3D(seed, x2, y3, z2), valCoord3D(seed, x3, y3, z2), xs),
|
||||
cubic(fshash3D(seed, x0, y0, z2), fshash3D(seed, x1, y0, z2), fshash3D(seed, x2, y0, z2), fshash3D(seed, x3, y0, z2), xs),
|
||||
cubic(fshash3D(seed, x0, y1, z2), fshash3D(seed, x1, y1, z2), fshash3D(seed, x2, y1, z2), fshash3D(seed, x3, y1, z2), xs),
|
||||
cubic(fshash3D(seed, x0, y2, z2), fshash3D(seed, x1, y2, z2), fshash3D(seed, x2, y2, z2), fshash3D(seed, x3, y2, z2), xs),
|
||||
cubic(fshash3D(seed, x0, y3, z2), fshash3D(seed, x1, y3, z2), fshash3D(seed, x2, y3, z2), fshash3D(seed, x3, y3, z2), xs),
|
||||
ys),
|
||||
cubic(
|
||||
cubic(valCoord3D(seed, x0, y0, z3), valCoord3D(seed, x1, y0, z3), valCoord3D(seed, x2, y0, z3), valCoord3D(seed, x3, y0, z3), xs),
|
||||
cubic(valCoord3D(seed, x0, y1, z3), valCoord3D(seed, x1, y1, z3), valCoord3D(seed, x2, y1, z3), valCoord3D(seed, x3, y1, z3), xs),
|
||||
cubic(valCoord3D(seed, x0, y2, z3), valCoord3D(seed, x1, y2, z3), valCoord3D(seed, x2, y2, z3), valCoord3D(seed, x3, y2, z3), xs),
|
||||
cubic(valCoord3D(seed, x0, y3, z3), valCoord3D(seed, x1, y3, z3), valCoord3D(seed, x2, y3, z3), valCoord3D(seed, x3, y3, z3), xs),
|
||||
cubic(fshash3D(seed, x0, y0, z3), fshash3D(seed, x1, y0, z3), fshash3D(seed, x2, y0, z3), fshash3D(seed, x3, y0, z3), xs),
|
||||
cubic(fshash3D(seed, x0, y1, z3), fshash3D(seed, x1, y1, z3), fshash3D(seed, x2, y1, z3), fshash3D(seed, x3, y1, z3), xs),
|
||||
cubic(fshash3D(seed, x0, y2, z3), fshash3D(seed, x1, y2, z3), fshash3D(seed, x2, y2, z3), fshash3D(seed, x3, y2, z3), xs),
|
||||
cubic(fshash3D(seed, x0, y3, z3), fshash3D(seed, x1, y3, z3), fshash3D(seed, x2, y3, z3), fshash3D(seed, x3, y3, z3), xs),
|
||||
ys),
|
||||
zs) * CUBIC_3D_BOUNDING
|
||||
}
|
||||
|
||||
@@ -20,43 +20,24 @@ private val GRAD_3D = arrayOf(
|
||||
Vector3(1.0, 1.0, 0.0), Vector3(0.0, -1.0, 1.0), Vector3(-1.0, 1.0, 0.0), Vector3(0.0, -1.0, -1.0))
|
||||
|
||||
fun gradCoord2D(seed: Int, x: Int, y: Int, xd: Double, yd: Double): Double {
|
||||
var hash = seed
|
||||
hash = hash xor X_PRIME * x
|
||||
hash = hash xor Y_PRIME * y
|
||||
val hash = uhash2D(seed, x, y)
|
||||
|
||||
hash = hash * hash * hash * 60493
|
||||
hash = hash shr 13 xor hash
|
||||
|
||||
val (x1, y1) = GRAD_2D[hash and 7]
|
||||
val (x1, y1) = GRAD_2D[(hash and 7U).toInt()]
|
||||
|
||||
return xd * x1 + yd * y1
|
||||
}
|
||||
|
||||
fun gradCoord3D(seed: Int, x: Int, y: Int, z: Int, xd: Double, yd: Double, zd: Double): Double {
|
||||
var hash = seed
|
||||
hash = hash xor X_PRIME * x
|
||||
hash = hash xor Y_PRIME * y
|
||||
hash = hash xor Z_PRIME * z
|
||||
val hash = uhash3D(seed, x, y, z)
|
||||
|
||||
hash *= hash * hash * 60493
|
||||
hash = hash shr 13 xor hash
|
||||
|
||||
val g = GRAD_3D[hash and 15]
|
||||
val g = GRAD_3D[(hash and 15U).toInt()]
|
||||
|
||||
return xd * g.x + yd * g.y + zd * g.z
|
||||
}
|
||||
|
||||
fun gradCoord4D(seed: Int, x: Int, y: Int, z: Int, w: Int, xd: Double, yd: Double, zd: Double, wd: Double): Double {
|
||||
var hash = seed
|
||||
hash = hash xor X_PRIME * x
|
||||
hash = hash xor Y_PRIME * y
|
||||
hash = hash xor Z_PRIME * z
|
||||
hash = hash xor W_PRIME * w
|
||||
val hash = (uhash4D(seed, x, y, z, w) and 31U).toInt()
|
||||
|
||||
hash = hash * hash * hash * 60493
|
||||
hash = hash shr 13 xor hash
|
||||
|
||||
hash = hash and 31
|
||||
var a = yd
|
||||
var b = zd
|
||||
var c = wd // X,Y,Z
|
||||
@@ -83,57 +64,6 @@ fun gradCoord4D(seed: Int, x: Int, y: Int, z: Int, w: Int, xd: Double, yd: Doubl
|
||||
return (if (hash and 4 == 0) -a else a) + (if (hash and 2 == 0) -b else b) + if (hash and 1 == 0) -c else c
|
||||
}
|
||||
|
||||
|
||||
fun hash2D(seed: Int, x: Int, y: Int): Int {
|
||||
var hash = seed
|
||||
hash = hash xor X_PRIME * x
|
||||
hash = hash xor Y_PRIME * y
|
||||
|
||||
hash = hash * hash * hash * 60493
|
||||
hash = hash shr 13 xor hash
|
||||
|
||||
return hash
|
||||
}
|
||||
|
||||
fun hash3D(seed: Int, x: Int, y: Int, z: Int): Int {
|
||||
var hash = seed
|
||||
hash = hash xor X_PRIME * x
|
||||
hash = hash xor Y_PRIME * y
|
||||
hash = hash xor Z_PRIME * z
|
||||
|
||||
hash = hash * hash * hash * 60493
|
||||
hash = hash shr 13 xor hash
|
||||
|
||||
return hash
|
||||
}
|
||||
|
||||
fun hash4D(seed: Int, x: Int, y: Int, z: Int, w: Int): Int {
|
||||
var hash = seed
|
||||
hash = hash xor X_PRIME * x
|
||||
hash = hash xor Y_PRIME * y
|
||||
hash = hash xor Z_PRIME * z
|
||||
hash = hash xor W_PRIME * w
|
||||
|
||||
hash = hash * hash * hash * 60493
|
||||
hash = hash shr 13 xor hash
|
||||
return hash
|
||||
}
|
||||
|
||||
|
||||
fun valCoord1D(seed: Int, x: Int): Double {
|
||||
var n = seed
|
||||
n = n xor X_PRIME * x
|
||||
return n * n * n * 60493 / 2147483648.0
|
||||
}
|
||||
|
||||
fun valCoord2D(seed: Int, x: Int, y: Int): Double {
|
||||
var n = seed
|
||||
n = n xor X_PRIME * x
|
||||
n = n xor Y_PRIME * y
|
||||
|
||||
return n * n * n * 60493 / 2147483648.0
|
||||
}
|
||||
|
||||
fun valCoord3D(seed: Int, x: Int, y: Int, z: Int): Double {
|
||||
var n = seed
|
||||
n = n xor X_PRIME * x
|
||||
|
||||
@@ -4,9 +4,11 @@ import org.openrndr.math.Vector2
|
||||
import org.openrndr.math.Vector3
|
||||
import org.openrndr.math.mix
|
||||
|
||||
fun gradientPerturbFractal(seed: Int, amplitude: Double = 1.0, frequency: Double = 2.0,
|
||||
lacunarity: Double = 2.0, gain: Double = 0.5,
|
||||
octaves: Int = 4, position: Vector3, interpolator: (Double) -> Double = ::quintic): Vector3 {
|
||||
fun gradientPerturbFractal(
|
||||
seed: Int, amplitude: Double = 1.0, frequency: Double = 2.0,
|
||||
lacunarity: Double = 2.0, gain: Double = 0.5,
|
||||
octaves: Int = 4, position: Vector3, interpolator: (Double) -> Double = ::quintic
|
||||
): Vector3 {
|
||||
|
||||
var seed_ = seed
|
||||
var amplitude_ = amplitude
|
||||
@@ -22,7 +24,13 @@ fun gradientPerturbFractal(seed: Int, amplitude: Double = 1.0, frequency: Double
|
||||
return p
|
||||
}
|
||||
|
||||
fun gradientPerturb(seed: Int, amplitude: Double, frequency: Double, position: Vector3, interpolator: (Double) -> Double = ::quintic): Vector3 {
|
||||
fun gradientPerturb(
|
||||
seed: Int,
|
||||
amplitude: Double,
|
||||
frequency: Double,
|
||||
position: Vector3,
|
||||
interpolator: (Double) -> Double = ::quintic
|
||||
): Vector3 {
|
||||
val xf = position.x * frequency
|
||||
val yf = position.y * frequency
|
||||
val zf = position.z * frequency
|
||||
@@ -38,15 +46,15 @@ fun gradientPerturb(seed: Int, amplitude: Double, frequency: Double, position: V
|
||||
val ys = interpolator(yf - y0)
|
||||
val zs = interpolator(zf - z0)
|
||||
|
||||
var vec0 = Cell3D[hash3D(seed, x0, y0, z0) and 0xff]
|
||||
var vec1 = Cell3D[hash3D(seed, x1, y0, z0) and 0xff]
|
||||
var vec0 = Cell3D[(uhash3D(seed, x0, y0, z0) and 0xffU).toInt()]
|
||||
var vec1 = Cell3D[(uhash3D(seed, x1, y0, z0) and 0xffU).toInt()]
|
||||
|
||||
var lx0x = mix(vec0.x, vec1.x, xs)
|
||||
var ly0x = mix(vec0.y, vec1.y, xs)
|
||||
var lz0x = mix(vec0.z, vec1.z, xs)
|
||||
|
||||
vec0 = Cell3D[hash3D(seed, x0, y1, z0) and 0xff]
|
||||
vec1 = Cell3D[hash3D(seed, x1, y1, z0) and 0xff]
|
||||
vec0 = Cell3D[(uhash3D(seed, x0, y1, z0) and 0xffU).toInt()]
|
||||
vec1 = Cell3D[(uhash3D(seed, x1, y1, z0) and 0xffU).toInt()]
|
||||
|
||||
var lx1x = mix(vec0.x, vec1.x, xs)
|
||||
var ly1x = mix(vec0.y, vec1.y, xs)
|
||||
@@ -56,30 +64,32 @@ fun gradientPerturb(seed: Int, amplitude: Double, frequency: Double, position: V
|
||||
val ly0y = mix(ly0x, ly1x, ys)
|
||||
val lz0y = mix(lz0x, lz1x, ys)
|
||||
|
||||
vec0 = Cell3D[hash3D(seed, x0, y0, z1) and 0xff]
|
||||
vec1 = Cell3D[hash3D(seed, x1, y0, z1) and 0xff]
|
||||
vec0 = Cell3D[(uhash3D(seed, x0, y0, z1) and 0xffU).toInt()]
|
||||
vec1 = Cell3D[(uhash3D(seed, x1, y0, z1) and 0xffU).toInt()]
|
||||
|
||||
lx0x = mix(vec0.x, vec1.x, xs)
|
||||
ly0x = mix(vec0.y, vec1.y, xs)
|
||||
lz0x = mix(vec0.z, vec1.z, xs)
|
||||
|
||||
vec0 = Cell3D[hash3D(seed, x0, y1, z1) and 0xff]
|
||||
vec1 = Cell3D[hash3D(seed, x1, y1, z1) and 0xff]
|
||||
vec0 = Cell3D[(uhash3D(seed, x0, y1, z1) and 0xffU).toInt()]
|
||||
vec1 = Cell3D[(uhash3D(seed, x1, y1, z1) and 0xffU).toInt()]
|
||||
|
||||
lx1x = mix(vec0.x, vec1.x, xs)
|
||||
ly1x = mix(vec0.y, vec1.y, xs)
|
||||
lz1x = mix(vec0.z, vec1.z, xs)
|
||||
|
||||
return position + Vector3(
|
||||
mix(lx0y, mix(lx0x, lx1x, ys), zs),
|
||||
mix(ly0y, mix(ly0x, ly1x, ys), zs),
|
||||
mix(lz0y, mix(lz0x, lz1x, ys), zs)
|
||||
mix(lx0y, mix(lx0x, lx1x, ys), zs),
|
||||
mix(ly0y, mix(ly0x, ly1x, ys), zs),
|
||||
mix(lz0y, mix(lz0x, lz1x, ys), zs)
|
||||
) * amplitude
|
||||
}
|
||||
|
||||
fun gradientPerturbFractal(seed: Int, amplitude: Double = 1.0, frequency: Double = 2.0,
|
||||
lacunarity: Double = 2.0, gain: Double = 0.5,
|
||||
octaves: Int = 4, position: Vector2, interpolator: (Double) -> Double = ::quintic): Vector2 {
|
||||
fun gradientPerturbFractal(
|
||||
seed: Int, amplitude: Double = 1.0, frequency: Double = 2.0,
|
||||
lacunarity: Double = 2.0, gain: Double = 0.5,
|
||||
octaves: Int = 4, position: Vector2, interpolator: (Double) -> Double = ::quintic
|
||||
): Vector2 {
|
||||
|
||||
var seed_ = seed
|
||||
var amplitude_ = amplitude
|
||||
@@ -95,7 +105,13 @@ fun gradientPerturbFractal(seed: Int, amplitude: Double = 1.0, frequency: Double
|
||||
return p
|
||||
}
|
||||
|
||||
fun gradientPerturb(seed: Int, amplitude: Double, frequency: Double, position: Vector2, interpolator: (Double) -> Double = ::quintic): Vector2 {
|
||||
fun gradientPerturb(
|
||||
seed: Int,
|
||||
amplitude: Double,
|
||||
frequency: Double,
|
||||
position: Vector2,
|
||||
interpolator: (Double) -> Double = ::quintic
|
||||
): Vector2 {
|
||||
val xf = position.x * frequency
|
||||
val yf = position.y * frequency
|
||||
val x0 = xf.fastFloor()
|
||||
@@ -106,21 +122,21 @@ fun gradientPerturb(seed: Int, amplitude: Double, frequency: Double, position: V
|
||||
val xs = interpolator(xf - x0)
|
||||
val ys = interpolator(yf - y0)
|
||||
|
||||
var vec0 = Cell2D[hash2D(seed, x0, y0) and 0xff]
|
||||
var vec1 = Cell2D[hash2D(seed, x1, y0) and 0xff]
|
||||
var vec0 = Cell2D[(uhash2D(seed, x0, y0) and 0xffU).toInt()]
|
||||
var vec1 = Cell2D[(uhash2D(seed, x1, y0) and 0xffU).toInt()]
|
||||
|
||||
val lx0x = mix(vec0.x, vec1.x, xs)
|
||||
val ly0x = mix(vec0.y, vec1.y, xs)
|
||||
|
||||
vec0 = Cell2D[hash2D(seed, x0, y1) and 0xff]
|
||||
vec1 = Cell2D[hash2D(seed, x1, y1) and 0xff]
|
||||
vec0 = Cell2D[(uhash2D(seed, x0, y1) and 0xffU).toInt()]
|
||||
vec1 = Cell2D[(uhash2D(seed, x1, y1) and 0xffU).toInt()]
|
||||
|
||||
val lx1x = mix(vec0.x, vec1.x, xs)
|
||||
val ly1x = mix(vec0.y, vec1.y, xs)
|
||||
|
||||
return position + Vector2(
|
||||
mix(lx0x, lx1x, ys),
|
||||
mix(ly0x, ly1x, ys)
|
||||
mix(lx0x, lx1x, ys),
|
||||
mix(ly0x, ly1x, ys)
|
||||
) * amplitude
|
||||
|
||||
}
|
||||
41
orx-noise/src/commonMain/kotlin/UHash.kt
Normal file
41
orx-noise/src/commonMain/kotlin/UHash.kt
Normal file
@@ -0,0 +1,41 @@
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
/**
|
||||
* uniform hash function
|
||||
* https://nullprogram.com/blog/2018/07/31/
|
||||
*/
|
||||
fun uhash11(x: UInt): UInt {
|
||||
var a = x
|
||||
a = a xor (a shr 16)
|
||||
a *= 0x7feb352du
|
||||
a = a xor (a shr 15)
|
||||
a *= 0x846ca68bu
|
||||
a = a xor (a shr 16)
|
||||
return a
|
||||
}
|
||||
|
||||
fun uhash1D(seed: Int, x: Int): UInt = uhash11(seed.toUInt() + uhash11(x.toUInt()))
|
||||
fun uhash2D(seed: Int, x: Int, y: Int): UInt = uhash11(seed.toUInt() + uhash11(y.toUInt() + uhash11(x.toUInt())))
|
||||
fun uhash3D(seed: Int, x: Int, y: Int, z: Int): UInt =
|
||||
uhash11(seed.toUInt() + uhash11(z.toUInt() + uhash11(x.toUInt() + uhash11(y.toUInt()))))
|
||||
|
||||
fun uhash4D(seed: Int, x: Int, y: Int, z: Int, w: Int): UInt =
|
||||
uhash11(seed.toUInt() + uhash11(z.toUInt() + uhash11(z.toUInt() + uhash11(x.toUInt() + uhash11(y.toUInt())))))
|
||||
|
||||
|
||||
fun fhash1D(seed: Int, x: Int): Double = uhash1D(seed, x).toDouble() / UInt.MAX_VALUE.toDouble()
|
||||
fun fhash2D(seed: Int, x: Int, y: Int): Double = uhash2D(seed, x, y).toDouble() / UInt.MAX_VALUE.toDouble()
|
||||
fun fhash3D(seed: Int, x: Int, y: Int, z: Int): Double =
|
||||
uhash3D(seed, x, y, z).toDouble() / UInt.MAX_VALUE.toDouble()
|
||||
|
||||
fun fhash4D(seed: Int, x: Int, y: Int, z: Int, w :Int): Double =
|
||||
uhash4D(seed, x, y, z, w).toDouble() / UInt.MAX_VALUE.toDouble()
|
||||
|
||||
|
||||
fun fshash1D(seed: Int, x: Int): Double = 2.0 * uhash1D(seed, x).toDouble() / UInt.MAX_VALUE.toDouble() - 1.0
|
||||
fun fshash2D(seed: Int, x: Int, y: Int): Double = 2.0 * uhash2D(seed, x, y).toDouble() / UInt.MAX_VALUE.toDouble() - 1.0
|
||||
fun fshash3D(seed: Int, x: Int, y: Int, z: Int): Double =
|
||||
2.0*uhash3D(seed, x, y, z).toDouble() / UInt.MAX_VALUE.toDouble() - 1.0
|
||||
|
||||
fun fshash4D(seed: Int, x: Int, y: Int, z: Int, w :Int): Double =
|
||||
2.0 * uhash4D(seed, x, y, z, w).toDouble() / UInt.MAX_VALUE.toDouble() - 1.0
|
||||
@@ -25,8 +25,8 @@ inline fun value(seed: Int, x: Double, y: Double, crossinline interpolation: (Do
|
||||
val xs = interpolation(x - x0)
|
||||
val ys = interpolation(y - y0)
|
||||
|
||||
val xf0 = mix(valCoord2D(seed, x0, y0), valCoord2D(seed, x1, y0), xs)
|
||||
val xf1 = mix(valCoord2D(seed, x0, y1), valCoord2D(seed, x1, y1), xs)
|
||||
val xf0 = mix(fshash2D(seed, x0, y0), fshash2D(seed, x1, y0), xs)
|
||||
val xf1 = mix(fshash2D(seed, x0, y1), fshash2D(seed, x1, y1), xs)
|
||||
|
||||
return mix(xf0, xf1, ys)
|
||||
}
|
||||
|
||||
@@ -28,11 +28,11 @@ inline fun value(seed: Int, x: Double, y: Double, z: Double, crossinline interpo
|
||||
val ys = interpolation(y - y0)
|
||||
val zs = interpolation(z - z0)
|
||||
|
||||
val xf00 = mix(fshash3D(seed, x0, y0, z0), fshash3D(seed, x1, y0, z0), xs)
|
||||
val xf10 = mix(fshash3D(seed, x0, y1, z0), fshash3D(seed, x1, y1, z0), xs)
|
||||
val xf01 = mix(fshash3D(seed, x0, y0, z1), fshash3D(seed, x1, y0, z1), xs)
|
||||
val xf11 = mix(fshash3D(seed, x0, y1, z1), fshash3D(seed, x1, y1, z1), xs)
|
||||
|
||||
val xf00 = mix(valCoord3D(seed, x0, y0, z0), valCoord3D(seed, x1, y0, z0), xs)
|
||||
val xf10 = mix(valCoord3D(seed, x0, y1, z0), valCoord3D(seed, x1, y1, z0), xs)
|
||||
val xf01 = mix(valCoord3D(seed, x0, y0, z1), valCoord3D(seed, x1, y0, z1), xs)
|
||||
val xf11 = mix(valCoord3D(seed, x0, y1, z1), valCoord3D(seed, x1, y1, z1), xs)
|
||||
|
||||
val yf0 = mix(xf00, xf10, ys)
|
||||
val yf1 = mix(xf01, xf11, ys)
|
||||
|
||||
21
orx-noise/src/jvmDemo/kotlin/DemoCubicNoise2D01.kt
Normal file
21
orx-noise/src/jvmDemo/kotlin/DemoCubicNoise2D01.kt
Normal file
@@ -0,0 +1,21 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.noise.*
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
extend {
|
||||
drawer.points {
|
||||
for (y in 0 until height) {
|
||||
for (x in 0 until width) {
|
||||
val c = cubicHermite3D(100, (x + y) * 0.04, (x - y) * 0.04, seconds * 1.0) * 0.5 + 0.5
|
||||
fill = ColorRGBa(c, c, c, 1.0)
|
||||
point(x.toDouble(), y.toDouble())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
26
orx-noise/src/jvmDemo/kotlin/DemoUHash01.kt
Normal file
26
orx-noise/src/jvmDemo/kotlin/DemoUHash01.kt
Normal file
@@ -0,0 +1,26 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.drawImage
|
||||
import org.openrndr.extra.noise.*
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
|
||||
|
||||
extend {
|
||||
drawer.points {
|
||||
for (y in 0 until height) {
|
||||
for (x in 0 until width) {
|
||||
val c = fhash3D(100, x + (seconds*60.0).toInt(), y, (0).toInt())
|
||||
//val u = uhash11(x.toUInt()).toDouble() / UInt.MAX_VALUE.toDouble()
|
||||
fill = ColorRGBa(c, c, c, 1.0)
|
||||
point(x.toDouble(), y.toDouble())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
21
orx-noise/src/jvmDemo/kotlin/DemoValueNoise2D01.kt
Normal file
21
orx-noise/src/jvmDemo/kotlin/DemoValueNoise2D01.kt
Normal file
@@ -0,0 +1,21 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.noise.*
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
extend {
|
||||
drawer.points {
|
||||
for (y in 0 until height) {
|
||||
for (x in 0 until width) {
|
||||
val c = valueQuintic3D(100, (x + y) * 0.04, (x - y) * 0.04, seconds * 0.1) * 0.5 + 0.5
|
||||
fill = ColorRGBa(c, c, c, 1.0)
|
||||
point(x.toDouble(), y.toDouble())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user