Skip to content

Commit

Permalink
[orx-olive] Add DemoWindowedGUI01.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
edwinRNDR committed May 16, 2024
1 parent fe69825 commit 8ea9807
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 63 deletions.
2 changes: 2 additions & 0 deletions orx-jvm/orx-olive/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ 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)
implementation(libs.kotlin.scriptingJvmHost)
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)
Expand Down
50 changes: 31 additions & 19 deletions orx-jvm/orx-olive/src/demo/kotlin/DemoOlive01.kt
Original file line number Diff line number Diff line change
@@ -1,34 +1,46 @@
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

fun main() = application {
configure {
width = 768
height = 576
}
program {
import org.openrndr.extra.olive.oliveProgram
import kotlin.math.cos

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 {
/**
* 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 <T : Extension> Program.extendHead(extension: T, configure: T.() -> Unit): T {
extensions.add(0, extension)
fun <T : Extension> extendHead(extension: T, configure: T.() -> Unit): T {
program.extensions.add(0, extension)
extension.configure()
extension.setup(this)
extension.setup(program)
return extension
}
extendHead(SingleScreenshot()) {
this.outputFile = System.getProperty("screenshotPath")
}
}
}
}
}
}
37 changes: 37 additions & 0 deletions orx-jvm/orx-olive/src/demo/kotlin/DemoOliveFromScript01.kt
Original file line number Diff line number Diff line change
@@ -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")
}
}
}
}
}
}
44 changes: 0 additions & 44 deletions orx-jvm/orx-olive/src/demo/kotlin/DemoOliveScriptless01.kt

This file was deleted.

60 changes: 60 additions & 0 deletions orx-jvm/orx-olive/src/demo/kotlin/DemoWindowedGUI01.kt
Original file line number Diff line number Diff line change
@@ -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
)
}
}
}
}
}

0 comments on commit 8ea9807

Please sign in to comment.