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

@@ -8,28 +8,26 @@ import org.openrndr.shape.Circle
import kotlin.math.cos
import kotlin.math.sin
fun main() {
application {
configure {
width = 800
height = 800
}
program {
extend {
var contour = Circle(drawer.bounds.center, 300.0).contour
contour = adjustContour(contour) {
selectVertex(0)
vertex.moveBy(Vector2(cos(seconds) * 40.0, sin(seconds * 0.43) * 40.0))
fun main() = application {
configure {
width = 800
height = 800
}
program {
extend {
var contour = Circle(drawer.bounds.center, 300.0).contour
contour = adjustContour(contour) {
selectVertex(0)
vertex.moveBy(Vector2(cos(seconds) * 40.0, sin(seconds * 0.43) * 40.0))
selectVertex(2)
vertex.rotate(seconds * 45.0)
selectVertex(2)
vertex.rotate(seconds * 45.0)
selectVertex(1)
vertex.scale(cos(seconds*0.943)*2.0)
}
drawer.stroke = ColorRGBa.RED
drawer.contour(contour)
selectVertex(1)
vertex.scale(cos(seconds * 0.943) * 2.0)
}
drawer.stroke = ColorRGBa.RED
drawer.contour(contour)
}
}
}
}

View File

@@ -8,27 +8,25 @@ import org.openrndr.shape.Circle
import kotlin.math.cos
import kotlin.math.sin
fun main() {
application {
configure {
width = 800
height = 800
}
program {
extend {
var contour = Circle(drawer.bounds.center, 300.0).contour
contour = adjustContour(contour) {
selectVertex(0)
vertex.remove()
selectVertex(0)
vertex.moveBy(Vector2(cos(seconds) * 40.0, sin(seconds * 0.43) * 40.0))
vertex.scale(cos(seconds*2.0)*2.0)
fun main() = application {
configure {
width = 800
height = 800
}
program {
extend {
var contour = Circle(drawer.bounds.center, 300.0).contour
contour = adjustContour(contour) {
selectVertex(0)
vertex.remove()
selectVertex(0)
vertex.moveBy(Vector2(cos(seconds) * 40.0, sin(seconds * 0.43) * 40.0))
vertex.scale(cos(seconds * 2.0) * 2.0)
}
drawer.stroke = ColorRGBa.RED
drawer.contour(contour)
}
drawer.stroke = ColorRGBa.RED
drawer.contour(contour)
}
}
}
}

View File

@@ -7,37 +7,35 @@ import org.openrndr.math.Vector2
import kotlin.math.cos
import kotlin.math.sin
fun main() {
application {
configure {
width = 800
height = 800
}
program {
extend {
var contour = drawer.bounds.scaledBy(0.5, 0.5, 0.5).contour
contour = adjustContour(contour) {
for (i in 0 until 4) {
selectEdge(i)
edge.toCubic()
}
selectEdge(0)
edge.scale(0.5, 0.5)
edge.rotate(cos(seconds*0.5)*30.0)
selectEdge(1)
fun main() = application {
configure {
width = 800
height = 800
}
program {
extend {
var contour = drawer.bounds.scaledBy(0.5, 0.5, 0.5).contour
contour = adjustContour(contour) {
for (i in 0 until 4) {
selectEdge(i)
edge.toCubic()
edge.splitAt(0.5)
edge.moveBy(Vector2(cos(seconds*10.0) * 40.0, 0.0))
//edge.next?.select()
selectEdge(3)
edge.moveBy(Vector2(0.0, sin(seconds*10.0) * 40.0))
}
drawer.stroke = ColorRGBa.RED
drawer.contour(contour)
selectEdge(0)
edge.scale(0.5, 0.5)
edge.rotate(cos(seconds * 0.5) * 30.0)
selectEdge(1)
edge.toCubic()
edge.splitAt(0.5)
edge.moveBy(Vector2(cos(seconds * 10.0) * 40.0, 0.0))
//edge.next?.select()
selectEdge(3)
edge.moveBy(Vector2(0.0, sin(seconds * 10.0) * 40.0))
}
drawer.stroke = ColorRGBa.RED
drawer.contour(contour)
}
}
}
}

View File

@@ -6,26 +6,24 @@ import org.openrndr.extra.shapes.adjust.adjustContour
import org.openrndr.shape.Circle
import kotlin.math.cos
fun main() {
application {
configure {
width = 800
height = 800
}
program {
extend {
var contour = if (seconds.mod(2.0) < 1.0) {
drawer.bounds.scaledBy(0.5, 0.5, 0.5).contour
} else {
Circle(drawer.bounds.center, 300.0).contour
}
contour = adjustContour(contour) {
selectEdge(0)
edge.replaceWith(cos(seconds) * 0.5 + 0.5)
}
drawer.stroke = ColorRGBa.RED
drawer.contour(contour)
fun main() = application {
configure {
width = 800
height = 800
}
program {
extend {
var contour = if (seconds.mod(2.0) < 1.0) {
drawer.bounds.scaledBy(0.5, 0.5, 0.5).contour
} else {
Circle(drawer.bounds.center, 300.0).contour
}
contour = adjustContour(contour) {
selectEdge(0)
edge.replaceWith(cos(seconds) * 0.5 + 0.5)
}
drawer.stroke = ColorRGBa.RED
drawer.contour(contour)
}
}
}
}

View File

@@ -6,31 +6,29 @@ import org.openrndr.extra.shapes.adjust.adjustContour
import org.openrndr.shape.Circle
import kotlin.math.cos
fun main() {
application {
configure {
width = 800
height = 800
}
program {
extend {
var contour =
Circle(drawer.bounds.center, 300.0).contour
fun main() = application {
configure {
width = 800
height = 800
}
program {
extend {
var contour =
Circle(drawer.bounds.center, 300.0).contour
contour = adjustContour(contour) {
selectEdges(0, 1, 2, 3)
edges.forEachIndexed { index, it ->
if (index == seconds.mod(4.0).toInt()) {
it.replaceWith(0.5)
} else {
val v = cos(seconds) * 0.15 + 0.25
it.sub(0.5 - v, 0.5 + v)
}
contour = adjustContour(contour) {
selectEdges(0, 1, 2, 3)
edges.forEachIndexed { index, it ->
if (index == seconds.mod(4.0).toInt()) {
it.replaceWith(0.5)
} else {
val v = cos(seconds) * 0.15 + 0.25
it.sub(0.5 - v, 0.5 + v)
}
}
drawer.stroke = ColorRGBa.RED
drawer.contour(contour)
}
drawer.stroke = ColorRGBa.RED
drawer.contour(contour)
}
}
}
}

View File

@@ -6,38 +6,36 @@ import org.openrndr.extra.shapes.adjust.adjustContour
import org.openrndr.shape.Circle
import kotlin.math.cos
fun main() {
application {
configure {
width = 800
height = 800
}
program {
extend {
var contour =
Circle(drawer.bounds.center, 300.0).contour
fun main() = application {
configure {
width = 800
height = 800
}
program {
extend {
var contour =
Circle(drawer.bounds.center, 300.0).contour
contour = adjustContour(contour) {
parameters.clearSelectedVertices = true
parameters.selectInsertedVertices = true
contour = adjustContour(contour) {
parameters.clearSelectedVertices = true
parameters.selectInsertedVertices = true
for (i in 0 until 4) {
val splitT = cos(seconds + i * Math.PI*0.5)*0.2+0.5
selectEdges { it -> true }
for (e in edges) {
e.splitAt(splitT)
}
// as a resut of the clearSelectedVertices and selectInsertedVertices settings
// the vertex selection is set to the newly inserted vertices
for ((index, v) in vertices.withIndex()) {
v.scale(cos(seconds + i + index) * 0.5 * (1.0 / (1.0 + i)) + 1.0, drawer.bounds.center)
}
for (i in 0 until 4) {
val splitT = cos(seconds + i * Math.PI * 0.5) * 0.2 + 0.5
selectEdges { it -> true }
for (e in edges) {
e.splitAt(splitT)
}
// as a resut of the clearSelectedVertices and selectInsertedVertices settings
// the vertex selection is set to the newly inserted vertices
for ((index, v) in vertices.withIndex()) {
v.scale(cos(seconds + i + index) * 0.5 * (1.0 / (1.0 + i)) + 1.0, drawer.bounds.center)
}
}
drawer.stroke = ColorRGBa.RED
drawer.contour(contour)
}
drawer.stroke = ColorRGBa.RED
drawer.contour(contour)
}
}
}
}

View File

@@ -7,36 +7,34 @@ import org.openrndr.math.Vector2
import org.openrndr.shape.contour
import kotlin.math.cos
fun main() {
application {
configure {
width = 800
height = 800
}
program {
extend {
var contour = contour {
moveTo(drawer.bounds.center - Vector2(300.0, 0.0))
lineTo(drawer.bounds.center + Vector2(300.0, 0.0))
}
contour = adjustContour(contour) {
selectEdge(0)
edge.splitIn(128)
val tr = cos(seconds) * 0.5 + 0.5
selectVertices { i, v -> v.t >= tr }
val anchor = contour.position(tr)
for (v in vertices) {
v.rotate((v.t - tr) * 2000.0, anchor)
v.scale(0.05, anchor)
}
}
drawer.stroke = ColorRGBa.RED
drawer.contour(contour)
fun main() = application {
configure {
width = 800
height = 800
}
program {
extend {
var contour = contour {
moveTo(drawer.bounds.center - Vector2(300.0, 0.0))
lineTo(drawer.bounds.center + Vector2(300.0, 0.0))
}
contour = adjustContour(contour) {
selectEdge(0)
edge.splitIn(128)
val tr = cos(seconds) * 0.5 + 0.5
selectVertices { i, v -> v.t >= tr }
val anchor = contour.position(tr)
for (v in vertices) {
v.rotate((v.t - tr) * 2000.0, anchor)
v.scale(0.05, anchor)
}
}
drawer.stroke = ColorRGBa.RED
drawer.contour(contour)
}
}
}
}

View File

@@ -1,4 +1,4 @@
//package adjust
package adjust
import org.openrndr.application
import org.openrndr.color.ColorRGBa
@@ -6,46 +6,44 @@ import org.openrndr.extra.shapes.adjust.adjustContour
import org.openrndr.math.Vector2
import org.openrndr.shape.contour
fun main() {
application {
configure {
width = 800
height = 800
}
program {
extend {
var contour = contour {
moveTo(drawer.bounds.position(0.5, 0.1) - Vector2(300.0, 0.0))
lineTo(drawer.bounds.position(0.5, 0.1) + Vector2(300.0, 0.0))
}
fun main() = application {
configure {
width = 800
height = 800
}
program {
extend {
var contour = contour {
moveTo(drawer.bounds.position(0.5, 0.1) - Vector2(300.0, 0.0))
lineTo(drawer.bounds.position(0.5, 0.1) + Vector2(300.0, 0.0))
}
contour = adjustContour(contour) {
selectVertex(0)
vertex.moveControlOutBy(Vector2(0.0, 100.0))
contour = adjustContour(contour) {
selectVertex(0)
vertex.moveControlOutBy(Vector2(0.0, 100.0))
selectVertex(1)
vertex.moveControlInBy(Vector2(0.0, -100.0))
}
drawer.stroke = ColorRGBa.RED
drawer.contour(contour)
contour = contour {
moveTo(drawer.bounds.position(0.5, 0.2) - Vector2(300.0, 0.0))
lineTo(drawer.bounds.position(0.5, 0.2) + Vector2(300.0, 0.0))
}
contour = adjustContour(contour) {
selectEdge(0)
edge.moveControl0By(Vector2(0.0, 100.0))
edge.moveControl1By(Vector2(0.0, -100.0))
}
drawer.stroke = ColorRGBa.RED
drawer.contour(contour)
selectVertex(1)
vertex.moveControlInBy(Vector2(0.0, -100.0))
}
drawer.stroke = ColorRGBa.RED
drawer.contour(contour)
contour = contour {
moveTo(drawer.bounds.position(0.5, 0.2) - Vector2(300.0, 0.0))
lineTo(drawer.bounds.position(0.5, 0.2) + Vector2(300.0, 0.0))
}
contour = adjustContour(contour) {
selectEdge(0)
edge.moveControl0By(Vector2(0.0, 100.0))
edge.moveControl1By(Vector2(0.0, -100.0))
}
drawer.stroke = ColorRGBa.RED
drawer.contour(contour)
}
}
}
}

View File

@@ -9,52 +9,50 @@ import org.openrndr.extra.shapes.tunni.tunniLine
import org.openrndr.extra.shapes.tunni.tunniPoint
import kotlin.math.sqrt
fun main() {
application {
configure {
width = 800
height = 800
}
program {
extend {
drawer.clear(ColorRGBa.WHITE)
var contour = drawer.bounds.offsetEdges(-200.0).contour
fun main() = application {
configure {
width = 800
height = 800
}
program {
extend {
drawer.clear(ColorRGBa.WHITE)
var contour = drawer.bounds.offsetEdges(-200.0).contour
drawer.fill = null
drawer.fill = null
contour = adjustContour(contour) {
selectVertices(0, 1)
for (v in vertices) {
v.averageTangents()
v.scale(sqrt(2.0))
v.rotate(45.0)
}
selectVertices(2)
for (v in vertices) {
v.switchTangents()
}
contour = adjustContour(contour) {
selectVertices(0, 1)
for (v in vertices) {
v.averageTangents()
v.scale(sqrt(2.0))
v.rotate(45.0)
}
drawer.stroke = ColorRGBa.BLACK
drawer.contour(contour)
drawer.stroke = ColorRGBa.RED
for (s in contour.segments) {
drawer.lineSegment(s.start, s.cubic.control[0])
drawer.lineSegment(s.end, s.cubic.control[1])
selectVertices(2)
for (v in vertices) {
v.switchTangents()
}
drawer.fill = ColorRGBa.BLACK
drawer.stroke = null
drawer.circles(contour.segments.map { it.start }, 5.0)
}
drawer.stroke = ColorRGBa.BLACK
drawer.contour(contour)
drawer.stroke = ColorRGBa.GRAY
for (s in contour.segments) {
drawer.lineSegment(s.tunniLine)
drawer.fill = ColorRGBa.CYAN
drawer.circle(s.tunniPoint, 5.0)
}
drawer.stroke = ColorRGBa.RED
for (s in contour.segments) {
drawer.lineSegment(s.start, s.cubic.control[0])
drawer.lineSegment(s.end, s.cubic.control[1])
}
drawer.fill = ColorRGBa.BLACK
drawer.stroke = null
drawer.circles(contour.segments.map { it.start }, 5.0)
drawer.stroke = ColorRGBa.GRAY
for (s in contour.segments) {
drawer.lineSegment(s.tunniLine)
drawer.fill = ColorRGBa.CYAN
drawer.circle(s.tunniPoint, 5.0)
}
}
}
}
}

View File

@@ -12,91 +12,89 @@ import org.openrndr.math.Vector2
import org.openrndr.shape.Segment2D
import kotlin.math.cos
fun main() {
application {
configure {
width = 800
height = 800
}
program {
fun main() = application {
configure {
width = 800
height = 800
}
program {
var res = drawer.bounds.offsetEdges(-200.0).contour
var selectedSegments = emptyList<Segment2D>()
var selectedPoints = emptyList<Vector2>()
var res = drawer.bounds.offsetEdges(-200.0).contour
var selectedSegments = emptyList<Segment2D>()
var selectedPoints = emptyList<Vector2>()
val contourSeq = adjustContourSequence(res) {
val contourSeq = adjustContourSequence(res) {
sequence {
for (i in 0 until 1000) {
selectEdges()
selectVertices((i*7).mod(4))
for (v in vertices) {
for (j in 0 until 30) {
v.rotate(45.0/30.0)
yield(status)
}
}
selectVertices((i*3).mod(4))
for (v in vertices) {
yield(status)
}
selectVertices()
selectEdges(i.mod(4))
sequence {
for (i in 0 until 1000) {
selectEdges()
selectVertices((i * 7).mod(4))
for (v in vertices) {
for (j in 0 until 30) {
for (e in edges) {
e.withTunniLine(e.tunniLine.position(0.5) + e.tunniLine.normal * cos(i.toDouble() + e.segmentIndex()) * 50.0/30.0)
yield(status)
}
v.rotate(45.0 / 30.0)
yield(status)
}
}
selectVertices((i * 3).mod(4))
for (v in vertices) {
yield(status)
}
selectVertices()
selectEdges(i.mod(4))
for (j in 0 until 30) {
for (e in edges) {
e.withTunniLine(e.tunniLine.position(0.5) + e.tunniLine.normal * cos(i.toDouble() + e.segmentIndex()) * 50.0 / 30.0)
yield(status)
}
}
}
}
}
launch {
for (i in contourSeq) {
res = i.contour
selectedPoints = i.selectedPoints
selectedSegments = i.selectedSegments
yield()
}
launch {
for (i in contourSeq) {
res = i.contour
selectedPoints = i.selectedPoints
selectedSegments = i.selectedSegments
yield()
}
}
extend {
drawer.clear(ColorRGBa.WHITE)
drawer.stroke = ColorRGBa.BLACK
drawer.contour(res)
drawer.stroke = ColorRGBa.RED
for (s in res.segments) {
drawer.lineSegment(s.start, s.cubic.control[0])
drawer.lineSegment(s.end, s.cubic.control[1])
}
drawer.fill = ColorRGBa.BLACK
drawer.stroke = null
drawer.circles(res.segments.map { it.start }, 5.0)
drawer.stroke = ColorRGBa.GRAY
for (s in res.segments) {
drawer.lineSegment(s.tunniLine)
drawer.fill = ColorRGBa.CYAN
drawer.circle(s.tunniPoint, 5.0)
}
extend {
drawer.clear(ColorRGBa.WHITE)
drawer.stroke = ColorRGBa.BLACK
drawer.contour(res)
drawer.stroke = ColorRGBa.RED
for (s in res.segments) {
drawer.lineSegment(s.start, s.cubic.control[0])
drawer.lineSegment(s.end, s.cubic.control[1])
}
drawer.fill = ColorRGBa.BLACK
drawer.stroke = null
drawer.circles(res.segments.map { it.start }, 5.0)
drawer.stroke = ColorRGBa.GRAY
for (s in res.segments) {
drawer.lineSegment(s.tunniLine)
drawer.fill = ColorRGBa.CYAN
drawer.circle(s.tunniPoint, 5.0)
}
drawer.stroke = ColorRGBa.MAGENTA
drawer.strokeWeight = 3.0
for (s in selectedSegments) {
drawer.segment(s)
}
for (p in selectedPoints) {
drawer.circle(p, 5.0)
}
drawer.stroke = ColorRGBa.MAGENTA
drawer.strokeWeight = 3.0
for (s in selectedSegments) {
drawer.segment(s)
}
for (p in selectedPoints) {
drawer.circle(p, 5.0)
}
}
}
}
}