diff --git a/orx-jvm/orx-gui/build.gradle.kts b/orx-jvm/orx-gui/build.gradle.kts index 07325931..a2529af5 100644 --- a/orx-jvm/orx-gui/build.gradle.kts +++ b/orx-jvm/orx-gui/build.gradle.kts @@ -18,6 +18,7 @@ val demoRuntimeOnly by configurations.getting {} dependencies { api(project(":orx-parameters")) api(project(":orx-jvm:orx-panel")) + api(project(":orx-noise")) implementation(libs.openrndr.filter) implementation(libs.openrndr.dialogs) implementation(libs.gson) diff --git a/orx-jvm/orx-gui/src/main/kotlin/Gui.kt b/orx-jvm/orx-gui/src/main/kotlin/Gui.kt index a3e42ca0..b5cba0ff 100644 --- a/orx-jvm/orx-gui/src/main/kotlin/Gui.kt +++ b/orx-jvm/orx-gui/src/main/kotlin/Gui.kt @@ -10,11 +10,12 @@ import org.openrndr.dialogs.openFileDialog import org.openrndr.dialogs.saveFileDialog import org.openrndr.dialogs.setDefaultPathForContext import org.openrndr.draw.Drawer +import org.openrndr.extra.noise.Random +import org.openrndr.extra.noise.random +import org.openrndr.extra.noise.uniform import org.openrndr.extra.parameters.* import org.openrndr.internal.Driver -import org.openrndr.math.Vector2 -import org.openrndr.math.Vector3 -import org.openrndr.math.Vector4 +import org.openrndr.math.* import org.openrndr.panel.ControlManager import org.openrndr.panel.controlManager import org.openrndr.panel.elements.* @@ -863,16 +864,16 @@ class GUI(val baseColor:ColorRGBa = ColorRGBa.GRAY, val defaultStyles: List).get(labeledObject.obj) - val randomValue = Math.random() * (max - min) + min - val newValue = (1.0 - strength) * currentValue + randomValue * strength + val randomValue = random(min, max) + val newValue = mix(currentValue, randomValue, strength) (parameter.property as KMutableProperty1).set(labeledObject.obj, newValue) } ParameterType.Int -> { val min = parameter.intRange!!.first val max = parameter.intRange!!.last val currentValue = (parameter.property as KMutableProperty1).get(labeledObject.obj) - val randomValue = Math.random() * (max - min) + min - val newValue = ((1.0 - strength) * currentValue + randomValue * strength).roundToInt() + val randomValue = random(min.toDouble(), max.toDouble()) + val newValue = mix(currentValue.toDouble(), randomValue, strength).roundToInt() (parameter.property as KMutableProperty1).set(labeledObject.obj, newValue) } ParameterType.Boolean -> { @@ -881,43 +882,40 @@ class GUI(val baseColor:ColorRGBa = ColorRGBa.GRAY, val defaultStyles: List { val currentValue = (parameter.property as KMutableProperty1).get(labeledObject.obj) - val randomValue = ColorRGBa(Math.random(), Math.random(), Math.random(), currentValue.alpha) - val newValue = ColorRGBa((1.0 - strength) * currentValue.r + randomValue.r * strength, - (1.0 - strength) * currentValue.g + randomValue.g * strength, - (1.0 - strength) * currentValue.b + randomValue.b * strength) - + val randomValue = ColorRGBa.fromVector(Random.vector3(0.0, 1.0), currentValue.alpha, currentValue.linearity) + val newValue = currentValue.mix(randomValue, strength) (parameter.property as KMutableProperty1).set(labeledObject.obj, newValue) } ParameterType.Vector2 -> { val min = parameter.doubleRange!!.start val max = parameter.doubleRange!!.endInclusive val currentValue = (parameter.property as KMutableProperty1).get(labeledObject.obj) - val randomValue = Vector2(Math.random(), Math.random()) * (max - min) + min - val newValue = currentValue * (1.0 - strength) + randomValue * strength + val randomValue = Random.vector2(min, max) + val newValue = currentValue.mix(randomValue, strength) (parameter.property as KMutableProperty1).set(labeledObject.obj, newValue) } ParameterType.XY -> { val min = parameter.vectorRange!!.first val max = parameter.vectorRange!!.second val currentValue = (parameter.property as KMutableProperty1).get(labeledObject.obj) - val randomValue = Vector2(Math.random() * (max.x - min.x) + min.x, Math.random() * (max.y - min.y) + min.y) - val newValue = currentValue * (1.0 - strength) + randomValue * strength + val randomValue = Vector2.uniform(min, max) + val newValue = currentValue.mix(randomValue, strength) (parameter.property as KMutableProperty1).set(labeledObject.obj, newValue) } ParameterType.Vector3 -> { val min = parameter.doubleRange!!.start val max = parameter.doubleRange!!.endInclusive val currentValue = (parameter.property as KMutableProperty1).get(labeledObject.obj) - val randomValue = Vector3(Math.random(), Math.random(), Math.random()) * (max - min) + min - val newValue = currentValue * (1.0 - strength) + randomValue * strength + val randomValue = Random.vector3(min, max) + val newValue = currentValue.mix(randomValue, strength) (parameter.property as KMutableProperty1).set(labeledObject.obj, newValue) } ParameterType.Vector4 -> { val min = parameter.doubleRange!!.start val max = parameter.doubleRange!!.endInclusive val currentValue = (parameter.property as KMutableProperty1).get(labeledObject.obj) - val randomValue = Vector4(Math.random(), Math.random(), Math.random(), Math.random()) * (max - min) + min - val newValue = currentValue * (1.0 - strength) + randomValue * strength + val randomValue = Random.vector4(min, max) + val newValue = currentValue.mix(randomValue, strength) (parameter.property as KMutableProperty1).set(labeledObject.obj, newValue) } else -> {