diff --git a/build.gradle b/build.gradle index a9311e5c..8215cf7d 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,9 @@ def multiplatformModules = [ "orx-shader-phrases", "orx-parameters", "orx-fx", - "orx-easing" + "orx-easing", + "orx-color" + ] diff --git a/orx-color/build.gradle b/orx-color/build.gradle deleted file mode 100644 index 920f1ede..00000000 --- a/orx-color/build.gradle +++ /dev/null @@ -1,21 +0,0 @@ -sourceSets { - demo { - java { - srcDirs = ["src/demo/kotlin"] - compileClasspath += main.getCompileClasspath() - runtimeClasspath += main.getRuntimeClasspath() - } - } -} - -dependencies { - implementation(project(":orx-shader-phrases")) - - demoImplementation(project(":orx-camera")) - demoImplementation(project(":orx-mesh-generators")) - demoImplementation("org.openrndr:openrndr-application:$openrndrVersion") - demoImplementation("org.openrndr:openrndr-extensions:$openrndrVersion") - demoRuntimeOnly("org.openrndr:openrndr-gl3:$openrndrVersion") - demoRuntimeOnly("org.openrndr:openrndr-gl3-natives-$openrndrOS:$openrndrVersion") - demoImplementation(sourceSets.getByName("main").output) -} \ No newline at end of file diff --git a/orx-color/build.gradle.kts b/orx-color/build.gradle.kts new file mode 100644 index 00000000..6e6dff4c --- /dev/null +++ b/orx-color/build.gradle.kts @@ -0,0 +1,96 @@ +import Orx_embed_shaders_gradle.EmbedShadersTask + +plugins { + kotlin("multiplatform") + kotlin("plugin.serialization") + id("orx.embed-shaders") +} + +val kotlinxSerializationVersion: String by rootProject.extra +val kotestVersion: String by rootProject.extra +val junitJupiterVersion: String by rootProject.extra +val jvmTarget: String by rootProject.extra +val kotlinApiVersion: String by rootProject.extra +val kotlinVersion: String by rootProject.extra +val kotlinLoggingVersion: String by rootProject.extra +val kluentVersion: String by rootProject.extra +val openrndrVersion: String by rootProject.extra +val openrndrOS: String by rootProject.extra +val spekVersion: String by rootProject.extra + +kotlin { + jvm { + compilations { + val demo by creating { + defaultSourceSet { + kotlin.srcDir("src/demo") + dependencies { + implementation(project(":orx-camera")) + implementation("org.openrndr:openrndr-application:$openrndrVersion") + implementation("org.openrndr:openrndr-extensions:$openrndrVersion") + runtimeOnly("org.openrndr:openrndr-gl3:$openrndrVersion") + runtimeOnly("org.openrndr:openrndr-gl3-natives-$openrndrOS:$openrndrVersion") + implementation(compilations["main"]!!.output.allOutputs) + } + } + } + } + compilations.all { + kotlinOptions.jvmTarget = jvmTarget + kotlinOptions.apiVersion = kotlinApiVersion + } + testRuns["test"].executionTask.configure { + useJUnitPlatform() + } + } + js(IR) { + browser() + nodejs() + } + + sourceSets { + @Suppress("UNUSED_VARIABLE") + val commonMain by getting { + dependencies { + implementation(project(":orx-parameters")) + implementation(project(":orx-shader-phrases")) + implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$kotlinxSerializationVersion") + implementation("org.openrndr:openrndr-application:$openrndrVersion") + implementation("org.openrndr:openrndr-draw:$openrndrVersion") + implementation("org.openrndr:openrndr-filter:$openrndrVersion") + implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion") + implementation("io.github.microutils:kotlin-logging:$kotlinLoggingVersion") + } + } + @Suppress("UNUSED_VARIABLE") + val commonTest by getting { + dependencies { + implementation(kotlin("test-common")) + implementation(kotlin("test-annotations-common")) + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxSerializationVersion") + implementation("io.kotest:kotest-assertions-core:$kotestVersion") + } + } + + @Suppress("UNUSED_VARIABLE") + val jvmTest by getting { + dependencies { + implementation(kotlin("test-common")) + implementation(kotlin("test-annotations-common")) + implementation(kotlin("test-junit5")) + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxSerializationVersion") + runtimeOnly("org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion") + runtimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion") + implementation("org.spekframework.spek2:spek-dsl-jvm:$spekVersion") + implementation("org.amshove.kluent:kluent:$kluentVersion") + } + } + + @Suppress("UNUSED_VARIABLE") + val jsTest by getting { + dependencies { + implementation(kotlin("test-js")) + } + } + } +} \ No newline at end of file diff --git a/orx-color/src/main/kotlin/palettes/Palettes.kt b/orx-color/src/commonMain/kotlin/palettes/Palettes.kt similarity index 100% rename from orx-color/src/main/kotlin/palettes/Palettes.kt rename to orx-color/src/commonMain/kotlin/palettes/Palettes.kt diff --git a/orx-color/src/main/kotlin/phrases/Phrases.kt b/orx-color/src/commonMain/kotlin/phrases/Phrases.kt similarity index 100% rename from orx-color/src/main/kotlin/phrases/Phrases.kt rename to orx-color/src/commonMain/kotlin/phrases/Phrases.kt diff --git a/orx-color/src/main/kotlin/presets/Colors.kt b/orx-color/src/commonMain/kotlin/presets/Colors.kt similarity index 100% rename from orx-color/src/main/kotlin/presets/Colors.kt rename to orx-color/src/commonMain/kotlin/presets/Colors.kt diff --git a/orx-color/src/main/kotlin/spaces/ColorHSLUVa.kt b/orx-color/src/commonMain/kotlin/spaces/ColorHSLUVa.kt similarity index 97% rename from orx-color/src/main/kotlin/spaces/ColorHSLUVa.kt rename to orx-color/src/commonMain/kotlin/spaces/ColorHSLUVa.kt index 8bb697fa..0e17e70d 100644 --- a/orx-color/src/main/kotlin/spaces/ColorHSLUVa.kt +++ b/orx-color/src/commonMain/kotlin/spaces/ColorHSLUVa.kt @@ -2,10 +2,7 @@ package org.openrndr.extras.color.spaces import org.openrndr.color.* import org.openrndr.math.mixAngle -import java.util.* -import kotlin.math.min -import kotlin.math.pow -import kotlin.math.sqrt +import kotlin.math.* private val m = arrayOf( doubleArrayOf(3.240969941904521, -1.537383177570093, -0.498610760293), @@ -42,7 +39,7 @@ private fun distanceFromPole(point: DoubleArray): Double { } private fun lengthOfRayUntilIntersect(theta: Double, line: DoubleArray): Length { - val length = line[1] / (Math.sin(theta) - line[0] * Math.cos(theta)) + val length = line[1] / (sin(theta) - line[0] * cos(theta)) return Length(length) } @@ -65,7 +62,7 @@ private fun maxSafeChromaForL(L100: Double): Double { } fun maxChromaForLH(L100: Double, H: Double): Double { - val hrad = H / 360 * Math.PI * 2 + val hrad = H / 360 * PI * 2 val bounds = getBounds(L100) var min = Double.MAX_VALUE for (bound in bounds!!) { diff --git a/orx-color/src/main/kotlin/spaces/ColorOKLABa.kt b/orx-color/src/commonMain/kotlin/spaces/ColorOKLABa.kt similarity index 100% rename from orx-color/src/main/kotlin/spaces/ColorOKLABa.kt rename to orx-color/src/commonMain/kotlin/spaces/ColorOKLABa.kt diff --git a/orx-color/src/main/kotlin/spaces/ColorOKLCHa.kt b/orx-color/src/commonMain/kotlin/spaces/ColorOKLCHa.kt similarity index 88% rename from orx-color/src/main/kotlin/spaces/ColorOKLCHa.kt rename to orx-color/src/commonMain/kotlin/spaces/ColorOKLCHa.kt index e445445d..10b7928b 100644 --- a/orx-color/src/main/kotlin/spaces/ColorOKLCHa.kt +++ b/orx-color/src/commonMain/kotlin/spaces/ColorOKLCHa.kt @@ -1,11 +1,10 @@ package org.openrndr.extras.color.spaces import org.openrndr.color.* +import org.openrndr.math.asDegrees +import org.openrndr.math.asRadians import org.openrndr.math.mixAngle -import kotlin.math.atan2 -import kotlin.math.cos -import kotlin.math.sin -import kotlin.math.sqrt +import kotlin.math.* /** * Color in cylindrical OKLab space @@ -24,9 +23,9 @@ data class ColorOKLCHa(val l: Double, val c: Double, val h: Double, val a: Doubl var h = atan2(oklaba.b, oklaba.a) if (h < 0) { - h += Math.PI * 2 + h += PI * 2 } - h = Math.toDegrees(h) + h = h.asDegrees return ColorOKLCHa(l, c, h, oklaba.alpha) } } @@ -42,8 +41,8 @@ data class ColorOKLCHa(val l: Double, val c: Double, val h: Double, val a: Doubl override fun mix(other: ColorOKLCHa, factor: Double) = mix(this, other, factor) fun toOKLABa(): ColorOKLABa { - val a = c * cos(Math.toRadians(h)) - val b = c * sin(Math.toRadians(h)) + val a = c * cos(h.asRadians) + val b = c * sin(h.asRadians) return ColorOKLABa(l, a, b, alpha = this.a) } diff --git a/orx-color/src/commonMain/kotlin/statistics/Histogram.kt b/orx-color/src/commonMain/kotlin/statistics/Histogram.kt new file mode 100644 index 00000000..fb363b01 --- /dev/null +++ b/orx-color/src/commonMain/kotlin/statistics/Histogram.kt @@ -0,0 +1,13 @@ +package org.openrndr.extras.color.statistics + +import org.openrndr.color.ColorRGBa +import org.openrndr.draw.ColorBuffer +import kotlin.random.Random + +private fun ColorRGBa.binIndex(binCount: Int): Triple { + val rb = (r * binCount).toInt().coerceIn(0, binCount - 1) + val gb = (g * binCount).toInt().coerceIn(0, binCount - 1) + val bb = (b * binCount).toInt().coerceIn(0, binCount - 1) + return Triple(rb, gb, bb) +} + diff --git a/orx-color/src/main/kotlin/statistics/Histogram.kt b/orx-color/src/jvmMain/src/statistics/Histogram.kt similarity index 76% rename from orx-color/src/main/kotlin/statistics/Histogram.kt rename to orx-color/src/jvmMain/src/statistics/Histogram.kt index 350ad3b0..941ed44c 100644 --- a/orx-color/src/main/kotlin/statistics/Histogram.kt +++ b/orx-color/src/jvmMain/src/statistics/Histogram.kt @@ -1,16 +1,3 @@ -package org.openrndr.extras.color.statistics - -import org.openrndr.color.ColorRGBa -import org.openrndr.draw.ColorBuffer -import kotlin.random.Random - -private fun ColorRGBa.binIndex(binCount: Int): Triple { - val rb = (r * binCount).toInt().coerceIn(0, binCount - 1) - val gb = (g * binCount).toInt().coerceIn(0, binCount - 1) - val bb = (b * binCount).toInt().coerceIn(0, binCount - 1) - return Triple(rb, gb, bb) -} - fun calculateHistogramRGB(buffer: ColorBuffer, binCount: Int = 16, weighting: ColorRGBa.() -> Double = { 1.0 }, @@ -51,7 +38,7 @@ class RGBHistogram(val freqs: Array>, val binCount: Int) { } fun color(rBin: Int, gBin: Int, bBin: Int): ColorRGBa = - ColorRGBa(rBin / (binCount - 1.0), gBin / (binCount - 1.0), bBin / (binCount - 1.0)) + ColorRGBa(rBin / (binCount - 1.0), gBin / (binCount - 1.0), bBin / (binCount - 1.0)) fun sample(random: Random = Random.Default): ColorRGBa { val x = random.nextDouble() @@ -75,13 +62,12 @@ class RGBHistogram(val freqs: Array>, val binCount: Int) { for (g in 0 until binCount) { for (b in 0 until binCount) { result += Pair( - ColorRGBa(r / (binCount - 1.0), g / (binCount - 1.0), b / (binCount - 1.0)), - freqs[r][g][b] + ColorRGBa(r / (binCount - 1.0), g / (binCount - 1.0), b / (binCount - 1.0)), + freqs[r][g][b] ) } } } return result.sortedByDescending { it.second } } -} - +} \ No newline at end of file diff --git a/orx-color/src/test/kotlin/TestMix.kt b/orx-color/src/jvmTest/kotlin/TestMix.kt similarity index 100% rename from orx-color/src/test/kotlin/TestMix.kt rename to orx-color/src/jvmTest/kotlin/TestMix.kt