diff --git a/orx-jvm/orx-olive/build.gradle.kts b/orx-jvm/orx-olive/build.gradle.kts index 427aeed9..ee82d017 100644 --- a/orx-jvm/orx-olive/build.gradle.kts +++ b/orx-jvm/orx-olive/build.gradle.kts @@ -16,6 +16,7 @@ tasks.test { dependencies { implementation(project(":orx-jvm:orx-file-watcher")) implementation(project(":orx-jvm:orx-kotlin-parser")) + demoImplementation(project(":orx-jvm:orx-gui")) implementation(libs.openrndr.application) implementation(libs.openrndr.math) implementation(libs.kotlin.scriptingJvm) @@ -23,6 +24,7 @@ dependencies { implementation(libs.kotlin.reflect) implementation(libs.kotlin.scriptingJSR223) implementation(libs.kotlin.coroutines) + demoImplementation(libs.kotlin.coroutines) testImplementation(libs.kluent) testImplementation(libs.kotest.runner) testImplementation(libs.kotest.assertions) diff --git a/orx-jvm/orx-olive/src/demo/kotlin/DemoOlive01.kt b/orx-jvm/orx-olive/src/demo/kotlin/DemoOlive01.kt index 635a5f21..5d5f7abd 100644 --- a/orx-jvm/orx-olive/src/demo/kotlin/DemoOlive01.kt +++ b/orx-jvm/orx-olive/src/demo/kotlin/DemoOlive01.kt @@ -1,27 +1,40 @@ import org.openrndr.Extension -import org.openrndr.Program import org.openrndr.application - +import org.openrndr.color.ColorRGBa import org.openrndr.extensions.SingleScreenshot -import org.openrndr.extra.olive.Olive +import org.openrndr.extra.olive.oliveProgram +import kotlin.math.cos -fun main() = application { - configure { - width = 768 - height = 576 - } - program { - - extend(Olive()) { - script = "orx-olive/src/demo/kotlin/demo-olive-01.kts" - // -- this block is for automation purposes only - if (System.getProperty("takeScreenshot") == "true") { - scriptLoaded.listen { +/** + * Live-coding with [oliveProgram] + */ +fun main() { + application { + configure { + width = 1280 + height = 720 + } + oliveProgram { + extend { + drawer.clear(ColorRGBa.GRAY) + drawer.fill = ColorRGBa.WHITE + for (i in 0 until 100) { + drawer.circle( + width / 2.0 + cos(seconds + i) * 320.0, + i * 7.2, + cos(i + seconds * 0.5) * 20.0 + 20.0 + ) + } + } + } + // -- this is only needed for the automated screenshots + .olive.scriptLoaded.listen { + if (System.getProperty("takeScreenshot") == "true") { // -- this is a bit of hack, we need to push the screenshot extension in front of the olive one - fun Program.extendHead(extension: T, configure: T.() -> Unit): T { - extensions.add(0, extension) + fun extendHead(extension: T, configure: T.() -> Unit): T { + program.extensions.add(0, extension) extension.configure() - extension.setup(this) + extension.setup(program) return extension } extendHead(SingleScreenshot()) { @@ -29,6 +42,5 @@ fun main() = application { } } } - } } } \ No newline at end of file diff --git a/orx-jvm/orx-olive/src/demo/kotlin/DemoOliveFromScript01.kt b/orx-jvm/orx-olive/src/demo/kotlin/DemoOliveFromScript01.kt new file mode 100644 index 00000000..d0266233 --- /dev/null +++ b/orx-jvm/orx-olive/src/demo/kotlin/DemoOliveFromScript01.kt @@ -0,0 +1,37 @@ +import org.openrndr.Extension +import org.openrndr.Program +import org.openrndr.application + +import org.openrndr.extensions.SingleScreenshot +import org.openrndr.extra.olive.Olive + +/** + * Live-coding with [Olive], an older, not recommended, way to do things + */ +fun main() = application { + configure { + width = 768 + height = 576 + } + program { + + extend(Olive()) { + script = "orx-olive/src/demo/kotlin/demo-olive-01.kts" + // -- this block is for automation purposes only + if (System.getProperty("takeScreenshot") == "true") { + scriptLoaded.listen { + // -- this is a bit of hack, we need to push the screenshot extension in front of the olive one + fun Program.extendHead(extension: T, configure: T.() -> Unit): T { + extensions.add(0, extension) + extension.configure() + extension.setup(this) + return extension + } + extendHead(SingleScreenshot()) { + this.outputFile = System.getProperty("screenshotPath") + } + } + } + } + } +} \ No newline at end of file diff --git a/orx-jvm/orx-olive/src/demo/kotlin/DemoOliveScriptless01.kt b/orx-jvm/orx-olive/src/demo/kotlin/DemoOliveScriptless01.kt deleted file mode 100644 index a3c90c46..00000000 --- a/orx-jvm/orx-olive/src/demo/kotlin/DemoOliveScriptless01.kt +++ /dev/null @@ -1,44 +0,0 @@ -import org.openrndr.Extension -import org.openrndr.application -import org.openrndr.color.ColorRGBa -import org.openrndr.extensions.SingleScreenshot -import org.openrndr.extra.olive.OliveScriptHost -import org.openrndr.extra.olive.oliveProgram -import kotlin.math.cos - -fun main() { - application { - configure { - width = 1280 - height = 720 - } - oliveProgram(scriptHost = OliveScriptHost.JSR223_REUSE) { - extend { - drawer.clear(ColorRGBa.GRAY) - drawer.fill = ColorRGBa.WHITE - for (i in 0 until 100) { - drawer.circle( - width / 2.0 + cos(seconds + i) * 320.0, - i * 7.2, - cos(i + seconds * 0.5) * 20.0 + 20.0 - ) - } - } - } - // -- this is only needed for the automated screenshots - .olive.scriptLoaded.listen { - if (System.getProperty("takeScreenshot") == "true") { - // -- this is a bit of hack, we need to push the screenshot extension in front of the olive one - fun extendHead(extension: T, configure: T.() -> Unit): T { - program.extensions.add(0, extension) - extension.configure() - extension.setup(program) - return extension - } - extendHead(SingleScreenshot()) { - this.outputFile = System.getProperty("screenshotPath") - } - } - } - } -} \ No newline at end of file diff --git a/orx-jvm/orx-olive/src/demo/kotlin/DemoWindowedGUI01.kt b/orx-jvm/orx-olive/src/demo/kotlin/DemoWindowedGUI01.kt new file mode 100644 index 00000000..a2344817 --- /dev/null +++ b/orx-jvm/orx-olive/src/demo/kotlin/DemoWindowedGUI01.kt @@ -0,0 +1,60 @@ +import org.openrndr.application +import org.openrndr.color.ColorRGBa +import org.openrndr.extra.gui.WindowedGUI +import org.openrndr.extra.olive.oliveProgram +import org.openrndr.extra.parameters.ColorParameter +import org.openrndr.extra.parameters.Description +import org.openrndr.extra.parameters.DoubleParameter +import org.openrndr.extra.parameters.IntParameter +import kotlin.math.cos +import kotlin.system.exitProcess + +/** + * Live-coding with [oliveProgram] and [WindowedGUI] + */ +fun main() { + // skip this demo on CI + if (System.getProperty("takeScreenshot") == "true") { + exitProcess(0) + } + application { + configure { + width = 720 + height = 720 + } + oliveProgram() { + val gui = WindowedGUI() + + val settings = @Description("Settings") object { + @DoubleParameter("radius", 0.0, 80.0) + var radius = 30.0 + + @ColorParameter("color") + var fill = ColorRGBa.RED + + @ColorParameter("background") + var background = ColorRGBa.BLACK + + @DoubleParameter("speed", 0.1, 10.0) + var speed = 1.0 + + @IntParameter("count", 1, 400) + var count = 100 + } + gui.add(settings) + + extend(gui) + extend { + drawer.clear(settings.background) + drawer.fill = settings.fill + for (i in 0 until settings.count) { + drawer.circle( + width / 2.0 + cos(settings. speed * seconds + i) * 320.0, + i * 7.2, + (cos(i + seconds * 0.5) * 1.0 + 1.0) * settings.radius + ) + } + } + } + } +} \ No newline at end of file