Skip to content

Commit 5e6a512

Browse files
committed
Add descriptions to demos
1 parent 7f7a369 commit 5e6a512

File tree

22 files changed

+311
-63
lines changed

22 files changed

+311
-63
lines changed

orx-color/src/jvmDemo/kotlin/DemoXSLUV01.kt

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
1-
// Visualize XSLUV color space by drawing a recursively subdivided arcs
2-
31
import org.openrndr.application
42
import org.openrndr.color.ColorRGBa
53
import org.openrndr.extra.color.spaces.ColorXSLUVa
64
import org.openrndr.math.Polar
75
import 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+
*/
918
fun 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)

orx-compositor/src/jvmDemo/kotlin/DemoCompositor01.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ fun main() = application {
3636
}
3737

3838
val items = List(50) {
39-
val pos = Vector3(Random.nextDouble() * width,
40-
Random.nextDouble(0.3, 0.7) * height,
41-
Random.nextDouble())
39+
val pos = Vector3(
40+
Random.nextDouble() * width,
41+
Random.nextDouble(0.3, 0.7) * height,
42+
Random.nextDouble()
43+
)
4244
Item(pos, ColorRGBa.PINK.shade(Random.nextDouble(0.2, 0.9)))
4345
}.sortedBy { it.pos.z }
4446

