Add OliveProgram scriptless replacement

This commit is contained in:
Edwin Jakobs
2020-05-01 15:04:43 +02:00
parent d53925efb1
commit 542ca90379
10 changed files with 113 additions and 56 deletions

View File

@@ -1,28 +1,36 @@
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.math.IntVector2
import org.openrndr.extra.olive.oliveProgram
import kotlin.math.cos
fun main() {
application {
configure {
position = IntVector2(3440 / 2 + 200, 360)
width = 1280
height = 720
}
program {
extend(Olive<Program>()) {
// -- this block is for automation purposes only
if (System.getProperty("takeScreenshot") == "true") {
scriptLoaded.listen {
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()) {
@@ -30,17 +38,5 @@ fun main() {
}
}
}
script = "orx-olive/src/demo/kotlin/DemoOliveScriptless01.kt"
program {
extend {
drawer.background(ColorRGBa.PINK)
drawer.circle(width /2.0, height / 2.0, 300.0 + Math.cos(seconds)*100.0)
drawer.fill = ColorRGBa.RED
drawer.circle(mouse.position, 100.0)
}
}
}
}
}
}