add OptionParameter to lfo wave type (#90)
This commit is contained in:
@@ -27,7 +27,7 @@ drawer.circle(0.0, 0.0, size.value)
|
||||
### LFO
|
||||
|
||||
```kotlin
|
||||
val size = LFO(LFOWave.SINE) // default LFOWave.SAW
|
||||
val size = LFO(LFOWave.Sine) // default LFOWave.Saw
|
||||
|
||||
val freq = 0.5
|
||||
val phase = 0.5
|
||||
|
||||
@@ -2,7 +2,6 @@ import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.isolated
|
||||
import org.openrndr.extensions.SingleScreenshot
|
||||
import org.openrndr.extra.timeoperators.Envelope
|
||||
import org.openrndr.extra.timeoperators.LFO
|
||||
import org.openrndr.extra.timeoperators.LFOWave
|
||||
import org.openrndr.extra.timeoperators.TimeOperators
|
||||
@@ -11,7 +10,7 @@ fun main() {
|
||||
application {
|
||||
program {
|
||||
val size = LFO()
|
||||
val rotation = LFO(LFOWave.SINE)
|
||||
val rotation = LFO(LFOWave.Sine)
|
||||
if (System.getProperty("takeScreenshot") == "true") {
|
||||
extend(SingleScreenshot()) {
|
||||
this.outputFile = System.getProperty("screenshotPath")
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
package org.openrndr.extra.timeoperators
|
||||
|
||||
import org.openrndr.extra.parameters.Description
|
||||
import org.openrndr.extra.parameters.OptionParameter
|
||||
import org.openrndr.math.clamp
|
||||
import org.openrndr.math.mod
|
||||
import kotlin.math.*
|
||||
|
||||
internal const val TAU = 2.0 * PI
|
||||
|
||||
// TODO: When there's a @DropdownParameter switch from Int to String
|
||||
enum class LFOWave(val wave: Int) {
|
||||
SAW(0), SINE(1), SQUARE(2), TRIANGLE(3)
|
||||
enum class LFOWave {
|
||||
Saw, Sine, Square, Triangle
|
||||
}
|
||||
|
||||
@Suppress("UNUSED")
|
||||
class LFO(var wave: LFOWave = LFOWave.SAW) : TimeTools {
|
||||
@Description("LFO")
|
||||
class LFO(wave: LFOWave = LFOWave.Saw) : TimeTools {
|
||||
@OptionParameter("Wave")
|
||||
var wave = wave
|
||||
|
||||
private var current = 0.0
|
||||
set(value) {
|
||||
field = clamp(value, 0.0, 1.0)
|
||||
@@ -28,10 +33,10 @@ class LFO(var wave: LFOWave = LFOWave.SAW) : TimeTools {
|
||||
|
||||
fun sample(frequency: Double = 1.0, phase: Double = 0.0): Double {
|
||||
return when(wave) {
|
||||
LFOWave.SAW -> saw(frequency, phase)
|
||||
LFOWave.SINE -> sine(frequency, phase)
|
||||
LFOWave.SQUARE -> square(frequency, phase)
|
||||
LFOWave.TRIANGLE -> triangle(frequency, phase)
|
||||
LFOWave.Saw -> saw(frequency, phase)
|
||||
LFOWave.Sine -> sine(frequency, phase)
|
||||
LFOWave.Square -> square(frequency, phase)
|
||||
LFOWave.Triangle -> triangle(frequency, phase)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user