[orx-shapes] Refactor package layout

This commit is contained in:
Edwin Jakobs
2024-01-23 09:38:43 +01:00
parent 78ba51ca85
commit 8fbb106823
54 changed files with 138 additions and 91 deletions

View File

@@ -0,0 +1,24 @@
package primitives
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.shapes.primitives.Arc
fun main() {
application {
configure {
width = 720
height = 720
}
program {
extend {
val a = Arc(drawer.bounds.center, 100.0, 0.0 + seconds * 36.0, -180.0 + seconds * 36.0)
drawer.clear(ColorRGBa.PINK)
drawer.contour(a.contour)
drawer.circle(a.position(0.0), 5.0)
drawer.circle(a.position(0.5), 5.0)
drawer.circle(a.position(1.0), 5.0)
}
}
}
}

View File

@@ -0,0 +1,34 @@
package primitives
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.shapes.primitives.Net
import org.openrndr.shape.Circle
import kotlin.math.sin
fun main() {
application {
program {
extend {
drawer.clear(ColorRGBa.BLACK)
drawer.stroke = ColorRGBa.WHITE
drawer.fill = ColorRGBa.PINK
val a = drawer.bounds.position(0.7, 0.5)
val b = drawer.bounds.position(0.3, 0.5)
val c = Circle(
drawer.bounds.position(
sin(seconds) * 0.35 + 0.5,
sin(seconds * 2) * 0.25 + 0.5
), 50.0
)
val net = Net(a, b, c)
drawer.circle(a, 10.0)
drawer.circle(b, 10.0)
drawer.circle(c)
drawer.strokeWeight = 2.0
drawer.contour(net.contour)
}
}
}
}

View File

@@ -0,0 +1,28 @@
package primitives
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.shapes.primitives.Pulley
import org.openrndr.math.Vector2
import org.openrndr.shape.Circle
fun main() {
application {
configure {
width = 720
height = 720
}
program {
extend {
drawer.clear(ColorRGBa.BLACK)
drawer.stroke = ColorRGBa.WHITE
drawer.fill = ColorRGBa.PINK
val pulley = Pulley(
Circle(drawer.bounds.center - Vector2(100.0, 100.0), 150.0),
Circle(drawer.bounds.center + Vector2(150.0, 150.0), 75.0)
)
drawer.contour(pulley.contour)
}
}
}
}

View File

@@ -0,0 +1,28 @@
package primitives
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.shapes.primitives.grid
fun main() {
application {
configure {
width = 800
height = 800
}
program {
extend {
drawer.fill = ColorRGBa.WHITE.opacify(0.25)
drawer.stroke = ColorRGBa.PINK
// Notice the negative gutter in this grid. It creates an
// overlap between the resulting rectangles.
val grid = drawer.bounds.grid(8, 4, 20.0, 20.0, -20.0, -20.0)
for (cell in grid.flatten()) {
drawer.rectangle(cell)
drawer.lineSegment(cell.position(0.0, 0.0), cell.position(1.0, 1.0))
}
}
}
}
}

View File

@@ -0,0 +1,39 @@
package primitives
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.noise.Random
import org.openrndr.extra.shapes.primitives.grid
fun main() {
application {
// Try changing the resolution. The design will use the available space.
configure {
width = 800
height = 400
}
program {
// By specifying the cell size we make sure the design will
// contain squares, independently of the window size and its
// aspect ratio.
val grid = drawer.bounds.grid(50.0, 50.0,
20.0, 20.0, 20.0, 20.0).flatten()
val grid2 = grid.map { rect ->
// Each of these inner grids will occupy the available space
// in the parent grid cells. Notice how we don't specify cell
// sizes here but counts instead (between 1 and 3 columns and
// rows)
val count = Random.int(1, 4)
rect.grid(count, count, 5.0, 5.0, 5.0, 5.0).flatten()
}.flatten().filter { Random.bool(0.5)}
extend {
drawer.clear(ColorRGBa.PINK)
drawer.rectangles(grid)
drawer.fill = ColorRGBa.BLACK
drawer.rectangles(grid2)
}
}
}
}

View File

