[orx-noise] Add hash functions

This commit is contained in:
Edwin Jakobs
2024-10-20 14:14:50 +02:00
parent 6e1e161726
commit fba1e5b61a
23 changed files with 473 additions and 63 deletions

View File

@@ -0,0 +1,24 @@
package org.openrndr.extra.noise.shapes
import org.openrndr.extra.noise.uhash11
import org.openrndr.math.Vector2
import org.openrndr.shape.Rectangle
import kotlin.random.Random
fun Rectangle.uniform(random: Random = Random.Default): Vector2 {
val x = random.nextDouble() * width + corner.x
val y = random.nextDouble() * height + corner.y
return Vector2(x, y)
}
fun Rectangle.hash(seed: Int, x: Int): Vector2 {
val ux = uhash11(seed.toUInt() + uhash11(x.toUInt()))
val uy = uhash11(ux + x.toUInt())
val fx = ux.toDouble() / UInt.MAX_VALUE.toDouble()
val fy = uy.toDouble() / UInt.MAX_VALUE.toDouble()
val x = fx * width + corner.x
val y = fy * height + corner.y
return Vector2(x, y)
}