Skip to content

Commit

Permalink
Demos: ensure all use fun main() = application {
Browse files Browse the repository at this point in the history
- Adjust some demo window sizes.
- Replace Random.double by Double.uniform
- Tweak some demos so screenshots look more interesting
  • Loading branch information
hamoid committed Jan 26, 2025
1 parent 1975a82 commit c8f7dd5
Show file tree
Hide file tree
Showing 116 changed files with 2,862 additions and 2,915 deletions.
58 changes: 28 additions & 30 deletions openrndr-demos/src/demo/kotlin/DemoContour03.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,39 @@ import org.openrndr.draw.isolated
import org.openrndr.shape.Circle
import org.openrndr.shape.Rectangle

fun main() {
application {
configure {
width = 720
height = 720
}
fun main() = application {
configure {
width = 720
height = 720
}

program {
val cs = Rectangle(0.0, 0.0, 200.0, 200.0).contour
val cc = Circle(100.0, 0.0, 100.0).contour
program {
val cs = Rectangle(0.0, 0.0, 200.0, 200.0).contour
val cc = Circle(100.0, 0.0, 100.0).contour

extend {
drawer.fill = ColorRGBa.GRAY
drawer.stroke = ColorRGBa.PINK
drawer.isolated {
drawer.contour(cs)
drawer.translate(300.0, 0.0)
extend {
drawer.fill = ColorRGBa.GRAY
drawer.stroke = ColorRGBa.PINK
drawer.isolated {
drawer.contour(cs)
drawer.translate(300.0, 0.0)

// this should create a contour similar to the input contour
drawer.contour(cs.sampleEquidistant(4))
drawer.contour(cs.sampleEquidistant(3))
}
// this should create a contour similar to the input contour
drawer.contour(cs.sampleEquidistant(4))
drawer.contour(cs.sampleEquidistant(3))
}

drawer.isolated {
drawer.translate(.0, 400.0)
drawer.contour(cc)
drawer.translate(300.0, 0.0)
drawer.isolated {
drawer.translate(.0, 400.0)
drawer.contour(cc)
drawer.translate(300.0, 0.0)

drawer.contour(cc)
// this should draw a hexagon
drawer.contour(cc.sampleEquidistant(6))
// this should draw a triangle
drawer.contour(cc.sampleEquidistant(3))
}
drawer.contour(cc)
// this should draw a hexagon
drawer.contour(cc.sampleEquidistant(6))
// this should draw a triangle
drawer.contour(cc.sampleEquidistant(3))
}
}
}
}
}
60 changes: 29 additions & 31 deletions openrndr-demos/src/demo/kotlin/DemoLineCapJoin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,40 @@ import org.openrndr.shape.Triangle
* a 3x3 grid of triangles and lines.
*/

fun main() {
application {
configure {
width = 720
height = 720
}
fun main() = application {
configure {
width = 720
height = 720
}

program {
val font = loadFont("demo-data/fonts/IBMPlexMono-Regular.ttf", 20.0)
val pointA = Vector2(0.0, 50.0)
val pointB = Vector2(50.0, -20.0)
val pointC = Vector2(-50.0, 0.0)
val triangle = Triangle(pointA, pointB, pointC).contour
program {
val font = loadFont("demo-data/fonts/IBMPlexMono-Regular.ttf", 20.0)
val pointA = Vector2(0.0, 50.0)
val pointB = Vector2(50.0, -20.0)
val pointC = Vector2(-50.0, 0.0)
val triangle = Triangle(pointA, pointB, pointC).contour

extend {
drawer.apply {
fill = ColorRGBa.GRAY
stroke = ColorRGBa.PINK
strokeWeight = 8.0
fontMap = font
LineCap.entries.forEachIndexed { x, cap ->
lineCap = cap
LineJoin.entries.forEachIndexed { y, join ->
lineJoin = join
val pos = IntVector2(x - 1, y - 1).vector2 * 180.0
isolated {
translate(bounds.position(0.46, 0.46) + pos)
text("cap: ${cap.name}", -30.5, 80.5)
text("join: ${join.name}", -30.5, 100.5)
contour(triangle)
lineSegment(pointA - pointC, pointB - pointC)
}
extend {
drawer.apply {
fill = ColorRGBa.GRAY
stroke = ColorRGBa.PINK
strokeWeight = 8.0
fontMap = font
LineCap.entries.forEachIndexed { x, cap ->
lineCap = cap
LineJoin.entries.forEachIndexed { y, join ->
lineJoin = join
val pos = IntVector2(x - 1, y - 1).vector2 * 180.0
isolated {
translate(bounds.position(0.46, 0.46) + pos)
text("cap: ${cap.name}", -30.5, 80.5)
text("join: ${join.name}", -30.5, 100.5)
contour(triangle)
lineSegment(pointA - pointC, pointB - pointC)
}
}
}
}
}
}
}
}
52 changes: 24 additions & 28 deletions orx-composition/src/jvmDemo/kotlin/DemoCompositionDrawer01.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,37 @@ import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.composition.composition
import org.openrndr.extra.composition.drawComposition
import org.openrndr.extra.svg.saveToFile
import org.openrndr.extra.svg.toSVG
import org.openrndr.math.Vector2
import java.io.File

fun main() {
application {
program {
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"
fun main() = application {
program {
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"
}

// print the svg to the console
println(composition.toSVG())
// print the svg to the console
println(composition.toSVG())

// save svg to a File
//composition.saveToFile(File("/path/to/design.svg"))
// save svg to a File
//composition.saveToFile(File("/path/to/design.svg"))

extend {
drawer.clear(ColorRGBa.WHITE)
extend {
drawer.clear(ColorRGBa.WHITE)

// draw the composition to the screen
drawer.composition(composition)
}
// draw the composition to the screen
drawer.composition(composition)
}
}
}
}
28 changes: 13 additions & 15 deletions orx-composition/src/jvmDemo/kotlin/DemoCompositionDrawer02.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@ import org.openrndr.extra.composition.ClipMode
import org.openrndr.extra.composition.composition
import org.openrndr.extra.composition.drawComposition

fun main() {
application {
program {
val cd = drawComposition {
fill = null
circle(width / 2.0, height / 2.0, 100.0)
fun main() = application {
program {
val cd = drawComposition {
fill = null
circle(width / 2.0, height / 2.0, 100.0)

fill = ColorRGBa.BLACK
clipMode = ClipMode.REVERSE_DIFFERENCE
circle(width / 2.0 + 50.0, height / 2.0, 100.0)
}
fill = ColorRGBa.BLACK
clipMode = ClipMode.REVERSE_DIFFERENCE
circle(width / 2.0 + 50.0, height / 2.0, 100.0)
}


extend {
drawer.clear(ColorRGBa.PINK)
drawer.composition(cd)
}
extend {
drawer.clear(ColorRGBa.PINK)
drawer.composition(cd)
}
}
}
}
31 changes: 14 additions & 17 deletions orx-composition/src/jvmDemo/kotlin/DemoCompositionDrawer03.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,22 @@ import org.openrndr.extra.composition.ClipMode
import org.openrndr.extra.composition.composition
import org.openrndr.extra.composition.drawComposition

fun main() {
application {
program {
val cd = drawComposition {
fill = null
clipMode = ClipMode.REVERSE_DIFFERENCE
fun main() = application {
program {
val cd = drawComposition {
fill = null
clipMode = ClipMode.REVERSE_DIFFERENCE

circle(width / 2.0-50.0, height / 2.0, 100.0)
circle(width / 2.0+50.0, height / 2.0, 100.0)

fill = ColorRGBa.BLACK
circle(width / 2.0, height / 2.0, 100.0)
}
circle(width / 2.0 - 50.0, height / 2.0, 100.0)
circle(width / 2.0 + 50.0, height / 2.0, 100.0)

fill = ColorRGBa.BLACK
circle(width / 2.0, height / 2.0, 100.0)
}

extend {
drawer.clear(ColorRGBa.PINK)
drawer.composition(cd)
}
extend {
drawer.clear(ColorRGBa.PINK)
drawer.composition(cd)
}
}
}
}
52 changes: 25 additions & 27 deletions orx-compositor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,38 +201,36 @@ import org.openrndr.extra.fx.edges.EdgesWork
import org.openrndr.extra.gui.GUI
import org.openrndr.math.Vector2

fun main() {
application {
configure {
width = 768
height = 768
}
program {
val w2 = width / 2.0
val h2 = height / 2.0
fun main() = application {
configure {
width = 768
height = 768
}
program {
val w2 = width / 2.0
val h2 = height / 2.0

val c = compose {
draw {
drawer.fill = ColorRGBa.PINK
drawer.circle(width / 2.0, height / 2.0, 10.0)
}

layer {
blend(Add())

val c = compose {
draw {
drawer.fill = ColorRGBa.PINK
drawer.circle(width / 2.0, height / 2.0, 10.0)
drawer.circle(width / 2.0, height / 2.0, 100.0)
}

layer {
blend(Add())

draw {
drawer.circle(width / 2.0, height / 2.0, 100.0)
}
post(ApproximateGaussianBlur()) {
window = 10
sigma = Math.cos(seconds * 10.0) * 10.0 + 10.0
}
post(ApproximateGaussianBlur()) {
window = 10
sigma = Math.cos(seconds * 10.0) * 10.0 + 10.0
}
}
extend(gui)
extend {
c.draw(drawer)
}
}
extend(gui)
extend {
c.draw(drawer)
}
}
}
Expand Down
Loading

0 comments on commit c8f7dd5

Please sign in to comment.