-
Notifications
You must be signed in to change notification settings - Fork 37
/
DemoArrangement02.kt
101 lines (86 loc) · 3.6 KB
/
DemoArrangement02.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package arrangement
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.isolated
import org.openrndr.extra.color.spaces.ColorOKHSVa
import org.openrndr.extra.noise.poissonDiskSampling
import org.openrndr.extra.shapes.arrangement.Arrangement
import org.openrndr.extra.shapes.arrangement.BoundedFace
import org.openrndr.extra.shapes.hobbycurve.hobbyCurve
import kotlin.random.Random
fun main() = application {
configure {
width = 800
height = 800
}
program {
// Create a nice curve that intersects itself
val uniformPoints = poissonDiskSampling(drawer.bounds.offsetEdges(-200.0), 100.0, random=Random(10579))
val curve = hobbyCurve(uniformPoints, closed=true)
// Construct an arrangement of the curve. In order to obtain an arrangement dealing with self intersections,
// the curve is passed in twice.
val arrangement = Arrangement(curve, curve)
// We will color each bounded face.
val faces = arrangement.boundedFaces
val colors = faces.withIndex().associate { (i, f) ->
f to ColorOKHSVa(i * 360.0 / faces.size, 0.75, 1.0).toRGBa()
}
extend {
drawer.apply {
clear(ColorRGBa.WHITE)
isolated {
// Shrink the drawing
translate(drawer.bounds.center)
scale(0.5)
translate(-drawer.bounds.center)
// Draw each face
stroke = null
for (f in faces) {
fill = colors[f]
contour(f.contour)
}
// Draw the curve on top
fill = null
stroke = ColorRGBa.BLACK
strokeWeight = 4.0
contour(curve)
strokeWeight = 4.0
stroke = ColorRGBa.BLACK
fill = ColorRGBa.WHITE
circles(arrangement.vertices.map { it.pos }, 12.0)
}
// We are going to draw the neighborhood of each vertex in the arrangement
for (v in arrangement.vertices) {
isolated {
// Shrink the drawing quite a bit
translate(v.pos)
scale(0.35)
translate(-v.pos)
// Move the drawing in the direction of the vertex
translate((v.pos - drawer.bounds.center).normalized * 300.0)
// For each outgoing half-edge, draw the associated face
for (e in v.outgoing) {
val f = e.face as? BoundedFace
if (f != null) {
stroke = null
fill = colors[f]!!.opacify(0.5)
contour(f.contour)
}
}
// For each outgoing half-edge, draw the edge
for (e in v.outgoing) {
strokeWeight = 2.0/0.35
stroke = ColorRGBa.BLACK
contour(e.contour)
}
// Draw the vertex
strokeWeight = 2 / 0.35
stroke = ColorRGBa.BLACK
fill = ColorRGBa.WHITE
circle(v.pos, 6.0 / 0.35)
}
}
}
}
}
}