-
Notifications
You must be signed in to change notification settings - Fork 37
/
DemoAdjustContourContinue01.kt
102 lines (86 loc) · 3.22 KB
/
DemoAdjustContourContinue01.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
102
package adjust
import kotlinx.coroutines.yield
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.shapes.adjust.adjustContourSequence
import org.openrndr.extra.shapes.tunni.tunniLine
import org.openrndr.extra.shapes.tunni.tunniPoint
import org.openrndr.extra.shapes.tunni.withTunniLine
import org.openrndr.launch
import org.openrndr.math.Vector2
import org.openrndr.shape.Segment2D
import kotlin.math.cos
fun main() {
application {
configure {
width = 800
height = 800
}
program {
var res = drawer.bounds.offsetEdges(-200.0).contour
var selectedSegments = emptyList<Segment2D>()
var selectedPoints = emptyList<Vector2>()
val contourSeq = adjustContourSequence(res) {
sequence {
for (i in 0 until 1000) {
selectEdges()
selectVertices((i*7).mod(4))
for (v in vertices) {
for (j in 0 until 30) {
v.rotate(45.0/30.0)
yield(status)
}
}
selectVertices((i*3).mod(4))
for (v in vertices) {
yield(status)
}
selectVertices()
selectEdges(i.mod(4))
for (j in 0 until 30) {
for (e in edges) {
e.withTunniLine(e.tunniLine.position(0.5) + e.tunniLine.normal * cos(i.toDouble() + e.segmentIndex()) * 50.0/30.0)
yield(status)
}
}
}
}
}
launch {
for (i in contourSeq) {
res = i.contour
selectedPoints = i.selectedPoints
selectedSegments = i.selectedSegments
yield()
}
}
extend {
drawer.clear(ColorRGBa.WHITE)
drawer.stroke = ColorRGBa.BLACK
drawer.contour(res)
drawer.stroke = ColorRGBa.RED
for (s in res.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(res.segments.map { it.start }, 5.0)
drawer.stroke = ColorRGBa.GRAY
for (s in res.segments) {
drawer.lineSegment(s.tunniLine)
drawer.fill = ColorRGBa.CYAN
drawer.circle(s.tunniPoint, 5.0)
}
drawer.stroke = ColorRGBa.MAGENTA
drawer.strokeWeight = 3.0
for (s in selectedSegments) {
drawer.segment(s)
}
for (p in selectedPoints) {
drawer.circle(p, 5.0)
}
}
}
}
}