diff --git a/orx-jvm/orx-keyframer/build.gradle b/orx-jvm/orx-keyframer/build.gradle index de5b5675..722f30ad 100644 --- a/orx-jvm/orx-keyframer/build.gradle +++ b/orx-jvm/orx-keyframer/build.gradle @@ -37,8 +37,10 @@ dependencies { testRuntimeOnly(libs.spek.junit5) testRuntimeOnly(libs.kotlin.reflect) demoImplementation(project(":orx-jvm:orx-panel")) + demoImplementation(project(":orx-jvm:orx-gui")) } tasks.getByName("compileKotlin").dependsOn("generateGrammarSource") +tasks.getByName("compileDemoKotlin").dependsOn("generateDemoGrammarSource") tasks.getByName("compileTestKotlin").dependsOn("generateTestGrammarSource") tasks.getByName("sourcesJar").dependsOn("generateGrammarSource") \ No newline at end of file diff --git a/orx-jvm/orx-keyframer/src/demo/kotlin/DemoExpressionEvaluator01.kt b/orx-jvm/orx-keyframer/src/demo/kotlin/DemoExpressionEvaluator01.kt new file mode 100644 index 00000000..97be117b --- /dev/null +++ b/orx-jvm/orx-keyframer/src/demo/kotlin/DemoExpressionEvaluator01.kt @@ -0,0 +1,39 @@ +import org.openrndr.application +import org.openrndr.extra.gui.GUI +import org.openrndr.extra.gui.addTo +import org.openrndr.extra.keyframer.evaluateExpression +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) + } + } + } +} \ No newline at end of file