[orx-shapes] Add Drawer.bezierPatches
This commit is contained in:
42
orx-shapes/src/demo/kotlin/DemoBezierPatchDrawer01.kt
Normal file
42
orx-shapes/src/demo/kotlin/DemoBezierPatchDrawer01.kt
Normal file
@@ -0,0 +1,42 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extensions.SingleScreenshot
|
||||
import org.openrndr.extra.shapes.bezierPatch
|
||||
import org.openrndr.extra.shapes.drawers.bezierPatch
|
||||
import org.openrndr.shape.Circle
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
if (System.getProperty("takeScreenshot") == "true") {
|
||||
extend(SingleScreenshot()) {
|
||||
this.outputFile = System.getProperty("screenshotPath")
|
||||
}
|
||||
}
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.PINK)
|
||||
val bp = bezierPatch(
|
||||
Circle(width/2.0, height/2.0, 200.0).contour
|
||||
).withColors(
|
||||
listOf(
|
||||
listOf(ColorRGBa.PINK, ColorRGBa.RED, ColorRGBa.BLACK, ColorRGBa.BLUE),
|
||||
listOf(ColorRGBa.RED, ColorRGBa.BLACK, ColorRGBa.BLUE, ColorRGBa.GREEN),
|
||||
listOf(ColorRGBa.PINK, ColorRGBa.RED, ColorRGBa.WHITE, ColorRGBa.GREEN),
|
||||
listOf(ColorRGBa.BLACK, ColorRGBa.WHITE, ColorRGBa.BLACK, ColorRGBa.BLUE),
|
||||
)
|
||||
)
|
||||
|
||||
drawer.bezierPatch(bp)
|
||||
|
||||
drawer.fill = null
|
||||
drawer.contour(bp.contour)
|
||||
for (i in 0 until 10) {
|
||||
drawer.contour(bp.horizontal(i/9.0))
|
||||
}
|
||||
for (i in 0 until 10) {
|
||||
drawer.contour(bp.vertical(i/9.0))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
54
orx-shapes/src/demo/kotlin/DemoBezierPatchDrawer02.kt
Normal file
54
orx-shapes/src/demo/kotlin/DemoBezierPatchDrawer02.kt
Normal file
@@ -0,0 +1,54 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.loadFont
|
||||
import org.openrndr.extensions.SingleScreenshot
|
||||
import org.openrndr.extra.shapes.bezierPatch
|
||||
import org.openrndr.extra.shapes.drawers.bezierPatch
|
||||
import org.openrndr.extras.color.spaces.toOKLABa
|
||||
import org.openrndr.shape.Circle
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
}
|
||||
program {
|
||||
if (System.getProperty("takeScreenshot") == "true") {
|
||||
extend(SingleScreenshot()) {
|
||||
this.outputFile = System.getProperty("screenshotPath")
|
||||
}
|
||||
}
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.BLACK)
|
||||
val bp2 = bezierPatch(
|
||||
Circle(width/2.0 - 180.0, height/2.0, 170.0).contour
|
||||
).withColors(
|
||||
listOf(
|
||||
listOf(ColorRGBa.PINK, ColorRGBa.PINK, ColorRGBa.PINK, ColorRGBa.PINK),
|
||||
listOf(ColorRGBa.RED, ColorRGBa.RED, ColorRGBa.RED, ColorRGBa.RED),
|
||||
listOf(ColorRGBa.BLUE, ColorRGBa.BLUE, ColorRGBa.BLUE, ColorRGBa.BLUE),
|
||||
listOf(ColorRGBa.WHITE, ColorRGBa.WHITE, ColorRGBa.WHITE, ColorRGBa.WHITE),
|
||||
)
|
||||
)
|
||||
drawer.bezierPatch(bp2)
|
||||
val bp3 = bezierPatch(
|
||||
Circle(width/2.0 + 180.0, height/2.0, 170.0).contour
|
||||
).withColors(
|
||||
listOf(
|
||||
listOf(ColorRGBa.PINK.toOKLABa(), ColorRGBa.PINK.toOKLABa(), ColorRGBa.PINK.toOKLABa(), ColorRGBa.PINK.toOKLABa()),
|
||||
listOf(ColorRGBa.RED.toOKLABa(), ColorRGBa.RED.toOKLABa(), ColorRGBa.RED.toOKLABa(), ColorRGBa.RED.toOKLABa()),
|
||||
listOf(ColorRGBa.BLUE.toOKLABa(), ColorRGBa.BLUE.toOKLABa(), ColorRGBa.BLUE.toOKLABa(), ColorRGBa.BLUE.toOKLABa()),
|
||||
listOf(ColorRGBa.WHITE.toOKLABa(), ColorRGBa.WHITE.toOKLABa(), ColorRGBa.WHITE.toOKLABa(), ColorRGBa.WHITE.toOKLABa()),
|
||||
)
|
||||
)
|
||||
drawer.bezierPatch(bp3)
|
||||
|
||||
drawer.fill = ColorRGBa.WHITE
|
||||
drawer.fontMap = loadFont("demo-data/fonts/IBMPlexMono-Regular.ttf", 16.0)
|
||||
drawer.text("RGB", width/2.0 - 180.0, height/2.0 + 200.0)
|
||||
drawer.text("OKLab", width/2.0 + 180.0, height/2.0 + 200.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
68
orx-shapes/src/demo/kotlin/DemoBezierPatchDrawer03.kt
Normal file
68
orx-shapes/src/demo/kotlin/DemoBezierPatchDrawer03.kt
Normal file
@@ -0,0 +1,68 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.isolated
|
||||
import org.openrndr.draw.loadFont
|
||||
import org.openrndr.extensions.SingleScreenshot
|
||||
import org.openrndr.extra.shapes.bezierPatch
|
||||
import org.openrndr.extra.shapes.drawers.bezierPatch
|
||||
import org.openrndr.extra.shapes.grid
|
||||
import org.openrndr.extras.color.spaces.toOKLABa
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.math.Vector3
|
||||
import org.openrndr.math.min
|
||||
import org.openrndr.math.transforms.buildTransform
|
||||
import org.openrndr.shape.Circle
|
||||
import org.openrndr.shape.Rectangle
|
||||
import kotlin.math.min
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
}
|
||||
program {
|
||||
if (System.getProperty("takeScreenshot") == "true") {
|
||||
extend(SingleScreenshot()) {
|
||||
this.outputFile = System.getProperty("screenshotPath")
|
||||
}
|
||||
}
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.BLACK)
|
||||
val colors = listOf(
|
||||
listOf(ColorRGBa.PINK.toOKLABa(), ColorRGBa.PINK.toOKLABa(), ColorRGBa.PINK.toOKLABa(), ColorRGBa.PINK.toOKLABa()),
|
||||
listOf(ColorRGBa.RED.toOKLABa(), ColorRGBa.RED.toOKLABa(), ColorRGBa.RED.toOKLABa(), ColorRGBa.RED.toOKLABa()),
|
||||
listOf(ColorRGBa.BLUE.toOKLABa(), ColorRGBa.BLUE.toOKLABa(), ColorRGBa.BLUE.toOKLABa(), ColorRGBa.BLUE.toOKLABa()),
|
||||
listOf(ColorRGBa.WHITE.toOKLABa(), ColorRGBa.WHITE.toOKLABa(), ColorRGBa.WHITE.toOKLABa(), ColorRGBa.WHITE.toOKLABa()),
|
||||
)
|
||||
|
||||
val grid = drawer.bounds.grid(4,4, marginX = 20.0, marginY = 20.0, gutterX = 10.0, gutterY = 10.0)
|
||||
|
||||
val cellWidth = grid[0][0].width
|
||||
val cellHeight = grid[0][0].height
|
||||
|
||||
val a = bezierPatch(Rectangle.fromCenter(Vector2(0.0, 0.0), cellWidth, cellHeight).contour)
|
||||
.withColors(colors)
|
||||
|
||||
val b = bezierPatch(
|
||||
Circle(0.0, 0.0, min(cellWidth, cellHeight) / 2.0).contour.transform(
|
||||
buildTransform {
|
||||
rotate(Vector3.UNIT_Z, 45.0)
|
||||
}
|
||||
)
|
||||
).withColors(colors)
|
||||
|
||||
for (y in grid.indices) {
|
||||
for (x in grid[y].indices) {
|
||||
val f = (y * grid[y].size + x).toDouble() / (grid.size * grid[y].size - 1.0)
|
||||
val blend = a * (1.0 - f) + b * f
|
||||
drawer.isolated {
|
||||
drawer.translate(grid[y][x].center)
|
||||
drawer.bezierPatch(blend)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user