Skip to content

Commit

Permalink
[openrndr-demos] Add rectangle batch demos
Browse files Browse the repository at this point in the history
  • Loading branch information
edwinRNDR committed Jul 21, 2020
1 parent b4908b3 commit c6a883f
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 29 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ buildscript {
apply plugin: 'org.jetbrains.dokka'

project.ext {
openrndrVersion = openrndrUseSnapshot? "0.4.0-SNAPSHOT" : "0.3.44-rc.4"
openrndrVersion = openrndrUseSnapshot? "0.4.0-SNAPSHOT" : "0.3.44-rc.5"
kotlinVersion = "1.3.72"
spekVersion = "2.0.11"
libfreenectVersion = "0.5.7-1.5.3"
Expand Down
36 changes: 18 additions & 18 deletions openrndr-demos/src/demo/kotlin/DemoCompositionDrawer01.kt
Original file line number Diff line number Diff line change
@@ -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)))
}
}
}
Expand Down
10 changes: 0 additions & 10 deletions openrndr-demos/src/demo/kotlin/DemoVolumeTexture01.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,21 @@ 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)
}

val cb = colorBuffer(128, 128)
extend {

screenshots.afterScreenshot

drawer.isolatedWithTarget(rt) {
drawer.ortho(rt)
drawer.clear(ColorRGBa.PINK)
}
volumeTexture.copyTo(cb, 0)
drawer.image(cb)
}

}
}
16 changes: 16 additions & 0 deletions openrndr-demos/src/demo/kotlin/DrawerRectangleBatch01.kt
Original file line number Diff line number Diff line change
@@ -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 changes: 29 additions & 0 deletions openrndr-demos/src/demo/kotlin/DrawerRectangleBatch02.kt
Original file line number Diff line number Diff line change
@@ -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 changes: 23 additions & 0 deletions openrndr-demos/src/demo/kotlin/DrawerRectangleBatch03.kt
Original file line number Diff line number Diff line change
@@ -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)

}
}
}
}
}
}

0 comments on commit c6a883f

Please sign in to comment.