[orx-shapes] Refactor package layout
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package bezierpatch
|
||||
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.shapes.bezierpatches.bezierPatch
|
||||
import org.openrndr.shape.LineSegment
|
||||
import org.openrndr.shape.ShapeContour
|
||||
|
||||
/**
|
||||
* Shows how to
|
||||
* - create a [bezierPatch] out of 4 [LineSegment]
|
||||
* - create a sub-patch out of a [bezierPatch]
|
||||
* - create horizontal and vertical [ShapeContour]s out of [bezierPatch]es
|
||||
*
|
||||
* The created contours are horizontal and vertical in "bezier-patch space" but
|
||||
* are rendered deformed following the shape of the bezier patch.
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 800
|
||||
height = 800
|
||||
}
|
||||
program {
|
||||
// helper to get screen locations using normalized uv values
|
||||
fun pos(u: Double, v: Double) = drawer.bounds.position(u, v)
|
||||
val c0 = LineSegment(pos(0.1, 0.1), pos(0.9, 0.1))
|
||||
val c1 = LineSegment(pos(0.4, 0.3), pos(0.6, 0.4))
|
||||
val c2 = LineSegment(pos(0.4, 0.7), pos(0.6, 0.6))
|
||||
val c3 = LineSegment(pos(0.1, 0.9), pos(0.9, 0.9))
|
||||
|
||||
val bp = bezierPatch(c0.segment, c1.segment, c2.segment, c3.segment)
|
||||
val bpSub = bp.sub(0.1, 0.1, 0.6,0.6)
|
||||
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.PINK)
|
||||
|
||||
// Show the line segments that form the bezier patch
|
||||
drawer.stroke = ColorRGBa.YELLOW
|
||||
drawer.strokeWeight = 5.0
|
||||
drawer.lineSegments(listOf(c0, c1, c2, c3))
|
||||
|
||||
drawer.strokeWeight = 1.0
|
||||
for (i in 0..50) {
|
||||
drawer.stroke = ColorRGBa.BLACK
|
||||
drawer.contour(bp.horizontal(i / 50.0))
|
||||
drawer.contour(bp.vertical(i / 50.0))
|
||||
|
||||
drawer.stroke = ColorRGBa.RED
|
||||
drawer.contour(bpSub.horizontal(i / 50.0))
|
||||
drawer.contour(bpSub.vertical(i / 50.0))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package bezierpatch
|
||||
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.shapes.bezierpatches.bezierPatch
|
||||
import org.openrndr.shape.Circle
|
||||
import org.openrndr.shape.ShapeContour
|
||||
|
||||
/**
|
||||
* Shows how to create a [bezierPatch] out of a
|
||||
* closed [ShapeContour] with 4 curved segments.
|
||||
*
|
||||
* Calling [Circle.contour] is one way of producing
|
||||
* such a contour with vertices at the cardinal points
|
||||
* but one can manually create any other 4-segment closed contour
|
||||
* to use in bezier patches.
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 800
|
||||
height = 800
|
||||
}
|
||||
program {
|
||||
val c = Circle(width / 2.0, height / 2.0, 350.0).contour
|
||||
val bp = bezierPatch(c)
|
||||
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.PINK)
|
||||
drawer.stroke = ColorRGBa.BLACK
|
||||
|
||||
for (i in 0..10) {
|
||||
drawer.contour(bp.horizontal(i / 10.0))
|
||||
drawer.contour(bp.vertical(i / 10.0))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package bezierpatch
|
||||
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.shapes.bezierpatches.bezierPatch
|
||||
import org.openrndr.extra.shapes.bezierpatches.distort
|
||||
import org.openrndr.extra.shapes.primitives.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 {
|
||||
width = 800
|
||||
height = 800
|
||||
}
|
||||
program {
|
||||
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)
|
||||
|
||||
// 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 starMoved = star.transform(
|
||||
transform {
|
||||
translate(j * width / 10.0, i * height / 10.0)
|
||||
}
|
||||
)
|
||||
drawer.contour(bp.distort(starMoved, drawer.bounds))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package bezierpatch
|
||||
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.shapes.bezierpatches.bezierPatch
|
||||
import org.openrndr.shape.Circle
|
||||
|
||||
/**
|
||||
* Shows how to get positions and gradient values of those positions
|
||||
* from a [bezierPatch]
|
||||
*
|
||||
* You can think of bezierPatch.position() as requesting points
|
||||
* in a wavy flag (the bezier patch) using normalized uv coordinates.
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 800
|
||||
height = 800
|
||||
}
|
||||
program {
|
||||
val bp = bezierPatch(
|
||||
Circle(drawer.bounds.center, 350.0).contour
|
||||
//Rectangle.fromCenter(drawer.bounds.center, 550.0).contour
|
||||
)
|
||||
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.PINK)
|
||||
drawer.stroke = ColorRGBa.BLACK
|
||||
|
||||
for (j in 1 until 50 step 2) {
|
||||
for (i in 1 until 50 step 2) {
|
||||
val u = i / 50.0
|
||||
val v = j / 50.0
|
||||
val pos = bp.position(u, v)
|
||||
val grad = bp.gradient(u, v).normalized * 10.0
|
||||
val perpendicular = grad.perpendicular()
|
||||
drawer.lineSegment(pos - grad, pos + grad)
|
||||
drawer.lineSegment(pos - perpendicular, pos + perpendicular)
|
||||
//drawer.circle(pos + grad, 3.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package bezierpatch
|
||||
|
||||
import org.openrndr.WindowMultisample
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.shapes.bezierpatches.bezierPatch
|
||||
import org.openrndr.extra.camera.Orbital
|
||||
import org.openrndr.math.Vector3
|
||||
import org.openrndr.shape.Segment3D
|
||||
|
||||
/**
|
||||
* Shows how to
|
||||
* - create a [bezierPatch] out of 4 [Segment3D]
|
||||
* - create a sub-patch out of a [bezierPatch]
|
||||
* - create horizontal and vertical [Path3D]s out of [bezierPatch]es
|
||||
* - add colors to a [bezierPatch]
|
||||
* - draw a [bezierPatch] surface
|
||||
*
|
||||
* The created contours are horizontal and vertical in "bezier-patch space" but
|
||||
* are rendered deformed following the shape of the bezier patch.
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 800
|
||||
height = 800
|
||||
multisample = WindowMultisample.SampleCount(8)
|
||||
}
|
||||
program {
|
||||
val c0 = Segment3D(Vector3(-5.0, 0.0, -9.0), Vector3(5.0, 0.0, -9.0))
|
||||
val c1 = Segment3D(Vector3(-5.0, -5.0, -3.0), Vector3(5.0, -5.0, -3.0))
|
||||
val c2 = Segment3D(Vector3(-5.0, 5.0, 3.0), Vector3(5.0, 5.0, 3.0))
|
||||
val c3 = Segment3D(Vector3(-5.0, 0.0, 9.0), Vector3(5.0, 0.0, 9.0))
|
||||
|
||||
val col = listOf(ColorRGBa.PINK, ColorRGBa.RED, ColorRGBa.BLUE, ColorRGBa.PINK)
|
||||
val cols = listOf(col, col, col, col)
|
||||
val bp = bezierPatch(c0, c1, c2, c3).withColors(cols)
|
||||
val bpSub = bp.sub(0.1, 0.1, 0.6, 0.6)
|
||||
|
||||
val cam = Orbital()
|
||||
extend(cam){
|
||||
eye = Vector3(x=9.9, y=12.8, z=6.9)
|
||||
lookAt = Vector3(x=1.6, y=-1.9, z=1.2)
|
||||
}
|
||||
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.PINK)
|
||||
|
||||
drawer.translate(-5.0, 0.0, 0.0)
|
||||
// Show the segments that form the bezier patch
|
||||
drawer.stroke = ColorRGBa.YELLOW
|
||||
drawer.strokeWeight = 50.0
|
||||
drawer.segments(listOf(c0, c1, c2, c3))
|
||||
|
||||
// Show the grid
|
||||
drawer.strokeWeight = 1.0
|
||||
val n = 10
|
||||
for (i in 0..n) {
|
||||
drawer.stroke = ColorRGBa.BLACK
|
||||
drawer.lineStrip(bp.horizontal(i / n.toDouble()).adaptivePositions(0.01))
|
||||
drawer.lineStrip(bp.vertical(i / n.toDouble()).adaptivePositions(0.01))
|
||||
|
||||
drawer.stroke = ColorRGBa.RED
|
||||
drawer.lineStrip(bpSub.horizontal(i / n.toDouble()).adaptivePositions(0.01))
|
||||
drawer.lineStrip(bpSub.vertical(i / n.toDouble()).adaptivePositions(0.01))
|
||||
}
|
||||
|
||||
// Draw the colored Bezier surface
|
||||
drawer.translate(10.0, 0.0, 0.0)
|
||||
drawer.bezierPatch(bp)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package bezierpatch
|
||||
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.shapes.bezierpatches.bezierPatch
|
||||
import org.openrndr.shape.Circle
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package bezierpatch
|
||||
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.loadFont
|
||||
import org.openrndr.extra.color.spaces.toOKLABa
|
||||
import org.openrndr.extra.shapes.bezierpatches.bezierPatch
|
||||
import org.openrndr.shape.Circle
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
}
|
||||
program {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package bezierpatch
|
||||
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.isolated
|
||||
import org.openrndr.extra.color.spaces.toOKLABa
|
||||
import org.openrndr.extra.shapes.bezierpatches.bezierPatch
|
||||
import org.openrndr.extra.shapes.primitives.grid
|
||||
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 {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package bezierpatch
|
||||
|
||||
import org.openrndr.application
|
||||
import org.openrndr.extra.shapes.bezierpatches.bezierPatch
|
||||
import org.openrndr.extra.shapes.bezierpatches.bezierPatches
|
||||
import org.openrndr.shape.Circle
|
||||
import org.openrndr.shape.ShapeContour
|
||||
|
||||
/**
|
||||
* Shows how to create a [bezierPatch] out of a
|
||||
* closed [ShapeContour] with 4 curved segments.
|
||||
*
|
||||
* Calling [Circle.contour] is one way of producing
|
||||
* such a contour with vertices at the cardinal points
|
||||
* but one can manually create any other 4-segment closed contour
|
||||
* to use in bezier patches.
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 800
|
||||
height = 800
|
||||
}
|
||||
program {
|
||||
val c0 = Circle(width / 3.0, height / 2.0, 150.0).contour
|
||||
val bp0 = bezierPatch(c0)
|
||||
|
||||
val c1 = Circle(2.0*width / 3.0, height / 2.0, 150.0).contour
|
||||
val bp1 = bezierPatch(c1)
|
||||
|
||||
|
||||
extend {
|
||||
drawer.bezierPatches(listOf(bp0, bp1))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user