Demos: ensure all use fun main() = application {

- Adjust some demo window sizes.
- Replace Random.double by Double.uniform
- Tweak some demos so screenshots look more interesting
This commit is contained in:
Abe Pazos
2025-01-26 20:57:04 +01:00
parent 1975a820fc
commit c8f7dd52c6
116 changed files with 2889 additions and 2942 deletions

View File

@@ -4,43 +4,41 @@ import org.openrndr.extra.gui.GUI
import org.openrndr.extra.gui.addTo
import org.openrndr.extra.parameters.TextParameter
fun main() {
application {
program {
val gui = GUI()
gui.compartmentsCollapsedByDefault = false
fun main() = application {
program {
val gui = GUI()
gui.compartmentsCollapsedByDefault = false
val settings = object {
@TextParameter("x expression", order = 10)
var xExpression = "cos(t) * 50.0 + width / 2.0"
val settings = object {
@TextParameter("x expression", order = 10)
var xExpression = "cos(t) * 50.0 + width / 2.0"
@TextParameter("y expression", order = 20)
var yExpression = "sin(t) * 50.0 + height / 2.0"
@TextParameter("y expression", order = 20)
var yExpression = "sin(t) * 50.0 + height / 2.0"
@TextParameter("radius expression", order = 30)
var radiusExpression = "cos(t) * 50.0 + 50.0"
}.addTo(gui)
@TextParameter("radius expression", order = 30)
var radiusExpression = "cos(t) * 50.0 + 50.0"
}.addTo(gui)
extend(gui)
extend {
//gui.visible = mouse.position.x < 200.0
extend(gui)
extend {
//gui.visible = mouse.position.x < 200.0
val expressionContext =
mapOf("t" to seconds, "width" to drawer.bounds.width, "height" to drawer.bounds.height)
val expressionContext =
mapOf("t" to seconds, "width" to drawer.bounds.width, "height" to drawer.bounds.height)
fun eval(expression: String): Double =
try {
evaluateExpression(expression, expressionContext) ?: 0.0
} catch (e: Throwable) {
0.0
}
fun eval(expression: String): Double =
try {
evaluateExpression(expression, expressionContext) ?: 0.0
} catch (e: Throwable) {
0.0
}
val x = eval(settings.xExpression)
val y = eval(settings.yExpression)
val radius = eval(settings.radiusExpression)
val x = eval(settings.xExpression)
val y = eval(settings.yExpression)
val radius = eval(settings.radiusExpression)
drawer.circle(x, y, radius)
}
drawer.circle(x, y, radius)
}
}
}
}

View File

@@ -8,37 +8,35 @@ import org.openrndr.extra.parameters.TextParameter
* Improved version of DemoExpressionEvaluator01, it uses [watchingExpression1] to automatically convert an expression
* string into a function with a parameter "t".
*/
fun main() {
application {
program {
val gui = GUI()
gui.compartmentsCollapsedByDefault = false
fun main() = application {
program {
val gui = GUI()
gui.compartmentsCollapsedByDefault = false
// the constants used in our expressions
val constants = mutableMapOf("width" to drawer.width.toDouble(), "height" to drawer.height.toDouble())
// the constants used in our expressions
val constants = mutableMapOf("width" to drawer.width.toDouble(), "height" to drawer.height.toDouble())
val settings = object {
@TextParameter("x expression", order = 10)
var xExpression = "cos(t) * 50.0 + width / 2.0"
val settings = object {
@TextParameter("x expression", order = 10)
var xExpression = "cos(t) * 50.0 + width / 2.0"
@TextParameter("y expression", order = 20)
var yExpression = "sin(t) * 50.0 + height / 2.0"
@TextParameter("y expression", order = 20)
var yExpression = "sin(t) * 50.0 + height / 2.0"
@TextParameter("radius expression", order = 30)
var radiusExpression = "cos(t) * 50.0 + 50.0"
}.addTo(gui)
@TextParameter("radius expression", order = 30)
var radiusExpression = "cos(t) * 50.0 + 50.0"
}.addTo(gui)
val xFunction by watchingExpression1(settings::xExpression, "t", constants)
val yFunction by watchingExpression1(settings::yExpression, "t", constants)
val radiusFunction by watchingExpression1(settings::radiusExpression, "t", constants)
val xFunction by watchingExpression1(settings::xExpression, "t", constants)
val yFunction by watchingExpression1(settings::yExpression, "t", constants)
val radiusFunction by watchingExpression1(settings::radiusExpression, "t", constants)
extend(gui)
extend {
val x = xFunction(seconds)
val y = yFunction(seconds)
val radius = radiusFunction(seconds)
drawer.circle(x, y, radius)
}
extend(gui)
extend {
val x = xFunction(seconds)
val y = yFunction(seconds)
val radius = radiusFunction(seconds)
drawer.circle(x, y, radius)
}
}
}
}