Add DemoNearestNeighbour01.kt for orx-kdtree
This commit is contained in:
2
orx-kdtree/README.md
Normal file
2
orx-kdtree/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
# orx-kdtree
|
||||
|
||||
17
orx-kdtree/build.gradle
Normal file
17
orx-kdtree/build.gradle
Normal file
@@ -0,0 +1,17 @@
|
||||
sourceSets {
|
||||
demo {
|
||||
java {
|
||||
srcDirs = ["src/demo/kotlin"]
|
||||
compileClasspath += main.getCompileClasspath()
|
||||
runtimeClasspath += main.getRuntimeClasspath()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
demoImplementation("org.openrndr:openrndr-core:$openrndrVersion")
|
||||
demoImplementation("org.openrndr:openrndr-extensions:$openrndrVersion")
|
||||
demoRuntimeOnly("org.openrndr:openrndr-gl3:$openrndrVersion")
|
||||
demoRuntimeOnly("org.openrndr:openrndr-gl3-natives-$openrndrOS:$openrndrVersion")
|
||||
demoImplementation(sourceSets.getByName("main").output)
|
||||
}
|
||||
34
orx-kdtree/src/demo/kotlin/DemoNearestNeighbour01.kt
Normal file
34
orx-kdtree/src/demo/kotlin/DemoNearestNeighbour01.kt
Normal file
@@ -0,0 +1,34 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.extensions.SingleScreenshot
|
||||
import org.openrndr.extra.kdtree.buildKDTree
|
||||
import org.openrndr.extra.kdtree.findNearest
|
||||
import org.openrndr.extra.kdtree.vector2Mapper
|
||||
import org.openrndr.math.Vector2
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 1280
|
||||
height = 720
|
||||
}
|
||||
program {
|
||||
if (System.getProperty("takeScreenshot") == "true") {
|
||||
extend(SingleScreenshot()) {
|
||||
this.outputFile = System.getProperty("screenshotPath")
|
||||
}
|
||||
}
|
||||
|
||||
val points = MutableList(1000) {
|
||||
Vector2(Math.random() * width, Math.random() * height)
|
||||
}
|
||||
val tree = buildKDTree(points, 2, ::vector2Mapper)
|
||||
extend {
|
||||
drawer.circles(points, 5.0)
|
||||
val nearest = findNearest(tree, mouse.position, 2, ::vector2Mapper)
|
||||
nearest?.let {
|
||||
drawer.circle(it.x, it.y, 20.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user