[orx-fcurve] Replace _expr_ with {expr}

This commit is contained in:
Edwin Jakobs
2024-03-30 16:26:23 +01:00
parent 513678d29b
commit feb8d8641e
3 changed files with 10 additions and 10 deletions

View File

@@ -152,7 +152,7 @@ In this example we used `% 9.0` to loop the time between 0.0 and 9.0, repeating
# EFCurves
Extended Fcurves have a additional preprocessing step in which scalar expressions are evaluated.
Extended Fcurves have an additional preprocessing step in which scalar expressions are evaluated.
## Comments
@@ -170,10 +170,10 @@ L5,5
## Expressions
Expressions wrapped in underscore characters (`_`) are evaluated using `orx-expression-evaluator`.
Expressions within curly brackets are evaluated using `orx-expression-evaluator`.
Please refer to its [documentation](https://github.com/openrndr/orx/tree/master/orx-expression-evaluator) for details on the expression language used.
For example: `M0 L_3 * 4_,4` evaluates to `M0 L12,4`.
For example: `M0 L{3 * 4},4` evaluates to `M0 L12,4`.
## Repetitions
@@ -193,9 +193,9 @@ For example `|M0 |h1 m1|[3]|[2]` expands to `M0 h1 m1 h1 m1 h1 m1 M0 h1 m1 h1 m1
### Interaction between repetitions and expressions
`M0 |H_it + 1_ m1][3]` expands to `M0 H1 m1 H2 m1 H3 m1`
`M0 |H{it + 1} m1][3]` expands to `M0 H1 m1 H2 m1 H3 m1`
`M0 |H_index + 1_ m_it_]{1.2, 1.3, 1.4}` expands to `M0 H1 m1.2 H2 m1.3 H3 m1.4`
`M0 |H{index + 1} m{it}]{1.2, 1.3, 1.4}` expands to `M0 H1 m1.2 H2 m1.3 H3 m1.4`
# References

View File

@@ -8,7 +8,7 @@ import org.openrndr.extra.expressions.evaluateExpression
* @param constants a map of constants that is passed to [evaluateExpression]
*/
fun efcurve(ef: String, constants: Map<String, Double> = emptyMap()): String {
val expression = Regex("_([^_]+)_")
val expression = Regex("\\{([^_]+)\\}")
// 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`

View File

@@ -16,18 +16,18 @@ class TestEFCurve {
@Test
fun expressions() {
assertEquals("M${9.0}", efcurve("M_4 + 5_"))
assertEquals("M${9.0}", efcurve("M{4 + 5}"))
}
@Test
fun listExpansion() {
assertEquals("M0 L1.0, ${3.0} L1.0, ${6.0}", efcurve("M0 |L1.0, _it_|{3, 6}"))
assertEquals("M0 L1.0, ${3.0} L1.0, ${6.0}", efcurve("M0 |L1.0, {it}|{3, 6}"))
}
@Test
fun repetition() {
assertEquals("M0 L1.0, 3.0 L1.0, 3.0", efcurve("M0 |L1.0, 3.0|[2]"))
assertEquals("M0 L1.0, ${0.0} L1.0, ${1.0}", efcurve("M0 |L1.0, _it_|[2]"))
assertEquals("M0 L1.0, ${0.0} L1.0, ${1.0} L1.0, ${0.0} L1.0, ${1.0} L1.0, ${0.0} L1.0, ${1.0}", efcurve("M0 ||L1.0, _it_|[2]|[3]"))
assertEquals("M0 L1.0, ${0.0} L1.0, ${1.0}", efcurve("M0 |L1.0, {it}|[2]"))
assertEquals("M0 L1.0, ${0.0} L1.0, ${1.0} L1.0, ${0.0} L1.0, ${1.0} L1.0, ${0.0} L1.0, ${1.0}", efcurve("M0 ||L1.0, {it}|[2]|[3]"))
}
}