forked from openrndr/orx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DemoVoronoi03.kt
41 lines (38 loc) · 1.43 KB
/
DemoVoronoi03.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
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.shapes.grid
import org.openrndr.extra.triangulation.delaunayTriangulation
import org.openrndr.math.Vector2
import org.openrndr.math.Vector3
import org.openrndr.math.transforms.buildTransform
import org.openrndr.shape.Circle
fun main() {
application {
configure {
width = 750
height = 1000
}
program {
extend {
val r = drawer.bounds.offsetEdges(-100.0)
val grid = r.grid(3,6).flatten()
val circles = grid.map { Circle(Vector2.ZERO, 158.975).contour.transform(
buildTransform {
translate(it.center)
rotate(Vector3.UNIT_Z, 0.0)
}
) }
val points = circles.flatMap { it.contour.equidistantPositions(16).take(16) }
drawer.circles(points, 5.0)
val d = points.delaunayTriangulation()
drawer.stroke = ColorRGBa.PINK
drawer.contours(d.halfedges())
drawer.stroke = ColorRGBa.YELLOW
drawer.fill = ColorRGBa.GRAY.opacify(0.5)
drawer.contours(d.voronoiDiagram(drawer.bounds).cellPolygons())
drawer.stroke = ColorRGBa.GRAY
drawer.contours(d.triangles().map { it.contour })
}
}
}
}