diff --git a/build.gradle b/build.gradle index a91fbf8e..d2efe4aa 100644 --- a/build.gradle +++ b/build.gradle @@ -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" diff --git a/openrndr-demos/src/demo/kotlin/DemoContourIntersections01.kt b/openrndr-demos/src/demo/kotlin/DemoContourIntersections01.kt new file mode 100644 index 00000000..ff081726 --- /dev/null +++ b/openrndr-demos/src/demo/kotlin/DemoContourIntersections01.kt @@ -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) + } + } + } + } +} \ No newline at end of file diff --git a/openrndr-demos/src/demo/kotlin/DemoContourIntersections02.kt b/openrndr-demos/src/demo/kotlin/DemoContourIntersections02.kt new file mode 100644 index 00000000..adea09c0 --- /dev/null +++ b/openrndr-demos/src/demo/kotlin/DemoContourIntersections02.kt @@ -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)) + } + } + } + } + } + } + } + } +} \ No newline at end of file diff --git a/openrndr-demos/src/demo/kotlin/DemoContourIntersections03.kt b/openrndr-demos/src/demo/kotlin/DemoContourIntersections03.kt new file mode 100644 index 00000000..6d0529fd --- /dev/null +++ b/openrndr-demos/src/demo/kotlin/DemoContourIntersections03.kt @@ -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) + } + } + } +} \ No newline at end of file