Fixes and move to jvmDemo (#286)
This commit is contained in:
24
orx-shapes/src/jvmDemo/kotlin/DemoAlphaShape.kt
Normal file
24
orx-shapes/src/jvmDemo/kotlin/DemoAlphaShape.kt
Normal file
@@ -0,0 +1,24 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.shapes.AlphaShape
|
||||
import org.openrndr.math.Vector2
|
||||
import kotlin.random.Random
|
||||
|
||||
fun main() = application {
|
||||
program {
|
||||
val points = List(40) {
|
||||
Vector2(
|
||||
Random.nextDouble(width*0.25, width*0.75),
|
||||
Random.nextDouble(height*0.25, height*0.75)
|
||||
)
|
||||
}
|
||||
val alphaShape = AlphaShape(points)
|
||||
val c = alphaShape.createContour()
|
||||
extend {
|
||||
drawer.fill = ColorRGBa.PINK
|
||||
drawer.contour(c)
|
||||
drawer.fill = ColorRGBa.WHITE
|
||||
drawer.circles(points, 4.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
55
orx-shapes/src/jvmDemo/kotlin/DemoBezierPatch01.kt
Normal file
55
orx-shapes/src/jvmDemo/kotlin/DemoBezierPatch01.kt
Normal file
@@ -0,0 +1,55 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extensions.SingleScreenshot
|
||||
import org.openrndr.extra.shapes.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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
38
orx-shapes/src/jvmDemo/kotlin/DemoBezierPatch02.kt
Normal file
38
orx-shapes/src/jvmDemo/kotlin/DemoBezierPatch02.kt
Normal file
@@ -0,0 +1,38 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extensions.SingleScreenshot
|
||||
import org.openrndr.extra.shapes.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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
57
orx-shapes/src/jvmDemo/kotlin/DemoBezierPatch03.kt
Normal file
57
orx-shapes/src/jvmDemo/kotlin/DemoBezierPatch03.kt
Normal file
@@ -0,0 +1,57 @@
|
||||
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.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 {
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
45
orx-shapes/src/jvmDemo/kotlin/DemoBezierPatch04.kt
Normal file
45
orx-shapes/src/jvmDemo/kotlin/DemoBezierPatch04.kt
Normal file
@@ -0,0 +1,45 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extensions.SingleScreenshot
|
||||
import org.openrndr.extra.shapes.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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
75
orx-shapes/src/jvmDemo/kotlin/DemoBezierPatch05.kt
Normal file
75
orx-shapes/src/jvmDemo/kotlin/DemoBezierPatch05.kt
Normal file
@@ -0,0 +1,75 @@
|
||||
import org.openrndr.WindowMultisample
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.BufferMultisample
|
||||
import org.openrndr.extensions.SingleScreenshot
|
||||
import org.openrndr.extra.shapes.bezierPatch
|
||||
import org.openrndr.extra.shapes.drawers.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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
37
orx-shapes/src/jvmDemo/kotlin/DemoBezierPatchDrawer01.kt
Normal file
37
orx-shapes/src/jvmDemo/kotlin/DemoBezierPatchDrawer01.kt
Normal file
@@ -0,0 +1,37 @@
|
||||
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 {
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
49
orx-shapes/src/jvmDemo/kotlin/DemoBezierPatchDrawer02.kt
Normal file
49
orx-shapes/src/jvmDemo/kotlin/DemoBezierPatchDrawer02.kt
Normal file
@@ -0,0 +1,49 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.loadFont
|
||||
import org.openrndr.extensions.SingleScreenshot
|
||||
import org.openrndr.extra.color.spaces.toOKLABa
|
||||
import org.openrndr.extra.shapes.bezierPatch
|
||||
import org.openrndr.extra.shapes.drawers.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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
63
orx-shapes/src/jvmDemo/kotlin/DemoBezierPatchDrawer03.kt
Normal file
63
orx-shapes/src/jvmDemo/kotlin/DemoBezierPatchDrawer03.kt
Normal file
@@ -0,0 +1,63 @@
|
||||
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.extra.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 {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
38
orx-shapes/src/jvmDemo/kotlin/DemoBezierPatches01.kt
Normal file
38
orx-shapes/src/jvmDemo/kotlin/DemoBezierPatches01.kt
Normal file
@@ -0,0 +1,38 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extensions.SingleScreenshot
|
||||
import org.openrndr.extra.shapes.bezierPatch
|
||||
import org.openrndr.shape.Circle
|
||||
import org.openrndr.shape.ShapeContour
|
||||
import org.openrndr.extra.shapes.drawers.bezierPatch
|
||||
import org.openrndr.extra.shapes.drawers.bezierPatches
|
||||
|
||||
/**
|
||||
* 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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
17
orx-shapes/src/jvmDemo/kotlin/DemoHobbyCurve01.kt
Normal file
17
orx-shapes/src/jvmDemo/kotlin/DemoHobbyCurve01.kt
Normal file
@@ -0,0 +1,17 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.shapes.hobbyCurve
|
||||
import org.openrndr.math.Vector2
|
||||
|
||||
fun main() = application {
|
||||
program {
|
||||
extend {
|
||||
val points = listOf(Vector2(150.0, 350.0), Vector2(325.0, 100.0), Vector2(500.0, 350.0), Vector2(325.0, 250.0))
|
||||
drawer.stroke = ColorRGBa.BLACK
|
||||
drawer.fill = ColorRGBa.PINK
|
||||
drawer.contour(hobbyCurve(points, closed=true))
|
||||
drawer.fill = ColorRGBa.WHITE
|
||||
drawer.circles(points, 4.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
26
orx-shapes/src/jvmDemo/kotlin/DemoHobbyCurve02.kt
Normal file
26
orx-shapes/src/jvmDemo/kotlin/DemoHobbyCurve02.kt
Normal file
@@ -0,0 +1,26 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.shapes.AlphaShape
|
||||
import org.openrndr.extra.shapes.hobbyCurve
|
||||
import org.openrndr.math.Vector2
|
||||
import kotlin.random.Random
|
||||
|
||||
fun main() = application {
|
||||
program {
|
||||
val points = List(40) {
|
||||
Vector2(
|
||||
Random.nextDouble(width*0.25, width*0.75),
|
||||
Random.nextDouble(height*0.25, height*0.75)
|
||||
)
|
||||
}
|
||||
val alphaShape = AlphaShape(points)
|
||||
val c = alphaShape.createContour()
|
||||
val hobby = hobbyCurve(c.segments.map { it.start }, closed=true)
|
||||
extend {
|
||||
drawer.fill = ColorRGBa.PINK
|
||||
drawer.contour(hobby)
|
||||
drawer.fill = ColorRGBa.WHITE
|
||||
drawer.circles(points, 4.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
26
orx-shapes/src/jvmDemo/kotlin/DemoRectangleGrid01.kt
Normal file
26
orx-shapes/src/jvmDemo/kotlin/DemoRectangleGrid01.kt
Normal file
@@ -0,0 +1,26 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.shapes.grid
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 800
|
||||
height = 800
|
||||
}
|
||||
program {
|
||||
extend {
|
||||
drawer.fill = ColorRGBa.WHITE.opacify(0.25)
|
||||
drawer.stroke = ColorRGBa.PINK
|
||||
|
||||
// Notice the negative gutter in this grid. It creates an
|
||||
// overlap between the resulting rectangles.
|
||||
val grid = drawer.bounds.grid(8, 4, 20.0, 20.0, -20.0, -20.0)
|
||||
for (cell in grid.flatten()) {
|
||||
drawer.rectangle(cell)
|
||||
drawer.lineSegment(cell.position(0.0, 0.0), cell.position(1.0, 1.0))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
37
orx-shapes/src/jvmDemo/kotlin/DemoRectangleGrid02.kt
Normal file
37
orx-shapes/src/jvmDemo/kotlin/DemoRectangleGrid02.kt
Normal file
@@ -0,0 +1,37 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.noise.Random
|
||||
import org.openrndr.extra.shapes.grid
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
// Try changing the resolution. The design will use the available space.
|
||||
configure {
|
||||
width = 800
|
||||
height = 400
|
||||
}
|
||||
program {
|
||||
// By specifying the cell size we make sure the design will
|
||||
// contain squares, independently of the window size and its
|
||||
// aspect ratio.
|
||||
val grid = drawer.bounds.grid(50.0, 50.0,
|
||||
20.0, 20.0, 20.0, 20.0).flatten()
|
||||
|
||||
val grid2 = grid.map { rect ->
|
||||
// Each of these inner grids will occupy the available space
|
||||
// in the parent grid cells. Notice how we don't specify cell
|
||||
// sizes here but counts instead (between 1 and 3 columns and
|
||||
// rows)
|
||||
val count = Random.int(1, 4)
|
||||
rect.grid(count, count, 5.0, 5.0, 5.0, 5.0).flatten()
|
||||
}.flatten().filter { Random.bool(0.5)}
|
||||
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.PINK)
|
||||
drawer.rectangles(grid)
|
||||
drawer.fill = ColorRGBa.BLACK
|
||||
drawer.rectangles(grid2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
orx-shapes/src/jvmDemo/kotlin/DemoRegularPolygon.kt
Normal file
31
orx-shapes/src/jvmDemo/kotlin/DemoRegularPolygon.kt
Normal file
@@ -0,0 +1,31 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.isolated
|
||||
import org.openrndr.extensions.SingleScreenshot
|
||||
import org.openrndr.extra.shapes.regularPolygon
|
||||
import org.openrndr.math.map
|
||||
import kotlin.math.cos
|
||||
|
||||
fun main() = application {
|
||||
program {
|
||||
extend {
|
||||
drawer.fill = ColorRGBa.PINK
|
||||
drawer.stroke = ColorRGBa.WHITE
|
||||
|
||||
for (sides in 0 until 8) {
|
||||
val radius0 = cos(seconds + sides) * 20.0 + 40.0
|
||||
val star = regularPolygon(sides + 3, radius = radius0)
|
||||
|
||||
drawer.isolated {
|
||||
translate(
|
||||
(sides % 4.0).map(0.0, 3.0,
|
||||
width * 0.2, width * 0.8),
|
||||
(sides / 4).toDouble().map(0.0, 1.0,
|
||||
height * 0.3, height * 0.7))
|
||||
rotate(seconds * 45.0)
|
||||
contour(star)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
23
orx-shapes/src/jvmDemo/kotlin/DemoRegularStar01.kt
Normal file
23
orx-shapes/src/jvmDemo/kotlin/DemoRegularStar01.kt
Normal file
@@ -0,0 +1,23 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extensions.SingleScreenshot
|
||||
import org.openrndr.extra.shapes.regularStar
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.sin
|
||||
|
||||
fun main() = application {
|
||||
program {
|
||||
extend {
|
||||
drawer.fill = ColorRGBa.PINK
|
||||
drawer.stroke = ColorRGBa.WHITE
|
||||
val radius0 = cos(seconds + 2) * 50.0 + 130.0
|
||||
val radius1 = sin(seconds + 2) * 50.0 + 130.0
|
||||
|
||||
val star = regularStar(5, radius0, radius1)
|
||||
|
||||
drawer.translate(width / 2.0, height / 2.0)
|
||||
drawer.rotate(seconds * 45.0)
|
||||
drawer.contour(star)
|
||||
}
|
||||
}
|
||||
}
|
||||
39
orx-shapes/src/jvmDemo/kotlin/DemoRegularStar02.kt
Normal file
39
orx-shapes/src/jvmDemo/kotlin/DemoRegularStar02.kt
Normal file
@@ -0,0 +1,39 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extensions.SingleScreenshot
|
||||
import org.openrndr.extra.shapes.regularStar
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.shape.contains
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.sin
|
||||
|
||||
fun main() = application {
|
||||
program {
|
||||
extend {
|
||||
drawer.fill = ColorRGBa.PINK
|
||||
drawer.stroke = ColorRGBa.WHITE
|
||||
val radius0 = cos(seconds) * 50.0 + 130.0
|
||||
val radius1 = sin(seconds * 2.0) * 50.0 + 130.0
|
||||
|
||||
val star = regularStar(12, radius0, radius1)
|
||||
|
||||
drawer.translate(width / 2.0, height / 2.0)
|
||||
drawer.rotate(seconds * 45.0)
|
||||
drawer.fill = null
|
||||
drawer.strokeWeight = 2.0
|
||||
drawer.contour(star)
|
||||
|
||||
drawer.strokeWeight = 1.0
|
||||
drawer.fill = ColorRGBa.WHITE
|
||||
|
||||
for (j in -20 until 20) {
|
||||
for (i in -20 until 20) {
|
||||
val q = Vector2(i * 10.0, j * 10.0)
|
||||
if (q in star) {
|
||||
drawer.circle(i * 10.0, j * 10.0, 5.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
17
orx-shapes/src/jvmDemo/kotlin/DemoRoundedRectangle.kt
Normal file
17
orx-shapes/src/jvmDemo/kotlin/DemoRoundedRectangle.kt
Normal file
@@ -0,0 +1,17 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extensions.SingleScreenshot
|
||||
import org.openrndr.extra.shapes.RoundedRectangle
|
||||
import kotlin.math.cos
|
||||
|
||||
fun main() = application {
|
||||
program {
|
||||
extend {
|
||||
drawer.fill = ColorRGBa.WHITE
|
||||
drawer.stroke = ColorRGBa.PINK
|
||||
val radius = cos(seconds) * 20.0 + 20.0
|
||||
val rectangle = RoundedRectangle(50.0, 50.0, width - 100.0, height - 100.0, radius)
|
||||
drawer.contour(rectangle.contour)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user