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
|
package flow
import flow.*
import kotlin.math.*
import org.openrndr.WindowMultisample
import org.openrndr.application
import org.openrndr.color.*
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.*
import org.openrndr.math.IntVector2
import org.openrndr.math.Vector2
import phenax.utils.*
// Configuration for each visual in ./FlowConfig.kt
fun main() = application {
recordDuration(12.seconds())
val scale = 1
if (captureEnabled || true) {
configure {
width = 1920 * scale
height = 1080 * scale
windowResizable = false
multisample = WindowMultisample.SampleCount(16)
}
} else {
configure {
width = 640
height = 360
windowResizable = false
}
}
oliveProgram {
val cellSize = Vector2(10.0, 10.0) * scale.toDouble()
val cellCount = IntVector2((width / cellSize.x).toInt(), (height / cellSize.y).toInt())
println(":: ${cellCount.x}, ${cellCount.y}")
val config = getConfig()
config.dimensions = IntVector2(width, height)
config.gridDimensions = cellCount
var points = config.generatePoints()
var traces = Array(config.particleCount) { ArrayDeque<Vector2>(config.maxSegmentsCount) }
var flowField = FlowField(cellCount, config.dimensions) { x, y -> config.getVectorValue(x, y) }
fun update() {
flowField.applyOn(points) { index, p ->
val lines = traces[index]
lines.addLast(p.position)
if (lines.size > config.maxSegmentsCount) lines.removeFirst()
}
}
if (screenshotEnabled) {
repeat(config.screenshotIterationsCount) { update() }
} else {
repeat(100) { update() }
extend { update() }
}
val showDebug = false
extend {
drawer.clear(ColorRGBa(0.11, 0.1, 0.1))
drawer.strokeWeight = 0.01
drawer.fill = ColorRGBa(0.1, 0.1, 0.1)
drawer.stroke = drawer.fill
config.drawer.draw(program, traces)
if (showDebug) {
drawer.strokeWeight = 0.01
drawer.fill = ColorRGBa(0.3, 0.3, 0.3)
drawer.stroke = drawer.fill
val r = 10.0
for ((row, cells) in flowField.vectors.withIndex()) {
for ((col, angle) in cells.withIndex()) {
val pos = Vector2(col * cellSize.x, row * cellSize.y)
drawer.lineSegment(pos.x, pos.y, pos.x + r * cos(angle), pos.y + r * sin(angle))
drawer.circle(pos.x, pos.y, 2.0)
// drawer.text("${col},${row}", pos + Vector2(12.0, 12.0))
}
}
}
}
}
}
|