Skip to content

Commit 522627c

Browse files
committed
Add descriptions to demos
1 parent 72368de commit 522627c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+608
-89
lines changed

orx-color/src/jvmDemo/kotlin/colorRange/DemoColorRange01.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package colorRange
22

3-
// Comparison of color lists generated by interpolating from
4-
// PINK to BLUE in different color models
5-
63
import org.openrndr.application
74
import org.openrndr.color.ColorRGBa
85
import org.openrndr.extra.color.palettes.rangeTo
@@ -11,6 +8,10 @@ import org.openrndr.math.Vector2
118
import org.openrndr.math.map
129
import org.openrndr.shape.Rectangle
1310

11+
/**
12+
* Comparison of color lists generated by interpolating from
13+
* `PINK` to `BLUE` in six different color spaces.
14+
*/
1415
fun main() = application {
1516
configure {
1617
width = 720

orx-color/src/jvmDemo/kotlin/colorRange/DemoColorRange02.kt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
11
package colorRange
22

3-
// Create a colorSequence with multiple color models
4-
53
import org.openrndr.application
64
import org.openrndr.color.ColorRGBa
75
import org.openrndr.extra.color.palettes.colorSequence
86
import org.openrndr.extra.color.spaces.toHSLUVa
97

8+
/**
9+
* Demonstrates how to create a `ColorSequence` containing three colors, one of them in the HSLUV color space.
10+
*
11+
* Each color in the sequence is assigned a normalized position: in this program, one at the start (0.0),
12+
* one in the middle (0.5) and one at the end (1.0).
13+
*
14+
* The `ColorSpace.blend()` method is used to get a list with 18 interpolated `ColorRGBa` colors,
15+
* then those colors are drawn as vertical rectangles covering the whole window.
16+
*/
1017
fun main() = application {
1118
configure {
1219
width = 720
1320
height = 360
1421
}
1522
program {
1623
extend {
17-
val cs = colorSequence(0.0 to ColorRGBa.PINK,
18-
0.5 to ColorRGBa.BLUE,
19-
1.0 to ColorRGBa.PINK.toHSLUVa()) // <-- note this one is in hsluv
24+
val cs = colorSequence(
25+
0.0 to ColorRGBa.PINK,
26+
0.5 to ColorRGBa.BLUE,
27+
1.0 to ColorRGBa.PINK.toHSLUVa() // <-- note this color is in HSLUV
28+
)
2029

2130
for (c in cs blend (width / 40)) {
2231
drawer.fill = c
2332
drawer.stroke = null
24-
drawer.rectangle(0.0, 0.0, 40.0, height.toDouble())
33+
drawer.rectangle(0.0, 0.0, 40.0, height.toDouble())
2534
drawer.translate(40.0, 0.0)
2635
}
2736
}

orx-color/src/jvmDemo/kotlin/colorRange/DemoColorRange03.kt

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,43 @@ import org.openrndr.draw.loadFont
66
import org.openrndr.extra.color.palettes.rangeTo
77
import org.openrndr.extra.color.spaces.*
88

9+
/**
10+
* This program creates color interpolations from `ColorRGBa.BLUE` to
11+
* `ColorRGBa.PINK` in 25 steps in multiple color spaces.
12+
*
13+
* The window height is adjusted based on the number of interpolations to show.
14+
*
15+
* The resulting gradients differ in saturation and brightness and apparently include more
16+
* `BLUE` or more `PINK` depending on the chosen color space.
17+
*/
918
fun main() = application {
19+
val colorA = ColorRGBa.BLUE
20+
val colorB = ColorRGBa.PINK
21+
22+
val stepCount = 25
23+
24+
val allSteps = listOf(
25+
"RGB" to (colorA..colorB blend stepCount),
26+
"RGB linear" to (colorA.toLinear()..colorB.toLinear() blend stepCount),
27+
"HSV" to (colorA..colorB.toHSVa() blend stepCount),
28+
"Lab" to (colorA.toLABa()..colorB.toLABa() blend stepCount),
29+
"LCh(ab)" to (colorA.toLCHABa()..colorB.toLCHABa() blend stepCount),
30+
"OKLab" to (colorA.toOKLABa()..colorB.toOKLABa() blend stepCount),
31+
"OKLCh" to (colorA.toOKLCHa()..colorB.toOKLCHa() blend stepCount),
32+
"OKHSV" to (colorA.toOKHSVa()..colorB.toOKHSVa() blend stepCount),
33+
"OKHSL" to (colorA.toOKHSLa()..colorB.toOKHSLa() blend stepCount),
34+
"HSLUV" to (colorA.toHSLUVa()..colorB.toHSLUVa() blend stepCount),
35+
"XSLUV" to (colorA.toXSLUVa()..colorB.toXSLUVa() blend stepCount),
36+
)
37+
1038
configure {
1139
width = 720
12-
height = 30 + 50 * 11 // row count
40+
height = 30 + 50 * allSteps.size
1341
}
1442
program {
1543
extend {
1644
drawer.clear(ColorRGBa.WHITE)
17-
18-
val colorA = ColorRGBa.BLUE
19-
val colorB = ColorRGBa.PINK
20-
21-
val stepCount = 25
22-
23-
val allSteps = listOf(
24-
"RGB" to (colorA..colorB blend stepCount),
25-
"RGB linear" to (colorA.toLinear()..colorB.toLinear() blend stepCount),
26-
"HSV" to (colorA..colorB.toHSVa() blend stepCount),
27-
"Lab" to (colorA.toLABa()..colorB.toLABa() blend stepCount),
28-
"LCh(ab)" to (colorA.toLCHABa()..colorB.toLCHABa() blend stepCount),
29-
"OKLab" to (colorA.toOKLABa()..colorB.toOKLABa() blend stepCount),
30-
"OKLCh" to (colorA.toOKLCHa()..colorB.toOKLCHa() blend stepCount),
31-
"OKHSV" to (colorA.toOKHSVa()..colorB.toOKHSVa() blend stepCount),
32-
"OKHSL" to (colorA.toOKHSLa()..colorB.toOKHSLa() blend stepCount),
33-
"HSLUV" to (colorA.toHSLUVa()..colorB.toHSLUVa() blend stepCount),
34-
"XSLUV" to (colorA.toXSLUVa()..colorB.toXSLUVa() blend stepCount),
35-
)
36-
3745
drawer.stroke = null
38-
3946
drawer.fontMap = loadFont("demo-data/fonts/IBMPlexMono-Regular.ttf", 16.0)
4047
drawer.translate(20.0, 20.0)
4148
for ((label, steps) in allSteps) {

orx-color/src/jvmDemo/kotlin/colorRange/DemoColorRange04.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ import org.openrndr.extra.color.spaces.toXSLUVa
1414
import org.openrndr.extra.meshgenerators.sphereMesh
1515
import org.openrndr.math.Vector3
1616

17+
/**
18+
* A visualization of color interpolations inside a 3D RGB cube with an interactive 3D `Orbital` camera.
19+
*
20+
* The hues of the source and target colors are animated over time.
21+
*
22+
* The color interpolations are shown simultaneously in nine different color spaces, revealing how in
23+
* each case they share common starting and ending points in 3D, but have unique paths going from
24+
* start to end.
25+
*
26+
* By rotating the cube 90 degrees towards the left and slightly zooming out, one can appreciate how
27+
* one of the points moves along the edges of the cube, while the other moves on the edges of a
28+
* smaller, invisible cube.
29+
*
30+
*/
1731
fun main() = application {
1832
configure {
1933
width = 720
@@ -44,9 +58,6 @@ fun main() = application {
4458
"XSLUV" to (colorA.toXSLUVa()..colorB.toXSLUVa() blend stepCount),
4559
)
4660

47-
drawer.stroke = null
48-
49-
drawer.fontMap = loadFont("demo-data/fonts/IBMPlexMono-Regular.ttf", 16.0)
5061
for ((_, steps) in allSteps) {
5162
for (i in steps.indices) {
5263
val srgb = steps[i].toSRGB().clip()

orx-color/src/jvmDemo/kotlin/colormap/DemoSpectralZucconiColormap.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ import org.openrndr.extra.color.colormaps.spectralZucconi6
55
import org.openrndr.extra.noise.fastFloor
66
import kotlin.math.sin
77

8+
/**
9+
* This program demonstrates the `spectralZucconi6()` function, which
10+
* takes a normalized value and returns a `ColorRGBa` using the
11+
* accurate spectral colormap developed by Alan Zucconi.
12+
*
13+
* It draws a varying number of vertical bands (between 16 and 48)
14+
* filled with various hues.
15+
*/
816
fun main() = application {
917
configure {
1018
width = 720
@@ -14,12 +22,13 @@ fun main() = application {
1422
extend {
1523
drawer.stroke = null
1624
val stripeCount = 32 + (sin(seconds) * 16.0).fastFloor()
25+
val bandWidth = width / stripeCount.toDouble()
1726
repeat(stripeCount) { i ->
1827
drawer.fill = spectralZucconi6(i / stripeCount.toDouble())
1928
drawer.rectangle(
20-
x = i * width / stripeCount.toDouble(),
29+
x = i * bandWidth,
2130
y = 0.0,
22-
width = width / stripeCount.toDouble(),
31+
width = bandWidth,
2332
height = height.toDouble(),
2433
)
2534
}

orx-color/src/jvmDemo/kotlin/colormap/DemoSpectralZucconiColormapPhrase.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ import org.openrndr.draw.shadeStyle
55
import org.openrndr.extra.color.colormaps.ColormapPhraseBook
66
import org.openrndr.extra.shaderphrases.preprocess
77

8+
/**
9+
* This program demonstrates how to use the shader-based version of
10+
* the `spectral_zucconi6()` function, which
11+
* takes a normalized value and returns an `rgb` color using the
12+
* accurate spectral colormap developed by Alan Zucconi.
13+
*
14+
* It shades a full-window rectangle using its normalized `x` coordinate
15+
* in a `ShadeStyle` to choose pixel colors.
16+
*/
817
fun main() = application {
918
configure {
1019
width = 720

orx-color/src/jvmDemo/kotlin/colormap/DemoSpectralZucconiColormapPlot.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ import org.openrndr.extra.color.colormaps.spectralZucconi6
88
import org.openrndr.extra.shaderphrases.preprocess
99
import org.openrndr.math.Vector2
1010

11+
/**
12+
* This demo uses the shader based `spectral_zucconi6()` function to fill the background,
13+
* then visualizes the red, green and blue components of the colors used in the background
14+
* as red, green and blue line strips.
15+
*
16+
* The Vector2 points for the line strips are calculated only once when the program starts.
17+
*/
1118
fun main() = application {
1219
configure {
1320
width = 720
@@ -20,14 +27,14 @@ fun main() = application {
2027
fragmentTransform = "x_fill.rgb = spectral_zucconi6(c_boundsPosition.x);"
2128
}
2229

30+
// Function that expects as an argument a function to convert a ColorRGBa into a Double,
31+
// and returns a list of Vector2 coordinates.
2332
fun getColormapPoints(
2433
block: ColorRGBa.() -> Double
2534
) = List(width) { x ->
2635
Vector2(
2736
x.toDouble(),
28-
height.toDouble()
29-
- block(spectralZucconi6(x / width.toDouble()))
30-
* height.toDouble()
37+
(1.0 - block(spectralZucconi6(x / width.toDouble()))) * height
3138
)
3239
}
3340

@@ -39,11 +46,13 @@ fun main() = application {
3946
shadeStyle = backgroundStyle
4047
rectangle(bounds)
4148
shadeStyle = null
42-
strokeWeight = 1.0
49+
4350
stroke = ColorRGBa.RED
4451
lineStrip(redPoints)
52+
4553
stroke = ColorRGBa.GREEN
4654
lineStrip(greenPoints)
55+
4756
stroke = ColorRGBa.BLUE
4857
lineStrip(bluePoints)
4958
}

orx-color/src/jvmDemo/kotlin/colormap/DemoTurboColormap.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ import org.openrndr.extra.color.colormaps.turboColormap
55
import org.openrndr.extra.noise.fastFloor
66
import kotlin.math.sin
77

8+
/**
9+
* This program demonstrates the `turboColormap()` function, which
10+
* takes a normalized value and returns a `ColorRGBa` using the
11+
* Turbo colormap developed by Google.
12+
*
13+
* It draws a varying number of vertical bands (between 16 and 48)
14+
* filled with various hues.
15+
*/
16+
817
fun main() = application {
918
configure {
1019
width = 720

orx-color/src/jvmDemo/kotlin/colormap/DemoTurboColormapPhrase.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ import org.openrndr.draw.shadeStyle
55
import org.openrndr.extra.color.colormaps.ColormapPhraseBook
66
import org.openrndr.extra.shaderphrases.preprocess
77

8+
/**
9+
* This program demonstrates how to use the shader-based version of
10+
* the `turbo_colormap()` function, which
11+
* takes a normalized value and returns an `rgb` color using the
12+
* Turbo colormap developed by Google.
13+
*
14+
* It shades a full-window rectangle using its normalized `x` coordinate
15+
* in a `ShadeStyle` to choose pixel colors.
16+
*/
817
fun main() = application {
918
configure {
1019
width = 720

orx-color/src/jvmDemo/kotlin/colormap/DemoTurboColormapPlot.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ import org.openrndr.extra.color.colormaps.turboColormap
88
import org.openrndr.extra.shaderphrases.preprocess
99
import org.openrndr.math.Vector2
1010

11+
/**
12+
* This demo uses the shader based `turbo_colormap()` function to fill the background,
13+
* then visualizes the red, green and blue components of the colors used in the background
14+
* as red, green and blue line strips.
15+
*
16+
* The Vector2 points for the line strips are calculated only once when the program starts.
17+
*/
1118
fun main() = application {
1219
configure {
1320
width = 720
@@ -23,10 +30,8 @@ fun main() = application {
2330
block: ColorRGBa.() -> Double
2431
) = List(width) { x ->
2532
Vector2(
26-
x = x.toDouble(),
27-
y = height.toDouble()
28-
- block(turboColormap(x / width.toDouble()))
29-
* height.toDouble()
33+
x.toDouble(),
34+
(1.0 - block(turboColormap(x / width.toDouble()))) * height
3035
)
3136
}
3237
val redPoints = getColormapPoints { r }
@@ -37,11 +42,13 @@ fun main() = application {
3742
shadeStyle = backgroundStyle
3843
rectangle(bounds)
3944
shadeStyle = null
40-
strokeWeight = 1.0
45+
4146
stroke = ColorRGBa.RED
4247
lineStrip(redPoints)
48+
4349
stroke = ColorRGBa.GREEN
4450
lineStrip(greenPoints)
51+
4552
stroke = ColorRGBa.BLUE
4653
lineStrip(bluePoints)
4754
}

0 commit comments

Comments
 (0)