[orx-shapes] Comment the ContourAdjuster and its demos
This commit is contained in:
@@ -2,6 +2,8 @@ package adjust
|
||||
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
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.extensions.averageTangents
|
||||
import org.openrndr.extra.shapes.adjust.extensions.switchTangents
|
||||
@@ -9,14 +11,36 @@ import org.openrndr.extra.shapes.tunni.tunniLine
|
||||
import org.openrndr.extra.shapes.tunni.tunniPoint
|
||||
import kotlin.math.sqrt
|
||||
|
||||
/**
|
||||
* Demonstrates how to manipulate a contour by adjusting and transforming its vertices
|
||||
* and edges, and subsequently visualizing the result using different drawing styles.
|
||||
*
|
||||
* The program creates a rectangular contour derived by shrinking the bounds of the drawing area.
|
||||
* It then applies multiple transformations to selected vertices. These transformations include:
|
||||
*
|
||||
* - Averaging tangents for selected vertices
|
||||
* - Scaling and rotating vertex positions based on the horizontal mouse position
|
||||
* - Switching tangents for specific vertices
|
||||
*
|
||||
* The resulting contour is drawn in black. Additionally:
|
||||
*
|
||||
* - Control line segments are visualized in red, connecting segment endpoints to control points.
|
||||
* - Vertices are numbered and highlighted with black-filled circles.
|
||||
* - Tunni lines, which represent optimized control line placements, are visualized in cyan.
|
||||
* - Tunni points, marking the Tunni line's control, are emphasized with yellow-filled circles.
|
||||
*
|
||||
*/
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 800
|
||||
height = 800
|
||||
}
|
||||
program {
|
||||
val font = loadFont("demo-data/fonts/IBMPlexMono-Regular.ttf", 16.0)
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.WHITE)
|
||||
drawer.fontMap = font
|
||||
|
||||
var contour = drawer.bounds.offsetEdges(-200.0).contour
|
||||
|
||||
drawer.fill = null
|
||||
@@ -26,7 +50,7 @@ fun main() = application {
|
||||
for (v in vertices) {
|
||||
v.averageTangents()
|
||||
v.scale(sqrt(2.0))
|
||||
v.rotate(45.0)
|
||||
v.rotate(mouse.position.x - 45.0)
|
||||
}
|
||||
|
||||
selectVertices(2)
|
||||
@@ -38,19 +62,25 @@ fun main() = application {
|
||||
drawer.contour(contour)
|
||||
|
||||
drawer.stroke = ColorRGBa.RED
|
||||
|
||||
for (s in contour.segments) {
|
||||
drawer.lineSegment(s.start, s.cubic.control[0])
|
||||
drawer.lineSegment(s.end, s.cubic.control[1])
|
||||
}
|
||||
|
||||
// Draw points and numbers
|
||||
drawer.fill = ColorRGBa.BLACK
|
||||
drawer.stroke = null
|
||||
drawer.circles(contour.segments.map { it.start }, 5.0)
|
||||
contour.segments.forEachIndexed { i, it ->
|
||||
drawer.text(i.toString(), it.start + 10.0)
|
||||
drawer.circle(it.start, 5.0)
|
||||
}
|
||||
|
||||
drawer.stroke = ColorRGBa.GRAY
|
||||
drawer.fill = ColorRGBa.YELLOW
|
||||
drawer.stroke = ColorRGBa.CYAN
|
||||
for (s in contour.segments) {
|
||||
drawer.strokeWeight = 3.0
|
||||
drawer.lineSegment(s.tunniLine)
|
||||
drawer.fill = ColorRGBa.CYAN
|
||||
drawer.strokeWeight = 1.0
|
||||
drawer.circle(s.tunniPoint, 5.0)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user