Demos: ensure all use fun main() = application {

- Adjust some demo window sizes.
- Replace Random.double by Double.uniform
- Tweak some demos so screenshots look more interesting
This commit is contained in:
Abe Pazos
2025-01-26 20:57:04 +01:00
parent 1975a820fc
commit c8f7dd52c6
116 changed files with 2889 additions and 2942 deletions

View File

@@ -15,42 +15,40 @@ import org.openrndr.shape.ShapeContour
* 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))
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)
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)
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))
// 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.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))
}
drawer.stroke = ColorRGBa.RED
drawer.contour(bpSub.horizontal(i / 50.0))
drawer.contour(bpSub.vertical(i / 50.0))
}
}
}
}
}

View File

@@ -15,25 +15,23 @@ import org.openrndr.shape.ShapeContour
* 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)
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
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))
}
for (i in 0..10) {
drawer.contour(bp.horizontal(i / 10.0))
drawer.contour(bp.vertical(i / 10.0))
}
}
}
}
}

View File

@@ -15,44 +15,42 @@ import org.openrndr.shape.ShapeContour
* 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
)
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)
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 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))
}
// 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))
}
}
}
}
}
}

View File

@@ -12,35 +12,33 @@ import org.openrndr.shape.Circle
* 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
)
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
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)
}
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)
}
}
}
}
}
}

View File

@@ -3,8 +3,8 @@ 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.extra.shapes.bezierpatches.bezierPatch
import org.openrndr.math.Vector3
import org.openrndr.shape.Segment3D
@@ -19,56 +19,54 @@ import org.openrndr.shape.Segment3D
* 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)
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)
}
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)
extend {
drawer.clear(ColorRGBa.PINK)
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)
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))
}
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)
}
// Draw the colored Bezier surface
drawer.translate(10.0, 0.0, 0.0)
drawer.bezierPatch(bp)
}
}
}
}

View File

@@ -5,33 +5,31 @@ 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(
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),
)
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.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))
}
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))
}
}
}
}
}

View File

@@ -7,43 +7,61 @@ 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(
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),
)
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(
)
drawer.bezierPatch(bp2)
val bp3 = bezierPatch(
Circle(width / 2.0 + 180.0, height / 2.0, 170.0).contour
).withColors(
listOf(
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()),
)
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.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)
}
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)
}
}
}
}

View File

@@ -13,49 +13,67 @@ 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()),
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)
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)
}
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)
}
}
}
}
}
}
}

View File

@@ -15,23 +15,21 @@ import org.openrndr.shape.ShapeContour
* 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)
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)
val c1 = Circle(2.0 * width / 3.0, height / 2.0, 150.0).contour
val bp1 = bezierPatch(c1)
extend {
drawer.bezierPatches(listOf(bp0, bp1))
}
extend {
drawer.bezierPatches(listOf(bp0, bp1))
}
}
}
}