[orx-shapes] Improve contour adjuster framework
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
//package adjust
|
||||
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.shapes.adjust.adjustContour
|
||||
@@ -1,3 +1,5 @@
|
||||
//package adjust
|
||||
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.shapes.adjust.adjustContour
|
||||
@@ -1,3 +1,5 @@
|
||||
//package adjust
|
||||
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.shapes.adjust.adjustContour
|
||||
@@ -1,3 +1,5 @@
|
||||
//package adjust
|
||||
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.shapes.adjust.adjustContour
|
||||
@@ -1,3 +1,5 @@
|
||||
//package adjust
|
||||
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.shapes.adjust.adjustContour
|
||||
@@ -1,3 +1,5 @@
|
||||
//package adjust
|
||||
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.shapes.adjust.adjustContour
|
||||
@@ -1,3 +1,5 @@
|
||||
//package adjust
|
||||
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.shapes.adjust.adjustContour
|
||||
52
orx-shapes/src/jvmDemo/kotlin/adjust/DemoAdjustContour08.kt
Normal file
52
orx-shapes/src/jvmDemo/kotlin/adjust/DemoAdjustContour08.kt
Normal file
@@ -0,0 +1,52 @@
|
||||
//package adjust
|
||||
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.shapes.adjust.adjustContour
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.shape.contour
|
||||
import kotlin.math.cos
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 800
|
||||
height = 800
|
||||
}
|
||||
program {
|
||||
extend {
|
||||
var contour = contour {
|
||||
moveTo(drawer.bounds.position(0.5, 0.1) - Vector2(300.0, 0.0))
|
||||
lineTo(drawer.bounds.position(0.5, 0.1) + Vector2(300.0, 0.0))
|
||||
}
|
||||
|
||||
contour = adjustContour(contour) {
|
||||
selectVertex(0)
|
||||
vertex.moveControlOutBy(Vector2(0.0, 100.0))
|
||||
|
||||
selectVertex(1)
|
||||
vertex.moveControlInBy(Vector2(0.0, -100.0))
|
||||
|
||||
}
|
||||
drawer.stroke = ColorRGBa.RED
|
||||
drawer.contour(contour)
|
||||
|
||||
|
||||
contour = contour {
|
||||
moveTo(drawer.bounds.position(0.5, 0.2) - Vector2(300.0, 0.0))
|
||||
lineTo(drawer.bounds.position(0.5, 0.2) + Vector2(300.0, 0.0))
|
||||
}
|
||||
|
||||
contour = adjustContour(contour) {
|
||||
selectEdge(0)
|
||||
edge.moveControl0By(Vector2(0.0, 100.0))
|
||||
edge.moveControl1By(Vector2(0.0, -100.0))
|
||||
|
||||
}
|
||||
drawer.stroke = ColorRGBa.RED
|
||||
drawer.contour(contour)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
60
orx-shapes/src/jvmDemo/kotlin/adjust/DemoAdjustContour09.kt
Normal file
60
orx-shapes/src/jvmDemo/kotlin/adjust/DemoAdjustContour09.kt
Normal file
@@ -0,0 +1,60 @@
|
||||
//package adjust
|
||||
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.shapes.adjust.adjustContour
|
||||
import org.openrndr.extra.shapes.adjust.extensions.averageTangents
|
||||
import org.openrndr.extra.shapes.adjust.extensions.switchTangents
|
||||
import org.openrndr.extra.shapes.tunni.tunniLine
|
||||
import org.openrndr.extra.shapes.tunni.tunniPoint
|
||||
import kotlin.math.sqrt
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 800
|
||||
height = 800
|
||||
}
|
||||
program {
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.WHITE)
|
||||
var contour = drawer.bounds.offsetEdges(-200.0).contour
|
||||
|
||||
drawer.fill = null
|
||||
|
||||
contour = adjustContour(contour) {
|
||||
selectVertices(0, 1)
|
||||
for (v in vertices) {
|
||||
v.averageTangents()
|
||||
v.scale(sqrt(2.0))
|
||||
v.rotate(45.0)
|
||||
}
|
||||
|
||||
selectVertices(2)
|
||||
for (v in vertices) {
|
||||
v.switchTangents()
|
||||
}
|
||||
}
|
||||
drawer.stroke = ColorRGBa.BLACK
|
||||
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])
|
||||
}
|
||||
drawer.fill = ColorRGBa.BLACK
|
||||
drawer.stroke = null
|
||||
drawer.circles(contour.segments.map { it.start }, 5.0)
|
||||
|
||||
drawer.stroke = ColorRGBa.GRAY
|
||||
for (s in contour.segments) {
|
||||
drawer.lineSegment(s.tunniLine)
|
||||
drawer.fill = ColorRGBa.CYAN
|
||||
drawer.circle(s.tunniPoint, 5.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
//package adjust
|
||||
|
||||
import kotlinx.coroutines.yield
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.shapes.adjust.adjustContourSequence
|
||||
import org.openrndr.extra.shapes.tunni.tunniLine
|
||||
import org.openrndr.extra.shapes.tunni.tunniPoint
|
||||
import org.openrndr.extra.shapes.tunni.withTunniLine
|
||||
import org.openrndr.launch
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.shape.Segment
|
||||
import kotlin.math.cos
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 800
|
||||
height = 800
|
||||
}
|
||||
program {
|
||||
|
||||
var res = drawer.bounds.offsetEdges(-200.0).contour
|
||||
var selectedSegments = emptyList<Segment>()
|
||||
var selectedPoints = emptyList<Vector2>()
|
||||
|
||||
val contourSeq = adjustContourSequence(res) {
|
||||
|
||||
sequence {
|
||||
for (i in 0 until 1000) {
|
||||
selectEdges()
|
||||
selectVertices((i*7).mod(4))
|
||||
for (v in vertices) {
|
||||
for (j in 0 until 30) {
|
||||
v.rotate(45.0/30.0)
|
||||
yield(status)
|
||||
}
|
||||
}
|
||||
|
||||
selectVertices((i*3).mod(4))
|
||||
for (v in vertices) {
|
||||
yield(status)
|
||||
|
||||
}
|
||||
|
||||
|
||||
selectVertices()
|
||||
selectEdges(i.mod(4))
|
||||
for (j in 0 until 30) {
|
||||
for (e in edges) {
|
||||
e.withTunniLine(e.tunniLine.position(0.5) + e.tunniLine.normal * cos(i.toDouble() + e.segmentIndex()) * 50.0/30.0)
|
||||
yield(status)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
launch {
|
||||
for (i in contourSeq) {
|
||||
res = i.contour
|
||||
selectedPoints = i.selectedPoints
|
||||
selectedSegments = i.selectedSegments
|
||||
yield()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.WHITE)
|
||||
drawer.stroke = ColorRGBa.BLACK
|
||||
drawer.contour(res)
|
||||
|
||||
drawer.stroke = ColorRGBa.RED
|
||||
|
||||
for (s in res.segments) {
|
||||
drawer.lineSegment(s.start, s.cubic.control[0])
|
||||
drawer.lineSegment(s.end, s.cubic.control[1])
|
||||
}
|
||||
drawer.fill = ColorRGBa.BLACK
|
||||
drawer.stroke = null
|
||||
drawer.circles(res.segments.map { it.start }, 5.0)
|
||||
|
||||
drawer.stroke = ColorRGBa.GRAY
|
||||
for (s in res.segments) {
|
||||
drawer.lineSegment(s.tunniLine)
|
||||
drawer.fill = ColorRGBa.CYAN
|
||||
drawer.circle(s.tunniPoint, 5.0)
|
||||
}
|
||||
|
||||
drawer.stroke = ColorRGBa.MAGENTA
|
||||
drawer.strokeWeight = 3.0
|
||||
for (s in selectedSegments) {
|
||||
drawer.segment(s)
|
||||
}
|
||||
for (p in selectedPoints) {
|
||||
drawer.circle(p, 5.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user