Add descriptions to demos

This commit is contained in:
Abe Pazos
2025-11-22 19:08:30 +01:00
parent 72368deb85
commit 522627ca51
45 changed files with 608 additions and 89 deletions

View File

@@ -0,0 +1,38 @@
package hobbycurve
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.noise.scatter
import org.openrndr.extra.shapes.hobbycurve.hobbyCurve
import org.openrndr.extra.shapes.ordering.hilbertOrder
import kotlin.random.Random
/**
* Demonstrates the use of the `tensions` argument when creating a Hobby curve.
*
* The program starts by creating a random set of scattered points with enough separation between them.
* The points are sorted using `hilbertOrder` to minimize the travel distance when visiting all the points.
* Finally, we draw a set of 40 hobby translucent curves using those same points but with varying tensions.
*/
fun main() = application {
configure {
width = 720
height = 720
}
program {
extend {
for (i in -20..20) {
val t = i / 10.0
val points = drawer.bounds.offsetEdges(-50.0)
.scatter(25.0, random = Random(0))
.hilbertOrder()
drawer.stroke = ColorRGBa.WHITE.opacify(0.5)
drawer.fill = null
drawer.contour(hobbyCurve(points, closed = false, tensions = { i, inAngle, outAngle ->
Pair(t, t)
}))
}
}
}
}

View File

@@ -0,0 +1,38 @@
package hobbycurve
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.color.presets.WHITE_SMOKE
import org.openrndr.extra.noise.simplex
import org.openrndr.extra.noise.uniform
import org.openrndr.extra.shapes.hobbycurve.hobbyCurve
import org.openrndr.extra.shapes.ordering.hilbertOrder
import org.openrndr.math.Vector2
/**
* Demonstrates the creation of a 40 hobby curves with 10 points each.
* The control points in all hobby curves are almost identical, varying only
* due to a slight increase in one of the arguments of a simplex noise call.
*
* The program shows that minor displacements in control points can have
* a large impact in the resulting curve.
*/
fun main() = application {
program {
val seed = 68040
val curves = List(40) { n ->
hobbyCurve(List(10) {
Vector2(
simplex(seed, it * 13.3, n * 0.001) * 300.0 + 320.0,
simplex(seed / 2, it * 77.4, n * 0.001) * 300.0 + 240.0
)
}.hilbertOrder(), true)
}
extend {
drawer.clear(ColorRGBa.WHITE_SMOKE)
drawer.fill = null
drawer.stroke = ColorRGBa.BLACK.opacify(0.3)
drawer.contours(curves)
}
}
}

View File

@@ -0,0 +1,47 @@
package primitives
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.color.presets.CORAL
import org.openrndr.extra.shapes.primitives.column
import org.openrndr.extra.shapes.primitives.irregularGrid
import org.openrndr.extra.shapes.primitives.row
import kotlin.random.Random
/**
* Demonstrates how to use `Rectangle.irregularGrid()` to create a grid with varying column widths
* and row heights. The widths and heights are specified as a list of 13 `Double` values, each
* picked randomly between the values 1.0 and 4.0. This produces two types of columns and two
* types of rows only: wide ones and narrow ones.
*
* The program also demonstrates how to query a `row()` and a `column()` from a `RectangleGrid` instance,
* both of which return a `List<Rectangle>`. Both `Rectangle` lists are rendered with translucent
* colors, which makes the intersection of the column and the row slightly brighter.
*
*/
fun main() = application {
configure {
width = 720
height = 720
}
program {
extend {
val r = Random(100)
val grid = drawer.bounds.irregularGrid(
List(13) { listOf(1.0, 4.0).random(r) },
List(13) { listOf(1.0, 4.0).random(r) }
)
drawer.fill = null
drawer.stroke = ColorRGBa.WHITE
drawer.rectangles(grid.flatten())
drawer.stroke = ColorRGBa.BLACK
drawer.fill = ColorRGBa.PINK.opacify(0.5)
drawer.rectangles(grid.column(2))
drawer.fill = ColorRGBa.CORAL.opacify(0.5)
drawer.rectangles(grid.row(6))
}
}
}

View File

@@ -0,0 +1,42 @@
package primitives
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.noise.scatter
import org.openrndr.extra.shapes.primitives.Tear
import org.openrndr.shape.Circle
/**
* Demonstrates the use of `Tear()` to create drop-like shapes out of a Vector2 point and a Circle.
*
* The tear locations are calculated using the `Rectangle.scatter()` function. Locations near the
* center of the window are filtered out.
*
* The radii of each tear is randomly chosen between three values. The orientation of each tear
* is calculated by getting the normalized difference between the tear and the center of the window,
* making them look as being emitted at the center of the window.
*/
fun main() = application {
configure {
width = 720
height = 720
}
program {
val points = drawer.bounds.scatter(40.0, distanceToEdge = 80.0).filter {
it.distanceTo(drawer.bounds.center) > 80.0
}
val tears = points.map {
val radius = listOf(5.0, 10.0, 20.0).random()
val offset = (it - drawer.bounds.center).normalized * radius
Tear(it - offset, Circle(it + offset, radius))
}
extend {
drawer.clear(ColorRGBa.WHITE)
drawer.fill = ColorRGBa.PINK
drawer.stroke = ColorRGBa.BLACK
drawer.contours(tears.map { it.contour })
}
}
}