[orx-chataigne] Add Chataigne support (#130)

This commit is contained in:
Boyd
2020-06-30 13:42:35 +02:00
committed by GitHub
parent 847f05cc7b
commit b0a0c7d674
6 changed files with 151 additions and 1 deletions

View File

@@ -0,0 +1,29 @@
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.osc.OSC
fun main() = application {
configure {
width = 500
height = 500
}
/* Find the Chataigne example project in /resources */
class SceneVariables : ChataigneOSC(OSC(portIn = 9005, portOut = 12001)) {
val myRadius: Double by DoubleChannel("/myRadius")
val myOpacity: Double by DoubleChannel("/myOpacity")
val myColor: ColorRGBa by ColorChannel("/myColor")
}
program {
val animation = SceneVariables()
extend {
animation.update(seconds)
drawer.fill = animation.myColor.opacify(animation.myOpacity)
drawer.circle(width/2.0, height/2.0, animation.myRadius * 250)
}
}
}

View File

@@ -0,0 +1,53 @@
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.osc.OSC
import java.awt.Color
import kotlin.reflect.KProperty
open class ChataigneOSC(
val osc: OSC
) {
inner class DoubleChannel(key:String) {
private var currentDouble = 0.0
init {
osc.listen(key) {
currentDouble = (it[0] as Float).toDouble()
}
}
operator fun getValue(thisRef: Any?, property: KProperty<*>):Double {
return currentDouble
}
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Double) {
print("$value")
}
}
inner class ColorChannel(key:String) {
private var currentColor = ColorRGBa.BLACK
init {
println(key)
osc.listen(key) {
val c = it[0] as Color
currentColor = ColorRGBa(c.red/255.0, c.green/255.0, c.blue/255.0, c.alpha/255.0)
}
}
operator fun getValue(thisRef: Any?, property: KProperty<*>):ColorRGBa {
return currentColor
}
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Double) {
print("$value")
}
}
fun update(seconds: Double) {
osc.send("/setTime", seconds.toFloat())
}
init {
println("setup Chataigne with OSC ${osc.address} in:${osc.portIn} out:${osc.portOut}")
}
}