Bump to OPENRNDR 0.3.44-rc.7, add intersection demos

This commit is contained in:
Edwin Jakobs
2020-07-29 12:01:23 +02:00
parent dd9a0b351a
commit 6060ebffcd
4 changed files with 111 additions and 1 deletions

View File

@@ -16,7 +16,7 @@ buildscript {
apply plugin: 'org.jetbrains.dokka'
project.ext {
openrndrVersion = openrndrUseSnapshot? "0.4.0-SNAPSHOT" : "0.3.44-rc.6"
openrndrVersion = openrndrUseSnapshot? "0.4.0-SNAPSHOT" : "0.3.44-rc.7"
kotlinVersion = "1.3.72"
spekVersion = "2.0.11"
libfreenectVersion = "0.5.7-1.5.3"

View 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)
}
}
}
}
}

View 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))
}
}
}
}
}
}
}
}
}

View 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)
}
}
}
}