[orx-fcurve] Add mfcurve, FCurve.min, FCurve.max, DemoFCurveSheet01.kt

This commit is contained in:
Edwin Jakobs
2024-05-13 08:30:05 +02:00
parent 968d544d3b
commit cc92dc26b2
6 changed files with 348 additions and 50 deletions

View File

@@ -3,6 +3,34 @@ package org.openrndr.extra.fcurve
import org.openrndr.extra.expressions.FunctionExtensions
import org.openrndr.extra.expressions.evaluateExpression
/**
* expand mfcurve to fcurve
*/
fun mfcurve(
mf: String,
constants: Map<String, Double> = emptyMap(),
functions: FunctionExtensions = FunctionExtensions.EMPTY
): String {
/**
* perform comment substitution
*/
val stripped = Regex("(#.*)$", RegexOption.MULTILINE).replace(mf, "")
/**
* detect modifier
*/
val parts = stripped.split("|")
val efcurve = parts.getOrElse(0) { "" }
val modifier = parts.getOrNull(1)
var fcurve = efcurve(efcurve, constants, functions)
if (modifier != null) {
fcurve = modifyFCurve(fcurve, modifier, constants, functions)
}
return fcurve
}
/**
* expand efcurve to fcurve
* @param ef an efcurve string
@@ -12,7 +40,6 @@ fun efcurve(
ef: String,
constants: Map<String, Double> = emptyMap(),
functions: FunctionExtensions = FunctionExtensions.EMPTY
): String {
// IntelliJ falsely reports a redundant escape character. the escape character is required when running the regular
// expression on a javascript target. Removing the escape character will result in a `Lone quantifier brackets`