Add orx-shapes

This commit is contained in:
Edwin Jakobs
2020-03-09 12:47:00 +01:00
parent fee87d5e53
commit 639b9ac911
2 changed files with 37 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
import org.openrndr.math.Vector2
import org.openrndr.shape.contour
import kotlin.math.min
class RoundedRectangle(val corner: Vector2, val width: Double, val height: Double, val radius: Double) {
constructor(x: Double, y: Double, width: Double, height: Double, radius: Double) : this(Vector2(x, y), width, height, radius)
/** the center of the rounded rectangle */
val center: Vector2
get() = corner + Vector2(width / 2, height / 2)
val x: Double get() = corner.x
val y: Double get() = corner.y
/** [ShapeContour] representation of the rounded rectangle */
val contour
get() = contour {
// A higher radius than half the width/height makes it go weird
val r = min(min(radius, width / 2), height / 2)
moveTo(x + r, y)
lineTo(x + width - r, y)
curveTo(Vector2(x + width, y), Vector2(x + width, y + r))
lineTo(x + width, y + height - r)
curveTo(Vector2(x + width, y + height), Vector2(x + width - r, y + height))
lineTo(x + r, y + height)
curveTo(Vector2(x, y + height), Vector2(x, y + height - r))
lineTo(x, y + r)
curveTo(Vector2(x, y), Vector2(x + r, y))
close()
}
}

View File

@@ -27,6 +27,7 @@ include 'orx-camera',
'orx-runway', 'orx-runway',
'orx-shader-phrases', 'orx-shader-phrases',
'orx-shade-styles', 'orx-shade-styles',
'orx-shapes',
'orx-syphon', 'orx-syphon',
'orx-temporal-blur', 'orx-temporal-blur',
'orx-kinect-common', 'orx-kinect-common',