Add comments to bezierPatch demos, simplify. (#173)

This commit is contained in:
Abe Pazos
2021-02-23 08:24:10 +01:00
committed by GitHub
parent 10aed4d53d
commit 8d6b82a24e
4 changed files with 95 additions and 42 deletions

View File

@@ -1,12 +1,19 @@
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extensions.Screenshots
import org.openrndr.extensions.SingleScreenshot
import org.openrndr.extra.shapes.bezierPatch
import org.openrndr.extra.shapes.distort
import org.openrndr.extra.shapes.regularStarRounded
import org.openrndr.math.transforms.transform
import org.openrndr.shape.Circle
import org.openrndr.shape.ShapeContour
/**
* Shows how to distort [ShapeContour]s using a [bezierPatch]
*
* In this case the contours are regular stars and the bezier patch
* is created using a circular contour with the required 4 segments.
*/
fun main() {
application {
configure {
@@ -19,26 +26,35 @@ fun main() {
this.outputFile = System.getProperty("screenshotPath")
}
}
extend(Screenshots())
val bp = bezierPatch(
Circle(width / 2.0, height / 2.0, 350.0).contour
)
val star = regularStarRounded(
7, 30.0, 40.0,
0.5, 0.5
)
extend {
drawer.clear(ColorRGBa.PINK)
val bp = bezierPatch(Circle(width / 2.0, height / 2.0, 350.0).contour)
// draw grid
for (i in 0..50) {
drawer.stroke = ColorRGBa.BLACK
drawer.contour(bp.horizontal(i / 50.0))
drawer.contour(bp.vertical(i / 50.0))
}
// draw stars
drawer.fill = ColorRGBa.PINK
for (j in 1 until 10) {
for (i in 1 until 10) {
val r = regularStarRounded(7, 30.0, 40.0, 0.5, 0.5).transform(
transform {
translate(j * width / 10.0, i * height / 10.0)
}
val starMoved = star.transform(
transform {
translate(j * width / 10.0, i * height / 10.0)
}
)
val dr = bp.distort(r, drawer.bounds)
drawer.contour(dr)
drawer.contour(bp.distort(starMoved, drawer.bounds))
}
}
}