Added orx-camera and orx-noise

This commit is contained in:
Edwin Jakobs
2018-12-03 16:06:30 +01:00
parent 414a0fcc95
commit 342de1aff9
8 changed files with 401 additions and 1 deletions

28
orx-noise/README.md Normal file
View File

@@ -0,0 +1,28 @@
# orx-noise
A collection of noisy functions
## Uniform random numbers
```kotlin
val sua = Double.uniform()
val sub = Double.uniform(-1.0, 1.0)
val v2ua = Vector2.uniform()
val v2ub = Vector2.uniform(-1.0, 1.0)
val v2uc = Vector2.uniform(Vector2(0.0, 0.0), Vector2(1.0, 1.0))
val v2ur = Vector2.uniformRing(0.5, 1.0)
val v3ua = Vector3.uniform()
val v3ub = Vector3.uniform(-1.0, 1.0)
val v3uc = Vector3.uniform(Vector3(0.0, 0.0, 0.0), Vector3(1.0, 1.0, 1.0))
val v3ur = Vector3.uniformRing(0.5, 1.0)
val v4ua = Vector4.uniform()
val v4ub = Vector4.uniform(-1.0, 1.0)
val v4uc = Vector4.uniform(Vector4(0.0, 0.0, 0.0, 0.0), Vector4(1.0, 1.0, 1.0, 1.0))
val v4ur = Vector4.uniformRing(0.5, 1.0)
val ringSamples = List(500) { Vector2.uniformRing() }
```

View File

@@ -0,0 +1,71 @@
package org.openrndr.extra.noise
import org.openrndr.math.Vector2
import org.openrndr.math.Vector3
import org.openrndr.math.Vector4
fun Double.Companion.uniform(min: Double = -1.0, max: Double = 1.0): Double {
return (Math.random() * (max - min)) + min
}
fun Vector2.Companion.uniform(min: Vector2 = -ONE, max: Vector2 = ONE): Vector2 {
return Vector2(Double.uniform(min.x, max.x), Double.uniform(min.y, max.y))
}
fun Vector2.Companion.uniform(min: Double = -1.0, max: Double = 1.0) =
Vector2.uniform(Vector2(min, min), Vector2(max, max))
fun Vector2.Companion.uniformRing(innerRadius: Double = 0.0, outerRadius: Double = 1.0): Vector2 {
while (true) {
uniform(-outerRadius, outerRadius).let {
val squaredLength = it.squaredLength
if (squaredLength >= innerRadius * innerRadius && squaredLength < outerRadius * outerRadius) {
return it
}
}
}
}
fun Vector3.Companion.uniform(min: Double = -1.0, max: Double = 1.0): Vector3 =
Vector3.uniform(Vector3(min, min, min), Vector3(max, max, max))
fun Vector3.Companion.uniform(min: Vector3 = -ONE, max: Vector3 = ONE): Vector3 {
return Vector3(Double.uniform(min.x, max.x), Double.uniform(min.y, max.y), Double.uniform(min.z, max.z))
}
// squared length 'polyfill' for OPENRNDR 0.3.30
private val Vector3.squaredLength__: Double get() = x * x + y * y + z * z
fun Vector3.Companion.uniformRing(innerRadius: Double = 0.0, outerRadius: Double = 1.0): Vector3 {
while (true) {
uniform(-outerRadius, outerRadius).let {
val squaredLength = it.squaredLength__
if (squaredLength >= innerRadius * innerRadius && squaredLength < outerRadius * outerRadius) {
return it
}
}
}
}
// squared length 'polyfill' for OPENRNDR 0.3.30
private val Vector4.squaredLength__: Double get() = x * x + y * y + z * z + w * w
fun Vector4.Companion.uniform(min: Double = -1.0, max: Double = 1.0): Vector4 =
Vector4.uniform(Vector4(min, min, min, min), Vector4(max, max,max, max))
fun Vector4.Companion.uniform(min: Vector4 = -ONE, max: Vector4 = ONE): Vector4 {
return Vector4(Double.uniform(min.x, max.x), Double.uniform(min.y, max.y), Double.uniform(min.z, max.z), Double.uniform(min.w, max.w))
}
fun Vector4.Companion.uniformRing(innerRadius: Double = 0.0, outerRadius: Double = 1.0): Vector4 {
while (true) {
uniform(-outerRadius, outerRadius).let {
val squaredLength = it.squaredLength__
if (squaredLength >= innerRadius * innerRadius && squaredLength < outerRadius * outerRadius) {
return it
}
}
}
}