Files
orx/orx-olive
Edwin Jakobs ab1a1b601d Improve orx-olive to work nicer with host extensions.
Removed javax.script.ScriptEngineFactory as that is no longer needed from Kotlin 1.3.50
2019-09-07 14:40:40 +02:00
..

orx-olive

Live coding extension for OPENRNDR

usage

make sure that you add the following to your list of dependencies (next to orx-olive)

compile "org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:1.3.31"

Then a simple live setup can created as follows:

import org.openrndr.Program
import org.openrndr.application
import org.openrndr.extra.olive.Olive

fun main() = application {
    configure {
        width = 768
        height = 576
    }
    program {
        extend(Olive<Program>())
    }
}

The extension will create a template script for you in src/main/kotlin/live.kts. You can edit this to see how the program updates automatically.

Shade style errors

Recent versions of orx-olive automatically set the org.openrndr.ignoreShadeStyleErrors property which makes OPENRNDR ignore errors in the shade style and return the default shader. To get this behaviour in older versions add -Dorg.openrndr.ignoreShadeStyleErrors=true to the JVM arguments.

Persistent Data

Sometimes you want to keep parts of your application persistent. In the following example we show how you can prepare the host program to contain a persistent camera device.

import org.openrndr.Program
import org.openrndr.application

class PersistentProgram: Program() {
    lateinit var camera: FFMPEGVideoPlayer
}

fun main() = application{
    program(PersistentProgram()) {
        camera = FFMPEGVideoPlayer.fromDevice()
        camera.start()

        extend(Olive<PersistentProgram>()) {
            script = "src/main/PersistentCamera.Kt"
        }
    }
}

The live script src/main/PersistentCamera.kt then looks like this:

@file:Suppress("UNUSED_LAMBDA_EXPRESSION")
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.*

{ program: PersistentProgram ->
    program.apply {
        extend {
            camera.next()
            drawer.drawStyle.colorMatrix = tint(ColorRGBa.GREEN) * grayscale(0.0, 0.0, 1.0)
            camera.draw(drawer)
        }
    }
}