orx-jumpflood/src/commonMain/kotlin/draw/SDFDraw.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class SDFStrokeFill : Filter(filterShaderFromCode(jf_sdf_stroke_fill, "sdf-strok
2424
@DoubleParameter("fill feather", 0.0, 20.0, order = 0)
2525
var fillFeather: Double by parameters
2626

27-
2827
@ColorParameter("fill color", order = 2)
2928
var fillColor: ColorRGBa by parameters
3029
init {

orx-jumpflood/src/jvmDemo/kotlin/DemoDirectionField01.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import org.openrndr.shape.Rectangle
1212
* Shows how to use the [DirectionalField] filter.
1313
* Draws moving white shapes on black background,
1414
* then applies the DirectionalField filter which returns a [ColorBuffer] in which
15-
* the red and green components encode the direction to the closest black/white edge.
15+
* the red and green components encode the direction to the closest black/white edge,
16+
* and the blue component the distance to that edge.
1617
*
1718
* Hold down a mouse button to see the raw animation.
1819
*/

orx-jumpflood/src/jvmDemo/kotlin/DemoDirectionField02.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@ import org.openrndr.math.Vector3
1212
import org.openrndr.math.clamp
1313

1414
/**
15-
* Create directional distance field and demonstrate signed distance
15+
* Demonstrates how use the `DirectionalField` effect to create
16+
* a `ColorBuffer` in which the RGB components encode direction and distance to the closest
17+
* edge of every pixel in an input `ColorBuffer`.
18+
*
19+
* The program draws scattered white circles on a `ColorBuffer`, then applies the `DistanceField()`
20+
* effect and renders the static result on every animation frame.
21+
*
22+
* Additionally, it uses the shadow (CPU version of the texture) to query the distance field texture
23+
* at current mouse position. The resulting blue color component is used as the radius of a circle
24+
* centered at the mouse position. The red and green components are used to draw a line to the
25+
* black/white edge closest to the mouse pointer.
1626
*/
1727
fun main() = application {
1828
configure {
@@ -26,12 +36,12 @@ fun main() = application {
2636
drawer.circles(points, 50.0)
2737
}
2838

29-
val filter = DirectionalField()
39+
val directionalField = DirectionalField()
3040
val ddf = input.createEquivalent(type = ColorType.FLOAT32)
3141

32-
filter.signedMagnitude = true
33-
filter.unitDirection = true
34-
filter.apply(input, ddf)
42+
directionalField.signedMagnitude = true
43+
directionalField.unitDirection = true
44+
directionalField.apply(input, ddf)
3545

3646
ddf.shadow.download()
3747
extend {

orx-jumpflood/src/jvmDemo/kotlin/DemoShapeSDF01.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ import org.openrndr.draw.colorBuffer
66
import org.openrndr.extra.jumpfill.ShapeSDF
77
import org.openrndr.extra.svg.loadSVG
88

9+
/**
10+
* Demonstrates the use of the `ShapeSDF()` effect, which takes vector shapes
11+
* (either `Shape` or `ShapeContour` instances) and produces a `ColorBuffer`
12+
* texture containing a signed distance field pointing at the closest vector edge
13+
* encoded in its RGB channels.
14+
*
15+
* Hold down any mouse button to observe the original vector shape in black and white,
16+
* without the effect applied.
17+
*/
918
fun main() = application {
1019
configure {
1120
width = 720

orx-jumpflood/src/jvmDemo/kotlin/DemoShapeSDF02.kt

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,21 @@ import org.openrndr.extra.svg.loadSVG
1111
import org.openrndr.math.Vector3
1212
import org.openrndr.math.transforms.transform
1313

14-
import kotlin.math.min
15-
14+
/**
15+
* Advanced demonstration making use of two `ShapeSDF` filters: the first applied to a static
16+
* SVG loaded from a file, and the second to a rotating version of the same shape.
17+
*
18+
* The demo also uses three additional SDF filters:
19+
* - `SDFSmoothIntersection`, which combines two color buffers containing SDF information
20+
* into a new color buffer
21+
* - `SDFOnion`, which takes one SDF color buffer and outputs one SDF color buffer
22+
* - `SDFStrokeFill`, used for rendering using configurable fill and stroke properties.
23+
*
24+
* The vertical mouse position is used to control the radius of the `SDFSmoothIntersection` effect.
25+
*
26+
* The program finally renders the result of the previous operations as one color buffer
27+
* thanks to the `SDFStrokeFill` effect.
28+
*/
1629
fun main() = application {
1730
configure {
1831
width = 720
@@ -30,7 +43,6 @@ fun main() = application {
3043
val union = SDFSmoothIntersection()
3144
val onion = SDFOnion()
3245

33-
3446
val strokeFill = SDFStrokeFill()
3547

3648
extend {
@@ -41,17 +53,20 @@ fun main() = application {
4153
sdf1.setShapes(shapes.map {
4254
it.transform(transform {
4355
translate(drawer.bounds.center)
44-
rotate(Vector3.Companion.UNIT_Z, seconds * 45.0 - 30.0)
56+
rotate(Vector3.UNIT_Z, seconds * 45.0 - 30.0)
4557
translate(-drawer.bounds.center)
4658
})
4759
})
4860

4961
sdf0.apply(emptyArray(), df0)
5062
sdf1.apply(emptyArray(), df1)
51-
union.radius = 10.0 + min(mouse.position.y, 100.0)
63+
64+
union.radius = 10.0 + mouse.position.y.coerceAtMost(100.0)
5265
union.apply(arrayOf(df0, df1), df0)
66+
5367
onion.radius = 20.0
5468
onion.apply(df0, df0)
69+
5570
strokeFill.strokeWeight = 2.0
5671
strokeFill.apply(df0, df0)
5772
drawer.image(df0)

orx-jumpflood/src/jvmDemo/kotlin/DemoShapeSDF03.kt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ import org.openrndr.extra.jumpfill.draw.SDFStrokeFill
99
import org.openrndr.extra.jumpfill.ops.SDFSmoothDifference
1010
import org.openrndr.extra.svg.loadSVG
1111

12+
/**
13+
* Advanced demonstration making use the `ShapeSDF` filter applied twice to a static
14+
* SVG loaded from a file, one with `useUV` set to true.
15+
*
16+
* A `FluidDistort` filter is used to generate an animated UV map which is fed into
17+
* both `ShapeSDF` filters. A `SDFSmoothDifference` filter is then applied to combine
18+
* both resulting `ColorBuffer` instances, and a `SDFStrokeFill` filter used for
19+
* rendering the result.
20+
*
21+
* The mouse horizontal position determines which of the three used color buffers is
22+
* displayed.
23+
*/
1224
fun main() = application {
1325
configure {
1426
width = 720
@@ -40,13 +52,22 @@ fun main() = application {
4052

4153
sdf0.useUV = true
4254
sdf0.apply(uvmap, df0)
55+
4356
sdf1.apply(uvmap, df1)
57+
4458
union.radius = 10.0
4559
union.apply(arrayOf(df0, df1), df0)
4660

4761
strokeFill.strokeWeight = 10.0
4862
strokeFill.apply(df0, df0)
49-
drawer.image(df0)
63+
64+
drawer.image(
65+
when (mouse.position.x) {
66+
in 0.0..width * 0.6 -> df0
67+
in width * 0.6..width * 0.8 -> df1
68+
else -> uvmap
69+
}
70+
)
5071
}
5172
}
5273
}

orx-jumpflood/src/jvmDemo/kotlin/DemoShapeSDF04.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ import org.openrndr.extra.jumpfill.ops.SDFSmoothDifference
1111
import org.openrndr.extra.svg.loadSVG
1212
import org.openrndr.shape.Circle
1313

14+
/**
15+
* Demonstrates using tow `ShapeSDF` filters. One contairs a vector shape loaded
16+
* from disk, the other a circular shape.
17+
*
18+
* A `Perturb` effect is used to generate a noise UV map, which is then fed into
19+
* the `ShapeSDF` filters.
20+
*
21+
* The two resulting `ColorBuffer`s are combined using a `SDFSmoothDifference` filter,
22+
* which erases the distorted circular shape from the loaded shape.
23+
*
24+
* The `SDFStrokeFill` is used to render the result.
25+
*
26+
* A GUI is available to tweak the parameters of the `Perturb` effect.
27+
* Lowering its `gain` to zero disables the effect, revealing the circle and the
28+
* smoothness (round corners) of the difference effect.
29+
*/
1430
fun main() = application {
1531
configure {
1632
width = 720

orx-jumpflood/src/jvmDemo/kotlin/DemoShapeSDF05.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import org.openrndr.shape.Circle
1414
import kotlin.math.cos
1515
import kotlin.math.sin
1616

17+
/**
18+
* Variation of DemoShapeSDF04, in which `Perturb` is applied twice with different
19+
* parameters for a more complex UV map, and with four effects added to the GUI
20+
* for further customization and exploration.
21+
*/
1722
fun main() = application {
1823
configure {
1924
width = 720
@@ -44,8 +49,8 @@ fun main() = application {
4449
sdf0.useUV = true
4550
gui.add(sdf0)
4651
gui.add(perturb)
47-
gui.add(strokeFill)
4852
gui.add(difference)
53+
gui.add(strokeFill)
4954

5055
extend(gui)
5156
extend {

0 commit comments

Comments
 (0)