[orx-noise] Add Rseq and Hammersley sequences

This commit is contained in:
Edwin Jakobs
2025-01-24 11:34:49 +01:00
parent c059b11841
commit c7b81feb5e
9 changed files with 397 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
package hammersley
import org.openrndr.application
import org.openrndr.extra.noise.hammersley.hammersley2D
/**
* Demo that visualizes a 2D Hammersley point set.
*
* The application is configured to run at 720x720 resolution. The program computes
* 400 2D Hammersley points mapped within the bounds of the application's resolution.
* These points are visualized by rendering circles at their respective positions.
*/
fun main() {
application {
configure {
width = 720
height = 720
}
program {
extend {
val points = (0 until 400).map {
hammersley2D(it, 400) * 720.0
}
drawer.circles(points, 5.0)
}
}
}
}

View File

@@ -0,0 +1,46 @@
package hammersley
import org.openrndr.application
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.hammersley.hammersley3D
import org.openrndr.math.Vector3
/**
* Demo program rendering a 3D visualization of points distributed using the Hammersley sequence in 3D space.
*
* The application is set up at a resolution of 720x720 pixels. Within the visual
* program, a sphere mesh is created and a set of 1400 points is generated using
* the Hammersley sequence. Each point is translated and rendered as a small sphere
* in 3D space. This is achieved by mapping the generated points into a scaled domain.
*
* The rendering utilizes the Orbital extension, enabling an interactive 3D camera
* to navigate the scene. The visualization relies on the draw loop for continuous
* rendering of the points.
*/
fun main() {
application {
configure {
width = 720
height = 720
}
program {
val sphere = sphereMesh(radius = 0.1)
extend(Orbital())
extend {
val points = (0 until 1400).map {
(hammersley3D(it, 1400) - Vector3(0.5)) * 10.0
}
for (point in points) {
drawer.isolated {
drawer.translate(point)
drawer.vertexBuffer(sphere, DrawPrimitive.TRIANGLES)
}
}
}
}
}
}

View File

@@ -0,0 +1,52 @@
package hammersley
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.hammersley.hammersley4D
import org.openrndr.extra.noise.rsequence.rSeq4D
import org.openrndr.math.Vector4
import kotlin.math.abs
import kotlin.math.min
/**
* Demo that visualizes a 4D Hammersley point set in a 3D space, with colors determined by the 4th dimension.
*
* The application is configured at a resolution of 720x720 pixels. A sphere mesh is created
* using the `sphereMesh` utility, and a total of 10,000 4D points are generated with the
* `hammersley4D` sequence. These points are scaled, translated, and rendered as small spheres.
* The color of each sphere is modified based on the 4th dimension of its corresponding point by
* shifting the hue in HSV color space.
*
* This program employs the `Orbital` extension, enabling camera interaction for 3D navigation
* of the scene. Rendering occurs within the draw loop, providing continuous visualization
* of the point distribution.
*/
fun main() {
application {
configure {
width = 720
height = 720
}
program {
val sphere = sphereMesh(radius = 0.1)
extend(Orbital())
extend {
val points = (0 until 10000).map {
(hammersley4D(it, 10000) - Vector4(0.5, 0.5, 0.5, 0.0)) * Vector4(10.0, 10.0, 10.0, 1.0)
}
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)
}
}
}
}
}
}

View File

@@ -0,0 +1,27 @@
package rseq
import org.openrndr.application
import org.openrndr.extra.noise.rsequence.rSeq2D
/**
* This demo sets up a window with dimensions 720x720 and renders frames
* demonstrating 2D quasirandomly distributed points. The points are generated
* using the R2 sequence and drawn as circles with a radius of 5.0.
*/
fun main() {
application {
configure {
width = 720
height = 720
}
program {
extend {
val points = (0 until 4000).map {
rSeq2D(it) * 720.0
}
drawer.circles(points, 5.0)
}
}
}
}

View File

@@ -0,0 +1,45 @@
package rseq
import org.openrndr.application
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.math.Vector3
/**
* This demo renders a 3D visualizationof points distributed using the R3 quasirandom sequence. Each point is
* represented as a sphere and positioned in 3D space based on the quasirandom sequence values.
*
* The visualization setup includes:
* - Configuration of application window size to 720x720.
* - Usage of an orbital camera for interactive 3D navigation.
* - Creation of a reusable sphere mesh with a specified radius.
* - Generation of quasirandom points in 3D space using the `rSeq3D` function.
* - Transformation and rendering of each point as a sphere using vertex buffers.
*/
fun main() {
application {
configure {
width = 720
height = 720
}
program {
val sphere = sphereMesh(radius = 0.1)
extend(Orbital())
extend {
val points = (0 until 1400).map {
(rSeq3D(it) - Vector3(0.5)) * 10.0
}
for (point in points) {
drawer.isolated {
drawer.translate(point)
drawer.vertexBuffer(sphere, DrawPrimitive.TRIANGLES)
}
}
}
}
}
}

View File

@@ -0,0 +1,54 @@
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)
}
}
}
}
}
}