Upgrade to OPENRNDR 0.4 snapshot
This commit is contained in:
40
orx-jvm/orx-chataigne/README.md
Normal file
40
orx-jvm/orx-chataigne/README.md
Normal file
@@ -0,0 +1,40 @@
|
||||
# orx-chataigne
|
||||
|
||||
Expose variables to [Chataigne](http://benjamin.kuperberg.fr/chataigne/en) and any other applications that can interface with it.
|
||||
The current implementation makes use of the OSC protocol and supports `Double` and `ColorRGBa`.
|
||||
|
||||
## Usage
|
||||
|
||||
Defining the variables
|
||||
```kotlin
|
||||
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")
|
||||
}
|
||||
```
|
||||
|
||||
Initiate
|
||||
|
||||
```kotlin
|
||||
val animation = SceneVariables()
|
||||
```
|
||||
|
||||
Update time
|
||||
|
||||
```kotlin
|
||||
animation.update(seconds)
|
||||
```
|
||||
|
||||
Use the variables
|
||||
|
||||
```kotlin
|
||||
animation.myRadius
|
||||
animation.myOpacity
|
||||
animation.myColor
|
||||
```
|
||||
|
||||
## Example project
|
||||
|
||||
Find the Chataigne example project in `/resources/timeline_example_chataigne.noisette` which works together with demo project `/src/demo/kotlin/ChataigneOSCDemo.kt`
|
||||
|
||||
25
orx-jvm/orx-chataigne/build.gradle
Normal file
25
orx-jvm/orx-chataigne/build.gradle
Normal file
@@ -0,0 +1,25 @@
|
||||
sourceSets {
|
||||
demo {
|
||||
java {
|
||||
srcDirs = ["src/demo/kotlin"]
|
||||
compileClasspath += main.getCompileClasspath()
|
||||
runtimeClasspath += main.getRuntimeClasspath()
|
||||
}
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
api project(":orx-osc")
|
||||
|
||||
implementation "com.google.code.gson:gson:$gsonVersion"
|
||||
demoImplementation("org.openrndr:openrndr-application:$openrndrVersion")
|
||||
|
||||
demoRuntimeOnly("org.openrndr:openrndr-gl3:$openrndrVersion")
|
||||
demoRuntimeOnly("org.openrndr:openrndr-gl3-natives-$openrndrOS:$openrndrVersion")
|
||||
demoRuntimeOnly("org.openrndr:openrndr-extensions:$openrndrVersion")
|
||||
demoImplementation("org.openrndr:openrndr-ffmpeg:$openrndrVersion")
|
||||
demoRuntimeOnly("org.openrndr:openrndr-ffmpeg-natives-$openrndrOS:$openrndrVersion")
|
||||
demoImplementation(project(":orx-fx"))
|
||||
// demoImplementation(project(":orx-osc"))
|
||||
|
||||
demoImplementation(sourceSets.getByName("main").output)
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
29
orx-jvm/orx-chataigne/src/demo/kotlin/ChataigneOSCDemo.kt
Normal file
29
orx-jvm/orx-chataigne/src/demo/kotlin/ChataigneOSCDemo.kt
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
56
orx-jvm/orx-chataigne/src/main/kotlin/ChataigneOSC.kt
Normal file
56
orx-jvm/orx-chataigne/src/main/kotlin/ChataigneOSC.kt
Normal file
@@ -0,0 +1,56 @@
|
||||
import mu.KotlinLogging
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.osc.OSC
|
||||
import java.awt.Color
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
private val logger = KotlinLogging.logger {}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
inner class ColorChannel(key: String) {
|
||||
private var currentColor = ColorRGBa.BLACK
|
||||
|
||||
init {
|
||||
osc.listen(key) {
|
||||
val red = it[0] as Float
|
||||
val green = it[1] as Float
|
||||
val blue = it[2] as Float
|
||||
val alpha = it[3] as Float
|
||||
|
||||
currentColor = ColorRGBa(red.toDouble(), green.toDouble(), blue.toDouble(), alpha.toDouble())
|
||||
}
|
||||
}
|
||||
|
||||
operator fun getValue(thisRef: Any?, property: KProperty<*>): ColorRGBa {
|
||||
return currentColor
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun update(seconds: Double) {
|
||||
osc.send("/setTime", seconds.toFloat())
|
||||
}
|
||||
|
||||
init {
|
||||
logger.info {
|
||||
"setup Chataigne with OSC ${osc.address} in:${osc.portIn} out:${osc.portOut}"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user