44 lines
1.4 KiB
Kotlin
44 lines
1.4 KiB
Kotlin
package path3d
|
|
|
|
import org.openrndr.application
|
|
import org.openrndr.color.ColorRGBa
|
|
import org.openrndr.draw.LineJoin
|
|
import org.openrndr.extra.camera.Orbital
|
|
import org.openrndr.extra.shapes.path3d.projectToContour
|
|
import org.openrndr.math.Spherical
|
|
import org.openrndr.math.Vector3
|
|
import org.openrndr.shape.ShapeContour
|
|
import org.openrndr.shape.path3D
|
|
|
|
/**
|
|
* Demonstrates how to convert a 3D path as seen by an [Orbital] camera to a 2D [ShapeContour].
|
|
*
|
|
* Among other uses, this can be useful when working with pen plotters,
|
|
* to export a 3D path to an SVG file, or to apply 2D contour post-processing with
|
|
* [org.openrndr.extra.shapes.adjust.adjustContour].
|
|
*
|
|
*/
|
|
fun main() = application {
|
|
program {
|
|
val path = path3D {
|
|
var p = Vector3(6.0, 0.0, 0.0)
|
|
moveTo(p)
|
|
for (i in 0 until 100) {
|
|
p = Spherical((i % 6) * 45.0, (i % 4 + 1) * 30.0 + i * 0.1, 6.0).cartesian
|
|
arcTo(5.0, cursor.atan2(p), false, false, p)
|
|
}
|
|
}
|
|
extend(Orbital())
|
|
extend {
|
|
drawer.stroke = ColorRGBa.PINK
|
|
drawer.path(path)
|
|
val c = path.projectToContour(drawer.projection, drawer.view, width, height)
|
|
drawer.defaults()
|
|
drawer.stroke = ColorRGBa.WHITE
|
|
drawer.lineJoin = LineJoin.ROUND
|
|
drawer.strokeWeight = 2.0
|
|
drawer.contour(c)
|
|
}
|
|
}
|
|
}
|