Demos: ensure 720px wide, reduce indentation

This commit is contained in:
Abe Pazos
2025-01-24 23:05:40 +01:00
parent ca8fbc1c0a
commit f84bf69713
31 changed files with 961 additions and 964 deletions

View File

@@ -11,34 +11,32 @@ import org.openrndr.shape.LineSegment
* cursor are highlighted with circles and lines connecting them to the cursor.
*
* Key features:
* - Generates 1000 random 2D points within the canvas dimensions (1080x720).
* - Generates 1000 random 2D points within the canvas.
* - Builds a KD-tree from the list of points for optimized spatial querying.
* - Visualizes the points and highlights the 7 nearest neighbors to the user's cursor position dynamically.
* - Highlights include red-colored circles around the nearest points and red lines connecting them to the cursor.
*/
fun main() {
application {
configure {
width = 1080
height = 720
fun main() = application {
configure {
width = 720
height = 720
}
program {
val points = MutableList(1000) {
Vector2(Math.random() * width, Math.random() * height)
}
val tree = points.kdTree()
program {
val points = MutableList(1000) {
Vector2(Math.random() * width, Math.random() * height)
}
val tree = points.kdTree()
extend {
drawer.circles(points, 5.0)
extend {
drawer.circles(points, 5.0)
val kNearest = tree.findKNearest(mouse.position, k = 7)
drawer.fill = ColorRGBa.RED
drawer.stroke = ColorRGBa.RED
drawer.strokeWeight = 2.0
drawer.circles(kNearest, 7.0)
drawer.lineSegments(kNearest.map { LineSegment(mouse.position, it) })
}
val kNearest = tree.findKNearest(mouse.position, k = 7)
drawer.fill = ColorRGBa.RED
drawer.stroke = ColorRGBa.RED
drawer.strokeWeight = 2.0
drawer.circles(kNearest, 7.0)
drawer.lineSegments(kNearest.map { LineSegment(mouse.position, it) })
}
}
}
}

View File

@@ -3,8 +3,8 @@ import org.openrndr.extra.kdtree.kdTree
import org.openrndr.math.Vector2
/**
* Initializes an interactive graphical application that displays 1000 randomly distributed 2D points
* on a canvas of dimensions 1280x720. The points are organized into a KD-tree for efficient spatial querying.
* Initializes an interactive graphical application that displays 1000 randomly distributed 2D points.
* The points are organized into a KD-tree for efficient spatial querying.
*
* Key functionality:
* - Displays the points as small circles on the canvas.
@@ -14,24 +14,22 @@ import org.openrndr.math.Vector2
* - KD-tree structure enables efficient nearest-neighbor searches.
* - The nearest point to the cursor is determined and visually emphasized in real-time as the cursor moves.
*/
fun main() {
application {
configure {
width = 1280
height = 720
fun main() = application {
configure {
width = 720
height = 720
}
program {
val points = MutableList(1000) {
Vector2(Math.random() * width, Math.random() * height)
}
program {
val points = MutableList(1000) {
Vector2(Math.random() * width, Math.random() * height)
}
val tree = points.kdTree()
extend {
drawer.circles(points, 5.0)
val nearest = tree.findNearest(mouse.position)
nearest?.let {
drawer.circle(it.x, it.y, 20.0)
}
val tree = points.kdTree()
extend {
drawer.circles(points, 5.0)
val nearest = tree.findNearest(mouse.position)
nearest?.let {
drawer.circle(it.x, it.y, 20.0)
}
}
}
}
}

View File

@@ -11,40 +11,37 @@ import org.openrndr.math.Vector2
* user's cursor position.
*
* Key features:
* - Generates and displays 1000 random 2D points within canvas dimensions of 1080x720.
* - Generates and displays 1000 random 2D points within the canvas.
* - Builds a KD-tree structure for optimized querying of spatial data.
* - Dynamically highlights points within a specified radius (50.0) from the cursor position.
* - Visualizes the current query radius around the cursor as an outline circle.
* - Uses different fill and stroke styles to distinguish highlighted points and query visuals.
*/
fun main() {
application {
fun main() = application {
configure {
width = 720
height = 720
}
configure {
width = 1080
height = 720
program {
val points = MutableList(1000) {
Vector2(Math.random() * width, Math.random() * height)
}
val tree = points.kdTree()
val radius = 50.0
program {
val points = MutableList(1000) {
Vector2(Math.random() * width, Math.random() * height)
}
val tree = points.kdTree()
val radius = 50.0
extend {
drawer.circles(points, 5.0)
extend {
drawer.circles(points, 5.0)
val allInRange = tree.findAllInRadius(mouse.position, radius = radius)
drawer.fill = ColorRGBa.PINK
drawer.stroke = ColorRGBa.PINK
drawer.strokeWeight = 2.0
drawer.circles(allInRange, 7.0)
val allInRange = tree.findAllInRadius(mouse.position, radius = radius)
drawer.fill = ColorRGBa.PINK
drawer.stroke = ColorRGBa.PINK
drawer.strokeWeight = 2.0
drawer.circles(allInRange, 7.0)
drawer.fill = null
drawer.strokeWeight = 1.0
drawer.circle(mouse.position, radius)
}
drawer.fill = null
drawer.strokeWeight = 1.0
drawer.circle(mouse.position, radius)
}
}
}
}