[orx-shapes] Demo comments
This commit is contained in:
@@ -12,6 +12,14 @@ import org.openrndr.shape.Rectangle
|
||||
import org.openrndr.shape.Shape
|
||||
import kotlin.random.Random
|
||||
|
||||
/**
|
||||
* Demonstrates the use of Arrangement to create a 2D arrangement of shapes.
|
||||
*
|
||||
* The Arrangement constructor takes as arguments instances of [org.openrndr.shape.ShapeProvider]s.
|
||||
*
|
||||
* Once constructed, we can request `originFaces`, `edges`, `vertices`, `boundaries` and `holes`,
|
||||
* to render or manipulate them further as needed.
|
||||
*/
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 800
|
||||
|
||||
@@ -10,6 +10,14 @@ import org.openrndr.extra.shapes.arrangement.BoundedFace
|
||||
import org.openrndr.extra.shapes.hobbycurve.hobbyCurve
|
||||
import kotlin.random.Random
|
||||
|
||||
/**
|
||||
* Demonstrates the use of Arrangement to create a 2D arrangement of shapes using a self-intersecting curve.
|
||||
*
|
||||
* For self-intersections we need to pass the same curve twice as arguments to Arrangement.
|
||||
* The specific curve used results in 4 intersection points.
|
||||
*
|
||||
* This demo shows how we can query and visualize the neighborhoods of those 4 vertices.
|
||||
*/
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 800
|
||||
@@ -21,7 +29,7 @@ fun main() = application {
|
||||
val uniformPoints = poissonDiskSampling(drawer.bounds.offsetEdges(-200.0), 100.0, random=Random(10579))
|
||||
val curve = hobbyCurve(uniformPoints, closed=true)
|
||||
|
||||
// Construct an arrangement of the curve. In order to obtain an arrangement dealing with self intersections,
|
||||
// Construct an arrangement of the curve. To get an arrangement dealing with self-intersections,
|
||||
// the curve is passed in twice.
|
||||
val arrangement = Arrangement(curve, curve)
|
||||
|
||||
|
||||
@@ -12,32 +12,46 @@ import org.openrndr.shape.Circle
|
||||
import kotlin.math.sqrt
|
||||
import kotlin.random.Random
|
||||
|
||||
/**
|
||||
* Demonstrates using the `boundedFaces` collection available in Arrangements.
|
||||
*
|
||||
* `boundedFaces` elements have a `contour` property, while `unboundedFaces` do not.
|
||||
*
|
||||
* In this example, `faces` contains 25 items: 24 `bounded` and 1 `unbounded` faces.
|
||||
*/
|
||||
fun main() = application {
|
||||
program {
|
||||
val circles = listOf(
|
||||
Circle(drawer.bounds.center - Vector2(50.0, 0.0), 50.0),
|
||||
Circle(drawer.bounds.center + Vector2(50.0, 0.0), 50.0),
|
||||
Circle(drawer.bounds.center + Vector2(0.0, 50.0), 50.0),
|
||||
Circle(drawer.bounds.center - Vector2(0.0, 50.0), 50.0),
|
||||
Circle(drawer.bounds.center - Vector2(50.0, 0.0), sqrt(50.0 * 50.0 + 50.0 * 50.0) - 49.9),
|
||||
Circle(drawer.bounds.center + Vector2(50.0, 0.0), sqrt(50.0 * 50.0 + 50.0 * 50.0) - 49.9),
|
||||
Circle(drawer.bounds.center - Vector2(0.0, 50.0), sqrt(50.0 * 50.0 + 50.0 * 50.0) - 49.9),
|
||||
Circle(drawer.bounds.center + Vector2(0.0, 50.0), sqrt(50.0 * 50.0 + 50.0 * 50.0) - 49.9),
|
||||
Circle(Vector2(-50.0, 0.0), 50.0),
|
||||
Circle(Vector2(50.0, 0.0), 50.0),
|
||||
Circle(Vector2(0.0, 50.0), 50.0),
|
||||
Circle(Vector2(0.0, -50.0), 50.0),
|
||||
Circle(Vector2(-50.0, 0.0), sqrt(50.0 * 50.0 + 50.0 * 50.0) - 49.9),
|
||||
Circle(Vector2(50.0, 0.0), sqrt(50.0 * 50.0 + 50.0 * 50.0) - 49.9),
|
||||
Circle(Vector2(0.0, -50.0), sqrt(50.0 * 50.0 + 50.0 * 50.0) - 49.9),
|
||||
Circle(Vector2(0.0, 50.0), sqrt(50.0 * 50.0 + 50.0 * 50.0) - 49.9),
|
||||
).shuffled()
|
||||
|
||||
val arr = Arrangement(circles)
|
||||
|
||||
println(arr.faces.size)
|
||||
println(arr.boundedFaces.size)
|
||||
println(arr.unboundedFaces.size)
|
||||
|
||||
extend {
|
||||
val r = Random(100)
|
||||
drawer.stroke = ColorRGBa.WHITE
|
||||
for (f in arr.boundedFaces) {
|
||||
drawer.fill =
|
||||
|
||||
rgb(
|
||||
Double.uniform(0.0, 1.0, r),
|
||||
Double.uniform(0.0, 1.0, r),
|
||||
Double.uniform(0.0, 1.0, r)
|
||||
).saturate<OKHSV>(0.25)
|
||||
drawer.stroke = ColorRGBa.WHITE
|
||||
drawer.translate(drawer.bounds.center)
|
||||
drawer.scale(2.0)
|
||||
|
||||
for (f in arr.boundedFaces) {
|
||||
drawer.fill = rgb(
|
||||
Double.uniform(0.0, 1.0, r),
|
||||
Double.uniform(0.0, 1.0, r),
|
||||
Double.uniform(0.0, 1.0, r)
|
||||
).saturate<OKHSV>(0.25)
|
||||
|
||||
drawer.contour(f.contour)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user