[orx-gui] Fix color randomization (#266)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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<Styl
|
||||
val min = parameter.doubleRange!!.start
|
||||
val max = parameter.doubleRange!!.endInclusive
|
||||
val currentValue = (parameter.property as KMutableProperty1<Any, Double>).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<Any, Double>).set(labeledObject.obj, newValue)
|
||||
}
|
||||
ParameterType.Int -> {
|
||||
val min = parameter.intRange!!.first
|
||||
val max = parameter.intRange!!.last
|
||||
val currentValue = (parameter.property as KMutableProperty1<Any, Int>).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<Any, Int>).set(labeledObject.obj, newValue)
|
||||
}
|
||||
ParameterType.Boolean -> {
|
||||
@@ -881,43 +882,40 @@ class GUI(val baseColor:ColorRGBa = ColorRGBa.GRAY, val defaultStyles: List<Styl
|
||||
}
|
||||
ParameterType.Color -> {
|
||||
val currentValue = (parameter.property as KMutableProperty1<Any, ColorRGBa>).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<Any, ColorRGBa>).set(labeledObject.obj, newValue)
|
||||
}
|
||||
ParameterType.Vector2 -> {
|
||||
val min = parameter.doubleRange!!.start
|
||||
val max = parameter.doubleRange!!.endInclusive
|
||||
val currentValue = (parameter.property as KMutableProperty1<Any, Vector2>).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<Any, Vector2>).set(labeledObject.obj, newValue)
|
||||
}
|
||||
ParameterType.XY -> {
|
||||
val min = parameter.vectorRange!!.first
|
||||
val max = parameter.vectorRange!!.second
|
||||
val currentValue = (parameter.property as KMutableProperty1<Any, Vector2>).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<Any, Vector2>).set(labeledObject.obj, newValue)
|
||||
}
|
||||
ParameterType.Vector3 -> {
|
||||
val min = parameter.doubleRange!!.start
|
||||
val max = parameter.doubleRange!!.endInclusive
|
||||
val currentValue = (parameter.property as KMutableProperty1<Any, Vector3>).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<Any, Vector3>).set(labeledObject.obj, newValue)
|
||||
}
|
||||
ParameterType.Vector4 -> {
|
||||
val min = parameter.doubleRange!!.start
|
||||
val max = parameter.doubleRange!!.endInclusive
|
||||
val currentValue = (parameter.property as KMutableProperty1<Any, Vector4>).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<Any, Vector4>).set(labeledObject.obj, newValue)
|
||||
}
|
||||
else -> {
|
||||
|
||||
Reference in New Issue
Block a user