forked from openrndr/orx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DemoQuadTree01.kt
48 lines (40 loc) · 1.28 KB
/
DemoQuadTree01.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.rectangleBatch
import org.openrndr.extra.noise.Random
import org.openrndr.extra.noise.gaussian
import org.openrndr.extra.quadtree.Quadtree
import org.openrndr.math.Vector2
import org.openrndr.shape.Rectangle
fun main() {
application {
configure {
width = 800
height = 800
title = "QuadTree"
}
program {
val box = Rectangle.fromCenter(Vector2(400.0), 750.0)
val points = (0 until 1_000).map {
Vector2.gaussian(box.center, Vector2(95.0), Random.rnd)
}
val quadTree = Quadtree<Vector2>(box) { it }
for (point in points) {
quadTree.insert(point)
}
val batch = drawer.rectangleBatch {
this.fill = null
this.stroke = ColorRGBa.GRAY
this.strokeWeight = 0.5
quadTree.batch(this)
}
extend {
drawer.clear(ColorRGBa.BLACK)
drawer.rectangles(batch)
drawer.fill = ColorRGBa.PINK.opacify(0.7)
drawer.stroke = null
drawer.circles(points, 5.0)
}
}
}
}