Bump to OPENRNDR 0.3.44-rc.7, add intersection demos
This commit is contained in:
37
openrndr-demos/src/demo/kotlin/DemoContourIntersections01.kt
Normal file
37
openrndr-demos/src/demo/kotlin/DemoContourIntersections01.kt
Normal file
@@ -0,0 +1,37 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.shape.Ellipse
|
||||
import org.openrndr.shape.OrientedEllipse
|
||||
import org.openrndr.shape.intersections
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
val c1 = Ellipse(width / 2.0, height / 2.0, 200.0, 100.0).contour
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.PINK)
|
||||
drawer.fill = null
|
||||
val c2 = OrientedEllipse(mouse.position, 100.0, 200.0, seconds*45.0).contour
|
||||
drawer.contour(c1)
|
||||
//drawer.contour(c2)
|
||||
val ints = intersections(c1, c2)
|
||||
|
||||
if (ints.isEmpty()) {
|
||||
drawer.contour(c2)
|
||||
} else {
|
||||
(ints + ints.take(1)).map { it.contourTB }.zipWithNext().forEach {
|
||||
val end = if (it.second <= it.first) it.second + 1.0 else it.second
|
||||
val sub = c2.sub(it.first, end)
|
||||
val l = sub.length
|
||||
val ta = sub.tForLength(15.0)
|
||||
val tb = sub.tForLength(l - 15.0)
|
||||
drawer.contour(sub.sub(ta, tb))
|
||||
}
|
||||
}
|
||||
for (i in ints) {
|
||||
drawer.circle(i.position, 15.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
41
openrndr-demos/src/demo/kotlin/DemoContourIntersections02.kt
Normal file
41
openrndr-demos/src/demo/kotlin/DemoContourIntersections02.kt
Normal file
@@ -0,0 +1,41 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.shape.Circle
|
||||
import org.openrndr.shape.Rectangle
|
||||
import org.openrndr.shape.intersections
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
extend {
|
||||
val circle = Circle(mouse.position, 200.0).contour
|
||||
|
||||
drawer.fill = null
|
||||
drawer.stroke = ColorRGBa.GREEN
|
||||
for (y in 50 until height step 100) {
|
||||
for (x in 50 until width step 100) {
|
||||
|
||||
for (ring in 0 until 10) {
|
||||
val r = Rectangle.fromCenter(Vector2(x * 1.0, y * 1.0), 90.0 - ring * 8.0, 90.0 - ring * 8.0).contour
|
||||
|
||||
val ints = intersections(circle, r)
|
||||
if (ints.isEmpty()) {
|
||||
drawer.contour(r)
|
||||
} else {
|
||||
ints.map { it.contourTB }.let { it + it.take(1) }.zipWithNext().forEach {
|
||||
val end = if (it.second <= it.first) it.second + 1.0 else it.second
|
||||
val sub = r.sub(it.first, end)
|
||||
val length = sub.length
|
||||
val ta = sub.tForLength(2.0)
|
||||
val tb = sub.tForLength(length - 2.0)
|
||||
drawer.contour(sub.sub(ta, tb))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
32
openrndr-demos/src/demo/kotlin/DemoContourIntersections03.kt
Normal file
32
openrndr-demos/src/demo/kotlin/DemoContourIntersections03.kt
Normal file
@@ -0,0 +1,32 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.shape.ShapeContour
|
||||
import org.openrndr.shape.intersections
|
||||
import kotlin.math.PI
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.sin
|
||||
|
||||
fun main() = application {
|
||||
program {
|
||||
val contour = ShapeContour.fromPoints(
|
||||
List(80) {
|
||||
val a = PI * 2 * it / 80.0
|
||||
val x = 200.0 * sin(a * 2)
|
||||
val y = 200.0 * cos(a)
|
||||
Vector2(x, y)
|
||||
}, closed = true
|
||||
)
|
||||
val ints = intersections(contour, contour)
|
||||
extend {
|
||||
drawer.run {
|
||||
clear(ColorRGBa.WHITE)
|
||||
translate(width * 0.5, height * 0.5)
|
||||
fill = null
|
||||
stroke = ColorRGBa.BLACK
|
||||
contour(contour)
|
||||
circles(ints.map { it.position }, 10.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user