[orx-color] Add HPLuv and two demos
This commit is contained in:
@@ -8,6 +8,8 @@ import org.openrndr.extra.color.tools.shiftHue
|
|||||||
/**
|
/**
|
||||||
* Generate an analogous palette
|
* Generate an analogous palette
|
||||||
* @param T the color model to use
|
* @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>
|
inline fun <reified T> ColorRGBa.analogous(hueShift: Double, steps: Int = 5): List<ColorRGBa>
|
||||||
where T : HueShiftableColor<T>,
|
where T : HueShiftableColor<T>,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import org.openrndr.color.*
|
|||||||
typealias RGB = ColorRGBa
|
typealias RGB = ColorRGBa
|
||||||
typealias LAB = ColorLABa
|
typealias LAB = ColorLABa
|
||||||
typealias LUV = ColorLUVa
|
typealias LUV = ColorLUVa
|
||||||
|
typealias HPLuv = ColorHPLUVa
|
||||||
typealias HSL = ColorHSLa
|
typealias HSL = ColorHSLa
|
||||||
typealias HSV = ColorHSVa
|
typealias HSV = ColorHSVa
|
||||||
typealias HSLuv = ColorHSLUVa
|
typealias HSLuv = ColorHSLUVa
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ inline fun <reified T : ColorModel<T>> ColorRGBa.convertTo(): T {
|
|||||||
ColorHSLa::class -> this.toHSLa()
|
ColorHSLa::class -> this.toHSLa()
|
||||||
ColorHSVa::class -> this.toHSVa()
|
ColorHSVa::class -> this.toHSVa()
|
||||||
ColorRGBa::class -> this
|
ColorRGBa::class -> this
|
||||||
|
ColorHPLUVa::class -> this.toHPLUVa()
|
||||||
ColorHSLUVa::class -> this.toHSLUVa()
|
ColorHSLUVa::class -> this.toHSLUVa()
|
||||||
ColorOKLABa::class -> this.toOKLABa()
|
ColorOKLABa::class -> this.toOKLABa()
|
||||||
ColorOKLCHa::class -> this.toOKLCHa()
|
ColorOKLCHa::class -> this.toOKLCHa()
|
||||||
|
|||||||
60
orx-color/src/jvmDemo/kotlin/DemoColorPalette01.kt
Normal file
60
orx-color/src/jvmDemo/kotlin/DemoColorPalette01.kt
Normal 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
31
orx-color/src/jvmDemo/kotlin/DemoColorPalette02.kt
Normal file
31
orx-color/src/jvmDemo/kotlin/DemoColorPalette02.kt
Normal 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()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user