Add orx-keyframer
This commit is contained in:
23
orx-keyframer/src/demo/kotlin/DemoFull01.kt
Normal file
23
orx-keyframer/src/demo/kotlin/DemoFull01.kt
Normal file
@@ -0,0 +1,23 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.extra.keyframer.Keyframer
|
||||
import org.openrndr.extra.keyframer.KeyframerFormat
|
||||
import org.openrndr.resourceUrl
|
||||
import java.net.URL
|
||||
|
||||
fun main() = application {
|
||||
program {
|
||||
class Animation: Keyframer() {
|
||||
val position by Vector2Channel(arrayOf("x", "y"))
|
||||
val radius by DoubleChannel("radius")
|
||||
val color by RGBChannel(arrayOf("r", "g", "b"))
|
||||
}
|
||||
val animation = Animation()
|
||||
animation.loadFromJson(URL(resourceUrl("/demo-full-01.json")), format = KeyframerFormat.FULL)
|
||||
|
||||
extend {
|
||||
animation(seconds)
|
||||
drawer.fill = animation.color
|
||||
drawer.circle(animation.position, animation.radius)
|
||||
}
|
||||
}
|
||||
}
|
||||
47
orx-keyframer/src/demo/kotlin/DemoScrub01.kt
Normal file
47
orx-keyframer/src/demo/kotlin/DemoScrub01.kt
Normal file
@@ -0,0 +1,47 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.extra.keyframer.Keyframer
|
||||
import org.openrndr.panel.controlManager
|
||||
import org.openrndr.panel.elements.Range
|
||||
import org.openrndr.panel.elements.Slider
|
||||
import org.openrndr.panel.elements.slider
|
||||
import org.openrndr.resourceUrl
|
||||
import java.net.URL
|
||||
|
||||
fun main() = application {
|
||||
program {
|
||||
|
||||
// -- replace the default clock with an offset clock
|
||||
var clockOffset = 0.0
|
||||
val oldClock = clock
|
||||
clock = { oldClock() - clockOffset }
|
||||
var clockSlider: Slider? = null
|
||||
|
||||
// -- setup a simple UI
|
||||
val cm = controlManager {
|
||||
layout {
|
||||
clockSlider = slider {
|
||||
range = Range(0.0, 30.0)
|
||||
events.valueChanged.listen {
|
||||
if (it.interactive) {
|
||||
clockOffset = oldClock() - it.newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
extend(cm)
|
||||
|
||||
class Animation: Keyframer() {
|
||||
val position by Vector2Channel(arrayOf("x", "y"))
|
||||
}
|
||||
val animation = Animation()
|
||||
animation.loadFromJson(URL(resourceUrl("/demo-simple-01.json")))
|
||||
|
||||
extend {
|
||||
// -- update the slider
|
||||
clockSlider?.value = seconds
|
||||
animation(seconds)
|
||||
drawer.circle(animation.position, 100.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
19
orx-keyframer/src/demo/kotlin/DemoSimple01.kt
Normal file
19
orx-keyframer/src/demo/kotlin/DemoSimple01.kt
Normal file
@@ -0,0 +1,19 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.extra.keyframer.Keyframer
|
||||
import org.openrndr.resourceUrl
|
||||
import java.net.URL
|
||||
|
||||
fun main() = application {
|
||||
program {
|
||||
class Animation: Keyframer() {
|
||||
val position by Vector2Channel(arrayOf("x", "y"))
|
||||
}
|
||||
val animation = Animation()
|
||||
animation.loadFromJson(URL(resourceUrl("/demo-simple-01.json")))
|
||||
|
||||
extend {
|
||||
animation(seconds)
|
||||
drawer.circle(animation.position, 100.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
21
orx-keyframer/src/demo/kotlin/DemoSimple02.kt
Normal file
21
orx-keyframer/src/demo/kotlin/DemoSimple02.kt
Normal file
@@ -0,0 +1,21 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.extra.keyframer.Keyframer
|
||||
import org.openrndr.resourceUrl
|
||||
import java.net.URL
|
||||
|
||||
fun main() = application {
|
||||
program {
|
||||
class Animation: Keyframer() {
|
||||
val position by Vector2Channel(arrayOf("x", "y"))
|
||||
val radius by DoubleChannel("radius")
|
||||
val color by RGBChannel(arrayOf("r", "g", "b"))
|
||||
}
|
||||
val animation = Animation()
|
||||
animation.loadFromJson(URL(resourceUrl("/demo-simple-02.json")))
|
||||
extend {
|
||||
animation(seconds)
|
||||
drawer.fill = animation.color
|
||||
drawer.circle(animation.position, animation.radius)
|
||||
}
|
||||
}
|
||||
}
|
||||
22
orx-keyframer/src/demo/kotlin/DemoSimpleExpressions01.kt
Normal file
22
orx-keyframer/src/demo/kotlin/DemoSimpleExpressions01.kt
Normal file
@@ -0,0 +1,22 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.extra.keyframer.Keyframer
|
||||
import org.openrndr.resourceUrl
|
||||
import java.net.URL
|
||||
|
||||
fun main() = application {
|
||||
program {
|
||||
class Animation : Keyframer() {
|
||||
val position by Vector2Channel(arrayOf("x", "y"))
|
||||
val radius by DoubleChannel("x")
|
||||
}
|
||||
|
||||
val animation = Animation()
|
||||
animation.loadFromJson(URL(resourceUrl("/demo-simple-expressions-01.json")),
|
||||
parameters = mapOf("cycleDuration" to 2.0))
|
||||
|
||||
extend {
|
||||
animation(seconds)
|
||||
drawer.circle(animation.position, animation.radius)
|
||||
}
|
||||
}
|
||||
}
|
||||
20
orx-keyframer/src/demo/kotlin/DemoSimpleRepetitions01.kt
Normal file
20
orx-keyframer/src/demo/kotlin/DemoSimpleRepetitions01.kt
Normal file
@@ -0,0 +1,20 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.extra.keyframer.Keyframer
|
||||
import org.openrndr.resourceUrl
|
||||
import java.net.URL
|
||||
|
||||
fun main() = application {
|
||||
program {
|
||||
class Animation: Keyframer() {
|
||||
val position by Vector2Channel(arrayOf("x", "y"))
|
||||
val radius by DoubleChannel("x")
|
||||
}
|
||||
val animation = Animation()
|
||||
animation.loadFromJson(URL(resourceUrl("/demo-simple-repetitions-01.json")))
|
||||
|
||||
extend {
|
||||
animation(seconds)
|
||||
drawer.circle(animation.position, animation.radius)
|
||||
}
|
||||
}
|
||||
}
|
||||
74
orx-keyframer/src/demo/resources/demo-full-01.json
Normal file
74
orx-keyframer/src/demo/resources/demo-full-01.json
Normal file
@@ -0,0 +1,74 @@
|
||||
{
|
||||
// this is breaking with proper json but.. gson accepts comments and they are invaluable
|
||||
// in the parameters block you can add custom values, which can be used in expressions
|
||||
"parameters": {
|
||||
"smallRadius": 5.0,
|
||||
"repetitionCount": 10,
|
||||
"width": 640.0,
|
||||
"height": 480.0,
|
||||
// you can have expressions inside parameters too, they are evaluated once, on load
|
||||
"resolvedOnLoad" : "width * 2.0"
|
||||
},
|
||||
// in the prototypes you can set up key prototypes
|
||||
"prototypes": {
|
||||
"red": {
|
||||
"r": 1.0,
|
||||
"g": 0.0,
|
||||
"b": 0.0
|
||||
},
|
||||
"blue": {
|
||||
"r": 0.0,
|
||||
"g": 0.0,
|
||||
"b": 1.0
|
||||
},
|
||||
"center": {
|
||||
// prototypes can have expressions too, they are evaluated as late as possible
|
||||
// thus, they are evaluated more than once
|
||||
"x": "width / 2",
|
||||
"y": "height / 2"
|
||||
},
|
||||
"small": {
|
||||
"radius": "smallRadius"
|
||||
},
|
||||
"large": {
|
||||
"radius": "smallRadius * 10.0"
|
||||
}
|
||||
},
|
||||
"keys": [
|
||||
{
|
||||
"time": 0.0,
|
||||
"easing": "cubic-in-out",
|
||||
"x": 3.0,
|
||||
"y": 4.0,
|
||||
"z": 9.0,
|
||||
"r": 0.0,
|
||||
"g": 1.0,
|
||||
"b": 0.0,
|
||||
"radius": 50,
|
||||
"foo" : 0.0
|
||||
},
|
||||
{
|
||||
"time": 2.0,
|
||||
"easing": "cubic-in-out",
|
||||
// here we apply the prototypes in cascading fashion from left to right
|
||||
"prototypes": "red center small"
|
||||
},
|
||||
{
|
||||
"time": 3.0,
|
||||
"repeat": {
|
||||
"count": "repetitionCount",
|
||||
"keys": [
|
||||
{
|
||||
"time": "(rep * 2.0) + 3.0",
|
||||
"prototypes": "blue large",
|
||||
"easing": "cubic-in-out"
|
||||
},
|
||||
{
|
||||
"time": "t + 1.0",
|
||||
"prototypes": "red small"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
20
orx-keyframer/src/demo/resources/demo-simple-01.json
Normal file
20
orx-keyframer/src/demo/resources/demo-simple-01.json
Normal file
@@ -0,0 +1,20 @@
|
||||
[
|
||||
{
|
||||
"time": 0.0,
|
||||
"x": 320.0,
|
||||
"y": 240.0
|
||||
},
|
||||
{
|
||||
"time": 10.0,
|
||||
"x": 0.0,
|
||||
"y": 0.0,
|
||||
"easing": "cubic-in-out"
|
||||
},
|
||||
{
|
||||
"time": 20.0,
|
||||
"x": 640.0,
|
||||
"y": 480.0,
|
||||
"easing": "cubic-in-out"
|
||||
}
|
||||
|
||||
]
|
||||
32
orx-keyframer/src/demo/resources/demo-simple-02.json
Normal file
32
orx-keyframer/src/demo/resources/demo-simple-02.json
Normal file
@@ -0,0 +1,32 @@
|
||||
[
|
||||
{
|
||||
"time": 0.0,
|
||||
"x": 320.0,
|
||||
"y": 240.0,
|
||||
"radius": 0.0,
|
||||
"r": 1.0,
|
||||
"g": 1.0,
|
||||
"b": 1.0
|
||||
},
|
||||
{
|
||||
"time": 5.0,
|
||||
"radius": 200.0,
|
||||
"r": 0.0
|
||||
},
|
||||
{
|
||||
"time": 10.0,
|
||||
"g": 0.0,
|
||||
"x": 0.0,
|
||||
"y": 0.0,
|
||||
"easing": "cubic-in-out"
|
||||
},
|
||||
{
|
||||
"time": 20.0,
|
||||
"x": 640.0,
|
||||
"y": 480.0,
|
||||
"radius": 50.0,
|
||||
"easing": "cubic-in-out",
|
||||
"g": 1.0,
|
||||
"b": 0.0
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,30 @@
|
||||
[
|
||||
{
|
||||
"time": 0.0,
|
||||
"x": 320.0,
|
||||
"y": 240.0,
|
||||
"radius": 0.0
|
||||
},
|
||||
{
|
||||
"time": 3.0,
|
||||
"repeat": {
|
||||
"count": 5,
|
||||
"keys": [
|
||||
{
|
||||
"duration": "cycleDuration * 0.5",
|
||||
"easing": "cubic-in-out",
|
||||
"x": 10.0,
|
||||
"y": 4.0,
|
||||
"radius": 400
|
||||
},
|
||||
{
|
||||
"duration": "cycleDuration * 0.5",
|
||||
"easing": "cubic-in-out",
|
||||
"x": 630.0,
|
||||
"y": 470.0,
|
||||
"radius": 40
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,30 @@
|
||||
[
|
||||
{
|
||||
"time": 0.0,
|
||||
"x": 320.0,
|
||||
"y": 240.0,
|
||||
"radius": 0.0
|
||||
},
|
||||
{
|
||||
"time": 3.0,
|
||||
"repeat": {
|
||||
"count": 5,
|
||||
"keys": [
|
||||
{
|
||||
"duration": 1.0,
|
||||
"easing": "cubic-in-out",
|
||||
"x": 10.0,
|
||||
"y": 4.0,
|
||||
"radius": 400
|
||||
},
|
||||
{
|
||||
"duration": 1.0,
|
||||
"easing": "cubic-in-out",
|
||||
"x": 630.0,
|
||||
"y": 470.0,
|
||||
"radius": 40
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user