[orx-envelopes] Add trigger id and object functions

This commit is contained in:
Edwin Jakobs
2023-04-26 10:46:17 +02:00
parent a732a0559d
commit 1f6e60faa0
8 changed files with 145 additions and 40 deletions

View File

@@ -0,0 +1,46 @@
import org.openrndr.application
import org.openrndr.draw.loadFont
import org.openrndr.extra.envelopes.ADSRTracker
import org.openrndr.extra.noise.uniform
import org.openrndr.shape.Rectangle
fun main() {
application {
program {
val tracker = ADSRTracker(this)
tracker.attack = 1.0
tracker.decay = 0.2
tracker.sustain = 0.8
tracker.release = 2.0
keyboard.keyDown.listen {
if (it.name == "t") {
val center = drawer.bounds.uniform(distanceToEdge = 30.0)
tracker.triggerOn(0) { time, value, position ->
drawer.circle(center, value * 100.0)
}
}
if (it.name == "r") {
val center = drawer.bounds.uniform(distanceToEdge = 30.0)
tracker.triggerOn(1) { time, value, position ->
val r = Rectangle.fromCenter(center, width = value * 100.0, height = value * 100.0)
drawer.rectangle(r)
}
}
}
keyboard.keyUp.listen {
if (it.name == "t")
tracker.triggerOff(0)
if (it.name == "r")
tracker.triggerOff(1)
}
extend {
tracker.values().forEach {
it()
}
drawer.fontMap = loadFont("demo-data/fonts/IBMPlexMono-Regular.ttf", 16.0)
drawer.text("press and hold 't' and/or 'r'", 20.0, height - 20.0)
}
}
}
}