From 507b9b255702d938713aaa10eb723587e7f3fe2a Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Sat, 22 Aug 2020 00:20:32 +0200 Subject: [PATCH] [orx-color] Improve DemoHSLUV02 --- orx-color/src/demo/kotlin/DemoHSLUV02.kt | 34 ++++++++++++++++++------ 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/orx-color/src/demo/kotlin/DemoHSLUV02.kt b/orx-color/src/demo/kotlin/DemoHSLUV02.kt index 4337b8bb..ffbe6caa 100644 --- a/orx-color/src/demo/kotlin/DemoHSLUV02.kt +++ b/orx-color/src/demo/kotlin/DemoHSLUV02.kt @@ -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) { - 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 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 = 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) } } }