[orx-color] Improve DemoHSLUV02

This commit is contained in:
Edwin Jakobs
2020-08-22 00:20:32 +02:00
parent 590a49c3e9
commit 507b9b2557

View File

@@ -1,4 +1,4 @@
// Visualize HSLUV color space
// Visualize HSLUV color space by drawing a phyllotaxis pattern
import org.openrndr.application
import org.openrndr.color.ColorRGBa
@@ -6,9 +6,22 @@ import org.openrndr.extensions.SingleScreenshot
import org.openrndr.extras.color.spaces.toHSLUVa
import org.openrndr.math.Polar
import org.openrndr.math.Vector2
import kotlin.math.sqrt
fun main() {
application {
configure {
width = 720
height = 720
}
val g = Math.PI * 2.0 * (1.0 - 1.0 / 1.61803398875)
fun phyllotaxis(count: Int) = sequence {
for (i in 0 until count) {
yield(Polar(Math.toDegrees(i * 1.0), g * i))
}
}
program {
// -- this block is for automation purposes only
if (System.getProperty("takeScreenshot") == "true") {
@@ -18,17 +31,22 @@ fun main() {
}
extend {
drawer.clear(ColorRGBa.GRAY)
val color = ColorRGBa.RED
val hc = color.toHSLUVa()
drawer.stroke = null
drawer.strokeWeight = 0.0
for (h in 0 until 360 step 10) {
for (s in 0 until 10) {
val count = 400
val bobRadius = 20.0
for (i in phyllotaxis(count)) {
val h = i.theta
val s = i.radius / (count * g)
for (l in 9 downTo 0) {
val position = Polar(h.toDouble(), s * 25.0).cartesian + Vector2(width/ 2.0, height / 2.0)
drawer.fill = hc.shiftHue(h.toDouble()).saturate(s/9.0).shade((9-l)/4.5).toRGBa().toSRGB()
drawer.circle(position, kotlin.math.sqrt(s/10.0)*25.0 * l/9.0)
}
val position = i.cartesian / (count * g) * (width / 2.0 - bobRadius) + Vector2(width / 2.0, height / 2.0)
drawer.fill = hc.shiftHue(h).saturate(s).shade((9 - l) / 4.5).toRGBa().toSRGB()
drawer.circle(position, sqrt(s) * 20.0 * l / 9.0)
}
}
}