[orx-shapes] Add demos, tweak comments
This commit is contained in:
@@ -31,10 +31,10 @@ fun <E> List<E>.update(vararg updates: Pair<Int, E>): List<E> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper for querying and adjusting [ShapeContour].
|
* Helper for querying and adjusting [ShapeContour].
|
||||||
* * An edge embodies exactly the same thing as a [Segment][org.openrndr.shape.Segment]
|
* * An edge embodies exactly the same thing as a [Segment2D][org.openrndr.shape.Segment2D]
|
||||||
* * All edge operations are immutable and will create a new [ContourEdge] pointing to a copied and updated [ShapeContour]
|
* * All edge operations are immutable and will create a new [ContourEdge] pointing to a copied and updated [ShapeContour]
|
||||||
* @param contour the contour to be adjusted
|
* @param contour the contour to be adjusted
|
||||||
* @param segmentIndex the index of the segment of the contour to be adjusted
|
* @param segmentIndex the index the contour's segment to be adjusted
|
||||||
* @param adjustments a list of [SegmentOperation] that have been applied to reach to [contour], this is used to inform [ShapeContour]
|
* @param adjustments a list of [SegmentOperation] that have been applied to reach to [contour], this is used to inform [ShapeContour]
|
||||||
* of changes in the contour topology.
|
* of changes in the contour topology.
|
||||||
* @since 0.4.4
|
* @since 0.4.4
|
||||||
@@ -126,7 +126,7 @@ data class ContourEdge(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Split the edge in [numberOfParts] parts of equal length
|
* Split the edge in [parts] parts of equal length
|
||||||
*/
|
*/
|
||||||
fun splitIn(parts: Int): ContourEdge {
|
fun splitIn(parts: Int): ContourEdge {
|
||||||
if (contour.empty || parts < 2) {
|
if (contour.empty || parts < 2) {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package adjust
|
|||||||
import org.openrndr.application
|
import org.openrndr.application
|
||||||
import org.openrndr.color.ColorRGBa
|
import org.openrndr.color.ColorRGBa
|
||||||
import org.openrndr.draw.loadFont
|
import org.openrndr.draw.loadFont
|
||||||
import org.openrndr.extra.color.presets.DARK_CYAN
|
|
||||||
import org.openrndr.extra.shapes.adjust.adjustContour
|
import org.openrndr.extra.shapes.adjust.adjustContour
|
||||||
import org.openrndr.extra.shapes.adjust.extensions.averageTangents
|
import org.openrndr.extra.shapes.adjust.extensions.averageTangents
|
||||||
import org.openrndr.extra.shapes.adjust.extensions.switchTangents
|
import org.openrndr.extra.shapes.adjust.extensions.switchTangents
|
||||||
|
|||||||
@@ -6,6 +6,12 @@ import org.openrndr.extra.shapes.alphashape.AlphaShape
|
|||||||
import org.openrndr.math.Vector2
|
import org.openrndr.math.Vector2
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Demonstrates the use of [AlphaShape] to create a [org.openrndr.shape.ShapeContour] out
|
||||||
|
* of a collection of random [Vector2] points. Unlike the convex hull, an Alpha shape can be concave.
|
||||||
|
*
|
||||||
|
* More details in [WikiPedia](https://en.wikipedia.org/wiki/Alpha_shape)
|
||||||
|
*/
|
||||||
fun main() = application {
|
fun main() = application {
|
||||||
program {
|
program {
|
||||||
val points = List(40) {
|
val points = List(40) {
|
||||||
47
orx-shapes/src/jvmDemo/kotlin/alphashape/DemoAlphaShape02.kt
Normal file
47
orx-shapes/src/jvmDemo/kotlin/alphashape/DemoAlphaShape02.kt
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package alphashape
|
||||||
|
|
||||||
|
import org.openrndr.application
|
||||||
|
import org.openrndr.color.ColorRGBa
|
||||||
|
import org.openrndr.extra.noise.shapes.uniform
|
||||||
|
import org.openrndr.extra.shapes.alphashape.AlphaShape
|
||||||
|
import org.openrndr.math.Vector2
|
||||||
|
import kotlin.random.Random
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Demonstrates the use of [AlphaShape] to create ten
|
||||||
|
* [org.openrndr.shape.ShapeContour] instances out of a collection of random [Vector2] points.
|
||||||
|
*
|
||||||
|
* The same points are used for each contour, but an increased alpha parameter
|
||||||
|
* is passed to the AlphaShape algorithm. Higher values return more convex shapes
|
||||||
|
* = shapes with a larger surface.
|
||||||
|
*
|
||||||
|
* The list of shapes is reversed to draw the smaller contours on top, otherwise only
|
||||||
|
* the last one would be visible.
|
||||||
|
*
|
||||||
|
* An instance of [Random] with a fixed seed is used to ensure the resulting
|
||||||
|
* random shape is always the same.
|
||||||
|
*/
|
||||||
|
fun main() = application {
|
||||||
|
program {
|
||||||
|
val rand = Random(242)
|
||||||
|
val points = List(40) {
|
||||||
|
drawer.bounds.uniform(rand)
|
||||||
|
}
|
||||||
|
val alphaShape = AlphaShape(points)
|
||||||
|
val minAlpha = alphaShape.determineContourAlpha()
|
||||||
|
|
||||||
|
val contours = List(10) {
|
||||||
|
alphaShape.createContour(minAlpha + it * it * it)
|
||||||
|
}.reversed()
|
||||||
|
extend {
|
||||||
|
drawer.stroke = null
|
||||||
|
contours.forEachIndexed { index, contour ->
|
||||||
|
drawer.fill = ColorRGBa.PINK.shade(0.5 + index * 0.07)
|
||||||
|
drawer.contour(contour)
|
||||||
|
}
|
||||||
|
|
||||||
|
drawer.fill = ColorRGBa.WHITE
|
||||||
|
drawer.circles(points, 4.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package operators
|
||||||
|
|
||||||
|
import org.openrndr.application
|
||||||
|
import org.openrndr.extra.shapes.adjust.adjustContour
|
||||||
|
import org.openrndr.extra.shapes.operators.roundCorners
|
||||||
|
import org.openrndr.shape.Rectangle
|
||||||
|
|
||||||
|
fun main() = application {
|
||||||
|
program {
|
||||||
|
extend {
|
||||||
|
val contours = listOf(
|
||||||
|
Rectangle(100.0, 100.0, 100.0, 100.0).contour,
|
||||||
|
adjustContour(Rectangle(400.0, 100.0, 100.0, 100.0).contour) {
|
||||||
|
selectVertex(0)
|
||||||
|
vertices.forEach { it.rotate(30.0) }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
val contoursRounded = contours.map {
|
||||||
|
it.roundCorners(10.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
drawer.contours(contours)
|
||||||
|
drawer.translate(0.0, 150.0)
|
||||||
|
drawer.contours(contoursRounded)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user