[orx-olive] Add DemoWindowedGUI01.kt

This commit is contained in:
Edwin Jakobs
2024-05-15 14:24:05 +02:00
parent fe69825343
commit 8ea980754e
5 changed files with 130 additions and 63 deletions

View File

@@ -16,6 +16,7 @@ tasks.test {
dependencies { dependencies {
implementation(project(":orx-jvm:orx-file-watcher")) implementation(project(":orx-jvm:orx-file-watcher"))
implementation(project(":orx-jvm:orx-kotlin-parser")) implementation(project(":orx-jvm:orx-kotlin-parser"))
demoImplementation(project(":orx-jvm:orx-gui"))
implementation(libs.openrndr.application) implementation(libs.openrndr.application)
implementation(libs.openrndr.math) implementation(libs.openrndr.math)
implementation(libs.kotlin.scriptingJvm) implementation(libs.kotlin.scriptingJvm)
@@ -23,6 +24,7 @@ dependencies {
implementation(libs.kotlin.reflect) implementation(libs.kotlin.reflect)
implementation(libs.kotlin.scriptingJSR223) implementation(libs.kotlin.scriptingJSR223)
implementation(libs.kotlin.coroutines) implementation(libs.kotlin.coroutines)
demoImplementation(libs.kotlin.coroutines)
testImplementation(libs.kluent) testImplementation(libs.kluent)
testImplementation(libs.kotest.runner) testImplementation(libs.kotest.runner)
testImplementation(libs.kotest.assertions) testImplementation(libs.kotest.assertions)

View File

@@ -1,27 +1,40 @@
import org.openrndr.Extension import org.openrndr.Extension
import org.openrndr.Program
import org.openrndr.application import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extensions.SingleScreenshot 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 { * Live-coding with [oliveProgram]
width = 768 */
height = 576 fun main() {
} application {
program { configure {
width = 1280
extend(Olive<Program>()) { height = 720
script = "orx-olive/src/demo/kotlin/demo-olive-01.kts" }
// -- this block is for automation purposes only oliveProgram {
if (System.getProperty("takeScreenshot") == "true") { extend {
scriptLoaded.listen { 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 // -- this is a bit of hack, we need to push the screenshot extension in front of the olive one
fun <T : Extension> Program.extendHead(extension: T, configure: T.() -> Unit): T { fun <T : Extension> extendHead(extension: T, configure: T.() -> Unit): T {
extensions.add(0, extension) program.extensions.add(0, extension)
extension.configure() extension.configure()
extension.setup(this) extension.setup(program)
return extension return extension
} }
extendHead(SingleScreenshot()) { extendHead(SingleScreenshot()) {
@@ -29,6 +42,5 @@ fun main() = application {
} }
} }
} }
}
} }
} }

View File

@@ -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<Program>()) {
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 <T : Extension> 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")
}
}
}
}
}
}

View File

@@ -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 <T : Extension> 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")
}
}
}
}
}

View File

@@ -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
)
}
}
}
}
}