add OptionParameter to lfo wave type (#90)

This commit is contained in:
Ricardo Matias
2020-05-07 13:13:45 +02:00
committed by GitHub
parent 538590c2f0
commit 0e3a1b4a4a
3 changed files with 15 additions and 11 deletions

View File

@@ -27,7 +27,7 @@ drawer.circle(0.0, 0.0, size.value)
### LFO ### LFO
```kotlin ```kotlin
val size = LFO(LFOWave.SINE) // default LFOWave.SAW val size = LFO(LFOWave.Sine) // default LFOWave.Saw
val freq = 0.5 val freq = 0.5
val phase = 0.5 val phase = 0.5

View File

@@ -2,7 +2,6 @@ import org.openrndr.application
import org.openrndr.color.ColorRGBa import org.openrndr.color.ColorRGBa
import org.openrndr.draw.isolated import org.openrndr.draw.isolated
import org.openrndr.extensions.SingleScreenshot import org.openrndr.extensions.SingleScreenshot
import org.openrndr.extra.timeoperators.Envelope
import org.openrndr.extra.timeoperators.LFO import org.openrndr.extra.timeoperators.LFO
import org.openrndr.extra.timeoperators.LFOWave import org.openrndr.extra.timeoperators.LFOWave
import org.openrndr.extra.timeoperators.TimeOperators import org.openrndr.extra.timeoperators.TimeOperators
@@ -11,7 +10,7 @@ fun main() {
application { application {
program { program {
val size = LFO() val size = LFO()
val rotation = LFO(LFOWave.SINE) val rotation = LFO(LFOWave.Sine)
if (System.getProperty("takeScreenshot") == "true") { if (System.getProperty("takeScreenshot") == "true") {
extend(SingleScreenshot()) { extend(SingleScreenshot()) {
this.outputFile = System.getProperty("screenshotPath") this.outputFile = System.getProperty("screenshotPath")

View File

@@ -1,18 +1,23 @@
package org.openrndr.extra.timeoperators 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.clamp
import org.openrndr.math.mod import org.openrndr.math.mod
import kotlin.math.* import kotlin.math.*
internal const val TAU = 2.0 * PI internal const val TAU = 2.0 * PI
// TODO: When there's a @DropdownParameter switch from Int to String enum class LFOWave {
enum class LFOWave(val wave: Int) { Saw, Sine, Square, Triangle
SAW(0), SINE(1), SQUARE(2), TRIANGLE(3)
} }
@Suppress("UNUSED") @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 private var current = 0.0
set(value) { set(value) {
field = clamp(value, 0.0, 1.0) 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 { fun sample(frequency: Double = 1.0, phase: Double = 0.0): Double {
return when(wave) { return when(wave) {
LFOWave.SAW -> saw(frequency, phase) LFOWave.Saw -> saw(frequency, phase)
LFOWave.SINE -> sine(frequency, phase) LFOWave.Sine -> sine(frequency, phase)
LFOWave.SQUARE -> square(frequency, phase) LFOWave.Square -> square(frequency, phase)
LFOWave.TRIANGLE -> triangle(frequency, phase) LFOWave.Triangle -> triangle(frequency, phase)
} }
} }