-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathDemoExpressionEvaluator01.kt
46 lines (37 loc) · 1.49 KB
/
DemoExpressionEvaluator01.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
import org.openrndr.application
import org.openrndr.extra.expressions.evaluateExpression
import org.openrndr.extra.gui.GUI
import org.openrndr.extra.gui.addTo
import org.openrndr.extra.parameters.TextParameter
fun main() {
application {
program {
val gui = GUI()
gui.compartmentsCollapsedByDefault = false
val settings = object {
@TextParameter("x expression", order = 10)
var xExpression = "cos(t) * 50.0 + width / 2.0"
@TextParameter("y expression", order = 20)
var yExpression = "sin(t) * 50.0 + height / 2.0"
@TextParameter("radius expression", order = 30)
var radiusExpression = "cos(t) * 50.0 + 50.0"
}.addTo(gui)
extend(gui)
extend {
//gui.visible = mouse.position.x < 200.0
val expressionContext =
mapOf("t" to seconds, "width" to drawer.bounds.width, "height" to drawer.bounds.height)
fun eval(expression: String): Double =
try {
evaluateExpression(expression, expressionContext) ?: 0.0
} catch (e: Throwable) {
0.0
}
val x = eval(settings.xExpression)
val y = eval(settings.yExpression)
val radius = eval(settings.radiusExpression)
drawer.circle(x, y, radius)
}
}
}
}