[orx-hash-grid] Add generated and verified documentation, improve DemoHashGrid01.kt
This commit is contained in:
@@ -3,6 +3,13 @@ import org.openrndr.extra.hashgrid.filter
|
||||
import org.openrndr.extra.noise.shapes.uniform
|
||||
import kotlin.random.Random
|
||||
|
||||
/** A demo to generate and display filtered random points.
|
||||
*
|
||||
* The program performs the following steps:
|
||||
* - Generates 10,000 random points uniformly distributed within the drawable bounds.
|
||||
* - Filters the generated points to enforce a minimum distance of 20.0 units between them.
|
||||
* - Visualizes the filtered points as circles with a radius of 10.0 units on the canvas.
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
|
||||
@@ -10,6 +10,16 @@ import org.openrndr.extra.noise.uniformRing
|
||||
import org.openrndr.math.Vector3
|
||||
import kotlin.random.Random
|
||||
|
||||
/**
|
||||
* This demo sets up and renders a 3D visualization of filtered random points displayed as small spheres.
|
||||
*
|
||||
* The program performs the following key steps:
|
||||
* - Generates 10,000 random 3D points within a ring defined by a minimum and maximum radius.
|
||||
* - Filters the points to ensure a minimum distance between any two points using a spatial hash grid.
|
||||
* - Creates a small sphere mesh that will be instanced for each filtered point.
|
||||
* - Sets up an orbital camera to allow viewing the 3D scene interactively.
|
||||
* - Renders the filtered points by translating the sphere mesh to each point's position and applying a shader that modifies the fragment color based on the view normal.
|
||||
*/
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
|
||||
@@ -4,6 +4,15 @@ import org.openrndr.extra.hashgrid.HashGrid
|
||||
import org.openrndr.extra.noise.shapes.uniform
|
||||
import kotlin.random.Random
|
||||
|
||||
/**
|
||||
* This demo sets up an interactive graphics application with a configurable
|
||||
* display window and visualization logic. It uses a `HashGrid` to manage points
|
||||
* in a 2D space and randomly generates points within the drawable area. These
|
||||
* points are then inserted into the grid if they satisfy certain spatial conditions.
|
||||
* The visual output includes:
|
||||
* - Rectangles representing the bounds of the cells in the grid.
|
||||
* - Circles representing the generated points.
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
@@ -12,16 +21,23 @@ fun main() {
|
||||
}
|
||||
program {
|
||||
val r = Random(0)
|
||||
val hashGrid = HashGrid(20.0)
|
||||
val hashGrid = HashGrid(72.0)
|
||||
|
||||
extend {
|
||||
val p = drawer.bounds.uniform(random = r)
|
||||
if (hashGrid.isFree(p)) {
|
||||
hashGrid.insert(p)
|
||||
for (i in 0 until 100) {
|
||||
val p = drawer.bounds.uniform(random = r)
|
||||
if (hashGrid.isFree(p)) {
|
||||
hashGrid.insert(p)
|
||||
}
|
||||
}
|
||||
drawer.circles(hashGrid.points().map { it.first }.toList(), 4.0)
|
||||
|
||||
drawer.fill = null
|
||||
drawer.stroke = ColorRGBa.WHITE
|
||||
drawer.rectangles(hashGrid.cells().map { it.bounds }.toList())
|
||||
drawer.fill = null
|
||||
drawer.stroke = ColorRGBa.PINK
|
||||
drawer.circles(hashGrid.points().map { it.first }.toList(), 36.0)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user