[openrndr-demos] Add rectangle batch demos
This commit is contained in:
@@ -1,36 +1,36 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.shape.CompositionDrawer
|
||||
import org.openrndr.shape.drawComposition
|
||||
import org.openrndr.svg.svgNamespaceInkscape
|
||||
import org.openrndr.svg.toSVG
|
||||
import org.openrndr.svg.writeSVG
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
|
||||
extend {
|
||||
|
||||
drawer.clear(ColorRGBa.WHITE)
|
||||
|
||||
val cd = CompositionDrawer()
|
||||
val layer = cd.group {
|
||||
fill = ColorRGBa.PINK
|
||||
stroke = ColorRGBa.BLACK
|
||||
strokeWeight = 10.0
|
||||
circle(Vector2(width/2.0, height/2.0), 100.0)
|
||||
circle(Vector2(200.0, 200.0), 50.0)
|
||||
val composition = drawComposition {
|
||||
val layer = group {
|
||||
fill = ColorRGBa.PINK
|
||||
stroke = ColorRGBa.BLACK
|
||||
strokeWeight = 10.0
|
||||
circle(Vector2(width / 2.0, height / 2.0), 100.0)
|
||||
circle(Vector2(200.0, 200.0), 50.0)
|
||||
}
|
||||
// demonstrating how to set custom attributes on the CompositionNode
|
||||
// these are stored in SVG
|
||||
layer.id = "Layer_2"
|
||||
layer.attributes["inkscape:label"] = "Layer 1"
|
||||
layer.attributes["inkscape:groupmode"] = "layer"
|
||||
}
|
||||
// demonstrating how to set custom attributes on the CompositionNode
|
||||
// these are stored in SVG
|
||||
layer.id = "Layer_2"
|
||||
layer.attributes["openrndr:custom"] = "5"
|
||||
|
||||
// draw the composition to the screen
|
||||
drawer.composition(cd.composition)
|
||||
drawer.composition(composition)
|
||||
|
||||
// print the svg to the console
|
||||
println(writeSVG(cd.composition))
|
||||
|
||||
println(composition.toSVG(namespaces = listOf(svgNamespaceInkscape)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,14 +3,8 @@ import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.*
|
||||
import org.openrndr.extensions.Screenshots
|
||||
|
||||
|
||||
fun main() = application {
|
||||
program {
|
||||
|
||||
val screenshots = extend(Screenshots()) {
|
||||
|
||||
}
|
||||
|
||||
val volumeTexture = VolumeTexture.create(128,128,32)
|
||||
val rt = renderTarget(128, 128) {
|
||||
volumeTexture(volumeTexture, 0)
|
||||
@@ -18,9 +12,6 @@ fun main() = application {
|
||||
|
||||
val cb = colorBuffer(128, 128)
|
||||
extend {
|
||||
|
||||
screenshots.afterScreenshot
|
||||
|
||||
drawer.isolatedWithTarget(rt) {
|
||||
drawer.ortho(rt)
|
||||
drawer.clear(ColorRGBa.PINK)
|
||||
@@ -28,6 +19,5 @@ fun main() = application {
|
||||
volumeTexture.copyTo(cb, 0)
|
||||
drawer.image(cb)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
16
openrndr-demos/src/demo/kotlin/DrawerRectangleBatch01.kt
Normal file
16
openrndr-demos/src/demo/kotlin/DrawerRectangleBatch01.kt
Normal file
@@ -0,0 +1,16 @@
|
||||
// A single rectangle
|
||||
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
|
||||
fun main() = application {
|
||||
program {
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.GRAY)
|
||||
drawer.fill = ColorRGBa.PINK
|
||||
drawer.stroke = ColorRGBa.WHITE
|
||||
drawer.strokeWeight = 2.0
|
||||
drawer.rectangle(100.0, 100.0, 50.0, 50.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
29
openrndr-demos/src/demo/kotlin/DrawerRectangleBatch02.kt
Normal file
29
openrndr-demos/src/demo/kotlin/DrawerRectangleBatch02.kt
Normal file
@@ -0,0 +1,29 @@
|
||||
// Stored rectangle batches
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.rectangleBatch
|
||||
|
||||
fun main() = application {
|
||||
program {
|
||||
val batch = drawer.rectangleBatch {
|
||||
fill = ColorRGBa.PINK
|
||||
stroke = ColorRGBa.WHITE
|
||||
for (i in 0 until 1000) {
|
||||
strokeWeight = Math.random() * 5.0 + 1.0
|
||||
val rwidth = Math.random() * 40.0 + 4.0
|
||||
val rheight = Math.random() * 40.0 + 4.0
|
||||
val x = Math.random() * width
|
||||
val y = Math.random() * height
|
||||
rectangle(x, y, rwidth, rheight, Math.random() * 360.0)
|
||||
}
|
||||
}
|
||||
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.GRAY)
|
||||
drawer.fill = ColorRGBa.PINK
|
||||
drawer.stroke = ColorRGBa.WHITE
|
||||
drawer.strokeWeight = 2.0
|
||||
drawer.rectangles(batch)
|
||||
}
|
||||
}
|
||||
}
|
||||
23
openrndr-demos/src/demo/kotlin/DrawerRectangleBatch03.kt
Normal file
23
openrndr-demos/src/demo/kotlin/DrawerRectangleBatch03.kt
Normal file
@@ -0,0 +1,23 @@
|
||||
// Dynamic rectangle batches
|
||||
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
|
||||
fun main() = application {
|
||||
program {
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.GRAY)
|
||||
drawer.fill = ColorRGBa.PINK
|
||||
drawer.stroke = ColorRGBa.WHITE
|
||||
drawer.strokeWeight = 2.0
|
||||
drawer.rectangles {
|
||||
for (y in 0 until height/20) {
|
||||
for (x in 0 until width/20) {
|
||||
rectangle(x * 20.0, y * 20.0, 10.0, 15.0, (x + y) * 10.0 + seconds*90.0)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user