Skip to content

Commit

Permalink
Add a demo for linke caps and joins
Browse files Browse the repository at this point in the history
  • Loading branch information
hamoid authored and edwinRNDR committed Jan 28, 2021
1 parent 7aa9052 commit a3fea2d
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions openrndr-demos/src/demo/kotlin/DemoLineCapJoin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.LineCap
import org.openrndr.draw.LineJoin
import org.openrndr.draw.isolated
import org.openrndr.draw.loadFont
import org.openrndr.math.IntVector2
import org.openrndr.math.Vector2
import org.openrndr.shape.Triangle

/**
* Test all combinations of line cap and line join by drawing
* a 3x3 grid of triangles and lines.
*/

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

extend {
drawer.apply {
fill = ColorRGBa.GRAY
stroke = ColorRGBa.PINK
strokeWeight = 8.0
fontMap = font
LineCap.values().forEachIndexed { x, cap ->
lineCap = cap
LineJoin.values().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)
}
}
}
}
}
}
}
}

0 comments on commit a3fea2d

Please sign in to comment.