1- // Visualize XSLUV color space by drawing a recursively subdivided arcs
2-
31import org.openrndr.application
42import org.openrndr.color.ColorRGBa
53import org.openrndr.extra.color.spaces.ColorXSLUVa
64import org.openrndr.math.Polar
75import org.openrndr.shape.contour
86
7+ /* *
8+ * Visualize the XSLUV color space by drawing a recursively subdivided set of arcs.
9+ *
10+ * The provided `Arc` class provides a `contour` getter, which creates a "thick" arc with
11+ * its thickness defined by the `height` argument. This is created by two arcs and two
12+ * connecting lines.
13+ *
14+ * The mouse x coordinate controls the saturation, while the y coordinate controls the luminosity.
15+ * The two if-statements check whether the program is taking a screenshot (this happens when
16+ * it runs on GitHub actions) to set fixed saturation and luminosity values.
17+ */
918fun main () = application {
1019 configure {
1120 width = 720
1221 height = 720
1322 }
1423
1524 class Arc (val start : Double , val radius : Double , val length : Double , val height : Double ) {
25+ /* *
26+ * Splits the Arc in two equal parts with half the length of the original
27+ */
1628 fun split (offset : Double = 0.0): List <Arc > {
1729 val hl = length / 2.0
1830 return listOf (
@@ -21,6 +33,11 @@ fun main() = application {
2133 )
2234 }
2335
36+ /* *
37+ * Return the contour of an arc with `height` thickness, by drawing an arc using `radius`,
38+ * then a line connecting to a returning arc using `radius + height`, and a final line to
39+ * close the contour.
40+ */
2441 val contour
2542 get() = contour {
2643 moveTo(Polar (start, radius).cartesian)
@@ -32,18 +49,22 @@ fun main() = application {
3249 }
3350 }
3451
52+ /* *
53+ * Create a list of `Arc` by recursively calling the `split` function until `depth` reaches 0.
54+ */
3555 fun List<Arc>.split (depth : Int ): List <Arc > = if (depth == 0 ) {
3656 this
3757 } else {
3858 this + flatMap { it.split(it.height) }.split(depth - 1 )
3959 }
4060
4161 program {
42- val arcs = (0 .. 4 ).map { Arc (it * 90.0 - 45.0 , 50.0 , 90.0 , 50.0 ) }.split(5 )
62+ val arcs = (0 .. 4 ).map {
63+ Arc (it * 90.0 - 45.0 , 50.0 , 90.0 , 50.0 )
64+ }.split(5 )
4365
4466 extend {
4567 drawer.clear(ColorRGBa .GRAY )
46- val color = ColorRGBa .RED
4768 drawer.stroke = ColorRGBa .BLACK
4869 drawer.strokeWeight = 1.0
4970 drawer.translate(drawer.bounds.center)
0 commit comments