@@ -0,0 +1,32 @@
package primitives
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.isolated
import org.openrndr.extra.shapes.primitives.regularPolygon
import org.openrndr.math.map
import kotlin.math.cos
fun main() = application {
program {
extend {
drawer.fill = ColorRGBa.PINK
drawer.stroke = ColorRGBa.WHITE
for (sides in 0 until 8) {
val radius0 = cos(seconds + sides) * 20.0 + 40.0
val star = regularPolygon(sides + 3, radius = radius0)
drawer.isolated {
translate(
(sides % 4.0).map(0.0, 3.0,
width * 0.2, width * 0.8),
(sides / 4).toDouble().map(0.0, 1.0,
height * 0.3, height * 0.7))
rotate(seconds * 45.0)
contour(star)
}
}
}
}
}

View File

@@ -0,0 +1,24 @@
package primitives
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.shapes.primitives.regularStar
import kotlin.math.cos
import kotlin.math.sin
fun main() = application {
program {
extend {
drawer.fill = ColorRGBa.PINK
drawer.stroke = ColorRGBa.WHITE
val radius0 = cos(seconds + 2) * 50.0 + 130.0
val radius1 = sin(seconds + 2) * 50.0 + 130.0
val star = regularStar(5, radius0, radius1)
drawer.translate(width / 2.0, height / 2.0)
drawer.rotate(seconds * 45.0)
drawer.contour(star)
}
}
}

View File

@@ -0,0 +1,40 @@
package primitives
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.shapes.primitives.regularStar
import org.openrndr.math.Vector2
import org.openrndr.shape.contains
import kotlin.math.cos
import kotlin.math.sin
fun main() = application {
program {
extend {
drawer.fill = ColorRGBa.PINK
drawer.stroke = ColorRGBa.WHITE
val radius0 = cos(seconds) * 50.0 + 130.0
val radius1 = sin(seconds * 2.0) * 50.0 + 130.0
val star = regularStar(12, radius0, radius1)
drawer.translate(width / 2.0, height / 2.0)
drawer.rotate(seconds * 45.0)
drawer.fill = null
drawer.strokeWeight = 2.0
drawer.contour(star)
drawer.strokeWeight = 1.0
drawer.fill = ColorRGBa.WHITE
for (j in -20 until 20) {
for (i in -20 until 20) {
val q = Vector2(i * 10.0, j * 10.0)
if (q in star) {
drawer.circle(i * 10.0, j * 10.0, 5.0)
}
}
}
}
}
}

View File

@@ -0,0 +1,18 @@
package primitives
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.shapes.primitives.RoundedRectangle
import kotlin.math.cos
fun main() = application {
program {
extend {
drawer.fill = ColorRGBa.WHITE
drawer.stroke = ColorRGBa.PINK
val radius = cos(seconds) * 20.0 + 20.0
val rectangle = RoundedRectangle(50.0, 50.0, width - 100.0, height - 100.0, radius)
drawer.contour(rectangle.contour)
}
}
}

View File

@@ -0,0 +1,30 @@
package primitives
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.color.presets.MEDIUM_PURPLE
import org.openrndr.extra.shapes.utilities.splitAt
import org.openrndr.shape.Circle
fun main() = application {
configure {
width = 800
height = 800
}
program {
val c = Circle(drawer.bounds.center, 300.0).contour
val cs = c.splitAt(listOf(1.0/3.0, 2.0/3.0))
extend {
drawer.strokeWeight = 5.0
drawer.stroke = ColorRGBa.PINK
drawer.contour(cs[0])
drawer.stroke = ColorRGBa.MEDIUM_PURPLE
drawer.contour(cs[1])
drawer.stroke = ColorRGBa.RED
drawer.contour(cs[2])
}
}
}

View File

@@ -0,0 +1,31 @@
package primitives
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.noise.scatter
import org.openrndr.extra.shapes.primitives.Tear
import org.openrndr.math.Vector2
import org.openrndr.shape.Circle
import kotlin.random.Random
fun main() {
application {
configure {
width = 720
height = 720
}
program {
val points = drawer.bounds.scatter(40.0, distanceToEdge = 150.0, random = Random(0))
val tears = points.map {
Tear(it - Vector2(0.0, 20.0), Circle(it + Vector2(0.0, 20.0), 20.0))
}
extend {
drawer.clear(ColorRGBa.BLACK)
drawer.fill = ColorRGBa.PINK
drawer.stroke = ColorRGBa.WHITE
drawer.contours(tears.map { it.contour })
}
}
}
}