[orx-color] Add HPLuv and two demos

This commit is contained in:
Abe Pazos
2023-12-08 17:12:13 +01:00
parent 8fb8e11a56
commit 10ffb7ce59
5 changed files with 95 additions and 0 deletions

View File

@@ -8,6 +8,8 @@ import org.openrndr.extra.color.tools.shiftHue
/**
* Generate an analogous palette
* @param T the color model to use
* @param hueShift Hue degrees between the first and the last color
* @param steps Number of colors to create
*/
inline fun <reified T> ColorRGBa.analogous(hueShift: Double, steps: Int = 5): List<ColorRGBa>
where T : HueShiftableColor<T>,

View File

@@ -5,6 +5,7 @@ import org.openrndr.color.*
typealias RGB = ColorRGBa
typealias LAB = ColorLABa
typealias LUV = ColorLUVa
typealias HPLuv = ColorHPLUVa
typealias HSL = ColorHSLa
typealias HSV = ColorHSVa
typealias HSLuv = ColorHSLUVa

View File

@@ -18,6 +18,7 @@ inline fun <reified T : ColorModel<T>> ColorRGBa.convertTo(): T {
ColorHSLa::class -> this.toHSLa()
ColorHSVa::class -> this.toHSVa()
ColorRGBa::class -> this
ColorHPLUVa::class -> this.toHPLUVa()
ColorHSLUVa::class -> this.toHSLUVa()
ColorOKLABa::class -> this.toOKLABa()
ColorOKLCHa::class -> this.toOKLCHa()

View File

@@ -0,0 +1,60 @@
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.color.palettes.analogous
import org.openrndr.extra.color.palettes.splitComplementary
import org.openrndr.extra.color.palettes.tetradic
import org.openrndr.extra.color.palettes.triadic
import org.openrndr.extra.color.presets.ORANGE
import org.openrndr.extra.color.spaces.*
/**
* Demonstrates the creation of color palettes using various available methods
*/
fun main() = application {
configure { }
program {
// HueShiftableColor:
// HPLuv HSL HSV LCHab LCHuv XSL XSV XSLuv HSLuv OKHSL OKHSV OKLCH
val palette0 = RGB.PINK.analogous<HSLuv>(360.0, 10)
val palette1 = RGB.RED.analogous<HSL>(240.0, 3)
val palette2 = RGB.YELLOW.triadic<OKHSV>()
val palette3 = RGB.CYAN.tetradic<OKLCH>()
val palette4 = RGB.CYAN.tetradic<OKLCH>(0.5)
val palette5 = RGB.ORANGE.splitComplementary<HPLuv>(0.2, true)
extend {
drawer.clear(ColorRGBa.WHITE)
drawer.stroke = ColorRGBa.BLACK.opacify(0.25)
palette0.forEachIndexed { i, c ->
drawer.fill = c
drawer.circle(100.0 + i * 40.0, 80.0, 40.0)
}
palette1.forEachIndexed { i, c ->
drawer.fill = c
drawer.circle(100.0 + i * 40.0, 180.0, 40.0)
}
palette2.forEachIndexed { i, c ->
drawer.fill = c
drawer.circle(380.0 + i * 40.0, 180.0, 40.0)
}
palette3.forEachIndexed { i, c ->
drawer.fill = c
drawer.circle(100.0 + i * 40.0, 280.0, 40.0)
}
palette4.forEachIndexed { i, c ->
drawer.fill = c
drawer.circle(350.0 + i * 40.0, 280.0, 40.0)
}
palette5.forEachIndexed { i, c ->
drawer.fill = c
drawer.circle(100.0 + i * 40.0, 380.0, 40.0)
}
}
}
}

View File

@@ -0,0 +1,31 @@
import org.openrndr.application
import org.openrndr.extra.color.palettes.analogous
import org.openrndr.extra.color.spaces.HSLuv
import org.openrndr.extra.color.spaces.RGB
/**
* By default, generated palettes contain colors of varying hue
* but similar brightness and saturation.
* Here we alter the brightness of each color using .shade() for
* an increased dynamic range.
*/
fun main() = application {
program {
val count = 8
val palette = RGB.PINK.analogous<HSLuv>(360.0, count).mapIndexed { i, c ->
c.shade((i + 1.0) / count)
}.reversed()
extend {
drawer.stroke = null
palette.forEachIndexed { i, c ->
drawer.fill = c
drawer.rectangle(
0.0, i * height / count.toDouble(),
width.toDouble(), height / count.toDouble()
)
}
}
}
}