Files
orx/orx-noise/src/jvmDemo/kotlin/rseq/DemoRseq4D01.kt
Abe Pazos c85144c6fe [orx-noise] Tidy up demos
Produce 720px wide images.
Use main() = application { for reduced indentation
2025-01-24 21:47:44 +01:00

53 lines
1.9 KiB
Kotlin

package rseq
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.sphereMesh
import org.openrndr.extra.noise.rsequence.rSeq3D
import org.openrndr.extra.noise.rsequence.rSeq4D
import org.openrndr.math.Vector3
import org.openrndr.math.Vector4
import kotlin.math.abs
import kotlin.math.min
/**
* Demo that presents a 3D visualization of points distributed using a 4D quasirandom sequence (R4).
* Each point is represented as a sphere with it position and color derived from the sequence values.
*
* This function performs the following tasks:
* - Configures the application window dimensions to 720x720 pixels.
* - Initializes a 3D camera for orbital navigation of the scene.
* - Generates 10,000 points in 4D space using the `rSeq4D` function. The points are scaled
* and transformed into 3D positions with an additional w-coordinate for color variation.
* - Creates a reusable sphere mesh for rendering.
* - Renders each point as a sphere with its position determined by the 3D coordinates
* of the point and its color calculated by shifting the hue of a base color using
* the w-coordinate value.
*/
fun main() = application {
configure {
width = 720
height = 720
}
program {
val sphere = sphereMesh(radius = 0.1)
val points = (0 until 10000).map {
(rSeq4D(it) - Vector4(0.5, 0.5, 0.5, 0.0)) * Vector4(10.0, 10.0, 10.0, 1.0)
}
extend(Orbital())
extend {
for (point in points) {
drawer.isolated {
drawer.translate(point.xyz)
drawer.fill = ColorRGBa.RED.toHSVa().shiftHue(point.w * 360.0).toRGBa()
drawer.vertexBuffer(sphere, DrawPrimitive.TRIANGLES)
}
}
}
}
}