-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathDemoAdjustContour09.kt
58 lines (50 loc) · 1.72 KB
/
DemoAdjustContour09.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
package adjust
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.shapes.adjust.adjustContour
import org.openrndr.extra.shapes.adjust.extensions.averageTangents
import org.openrndr.extra.shapes.adjust.extensions.switchTangents
import org.openrndr.extra.shapes.tunni.tunniLine
import org.openrndr.extra.shapes.tunni.tunniPoint
import kotlin.math.sqrt
fun main() = application {
configure {
width = 800
height = 800
}
program {
extend {
drawer.clear(ColorRGBa.WHITE)
var contour = drawer.bounds.offsetEdges(-200.0).contour
drawer.fill = null
contour = adjustContour(contour) {
selectVertices(0, 1)
for (v in vertices) {
v.averageTangents()
v.scale(sqrt(2.0))
v.rotate(45.0)
}
selectVertices(2)
for (v in vertices) {
v.switchTangents()
}
}
drawer.stroke = ColorRGBa.BLACK
drawer.contour(contour)
drawer.stroke = ColorRGBa.RED
for (s in contour.segments) {
drawer.lineSegment(s.start, s.cubic.control[0])
drawer.lineSegment(s.end, s.cubic.control[1])
}
drawer.fill = ColorRGBa.BLACK
drawer.stroke = null
drawer.circles(contour.segments.map { it.start }, 5.0)
drawer.stroke = ColorRGBa.GRAY
for (s in contour.segments) {
drawer.lineSegment(s.tunniLine)
drawer.fill = ColorRGBa.CYAN
drawer.circle(s.tunniPoint, 5.0)
}
}
}
}