[orx-math] Add orx-math module

This commit is contained in:
Edwin Jakobs
2025-02-02 11:24:39 +01:00
parent 13bc4bc472
commit c88c4454e1
10 changed files with 555 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
package linearrange
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.isolated
import org.openrndr.extra.math.linearrange.rangeTo
import org.openrndr.math.Vector2
import org.openrndr.shape.Rectangle
import kotlin.math.cos
import kotlin.math.sin
fun main() {
application {
configure {
width = 720
height = 720
}
program {
val range = Rectangle.fromCenter(Vector2(36.0, 36.0), 72.0, 18.0)..
Rectangle.fromCenter(Vector2(36.0, 36.0), 18.0, 72.0)
extend {
drawer.fill = ColorRGBa.PINK.opacify(0.9)
drawer.stroke = null
for (y in 0 until height step 72) {
for (x in 0 until width step 72) {
val u = cos(seconds + x * 0.007) * 0.5 + 0.5
val s = sin(seconds*1.03 + y * 0.0075) * 0.5 + 0.5
drawer.isolated {
drawer.translate(x.toDouble(), y.toDouble())
drawer.rectangle(range.value(u * s))
}
}
}
}
}
}
}

View File

@@ -0,0 +1,41 @@
package linearrange
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.isolated
import org.openrndr.extra.math.linearrange.rangeTo
import org.openrndr.math.Vector2
import org.openrndr.shape.Rectangle
import kotlin.math.cos
import kotlin.math.sin
fun main() {
application {
configure {
width = 720
height = 720
}
program {
val range0 = Rectangle.fromCenter(Vector2(36.0, 36.0), 72.0, 18.0)..
Rectangle.fromCenter(Vector2(36.0, 36.0), 18.0, 72.0)
val range1 = Rectangle.fromCenter(Vector2(36.0, 0.0), 9.0, 9.0)..
Rectangle.fromCenter(Vector2(36.0, 72.0), 9.0, 9.0)
val range = range0..range1
extend {
drawer.fill = ColorRGBa.PINK.opacify(0.9)
drawer.stroke = null
for (y in 0 until height step 72) {
for (x in 0 until width step 72) {
val u = cos(seconds* 2.0 + x * 0.01) * 0.5 + 0.5
val v = sin(seconds * 1.03 + y * 0.01) * 0.5 + 0.5
drawer.isolated {
drawer.translate(x.toDouble(), y.toDouble())
drawer.rectangle(range.value(u, v))
}
}
}
}
}
}
}

View File

@@ -0,0 +1,45 @@
package simplexrange
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.DrawPrimitive
import org.openrndr.draw.isolated
import org.openrndr.extra.camera.Orbital
import org.openrndr.extra.meshgenerators.boxMesh
import org.openrndr.extra.math.simplexrange.SimplexRange3D
import org.openrndr.math.Vector3
fun main() {
application {
configure {
width = 720
height = 720
}
program {
val box = boxMesh()
extend(Orbital()) {
eye = Vector3(1.0, -1.0, 1.0).normalized * 140.0
fov = 15.0
}
extend {
val sr = SimplexRange3D(
ColorRGBa.PINK.toLinear(),
ColorRGBa.RED.toLinear(),
ColorRGBa.MAGENTA.toLinear(),
ColorRGBa.BLUE.toLinear()
)
for (z in 0 until 20)
for (y in 0 until 20)
for (x in 0 until 20) {
drawer.isolated {
drawer.translate(x - 10.0, y - 10.0, z - 10.0)
drawer.fill = sr.value(x / 20.0, y / 20.0, z / 20.0)
drawer.vertexBuffer(box, DrawPrimitive.TRIANGLES)
}
}
}
}
}
}