Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
hamoid committed Jul 24, 2023
1 parent 46a7a40 commit 38504ca
Show file tree
Hide file tree
Showing 118 changed files with 353 additions and 177 deletions.
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
kotlin = "1.8.20"
openrndr = "0.4.3-alpha8"
orx = "0.4.3-alpha8"
openrndr = "0.4.3"
orx = "0.4.3"
orml = "0.4.1"

slf4j = "2.0.7"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package examples.`04_Drawing_basics`
package examples.`04_Drawing`

import org.openrndr.application
import org.openrndr.color.ColorRGBa
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package examples.`04_Drawing_basics`
package examples.`04_Drawing`

import org.openrndr.application
import org.openrndr.color.ColorRGBa
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package examples.`04_Drawing_basics`
package examples.`04_Drawing`

import org.openrndr.application
import org.openrndr.color.ColorRGBa
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package examples.`04_Drawing_basics`
package examples.`04_Drawing`

import org.openrndr.application
import org.openrndr.color.ColorRGBa
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package examples.`04_Drawing_basics`
package examples.`04_Drawing`

import org.openrndr.application
import org.openrndr.color.ColorRGBa
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package examples.`04_Drawing_basics`
package examples.`04_Drawing`

import org.openrndr.application
import org.openrndr.color.ColorRGBa
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package examples.`04_Drawing_basics`
package examples.`04_Drawing`

import org.openrndr.application
import org.openrndr.color.ColorRGBa
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package examples.`04_Drawing_basics`
package examples.`04_Drawing`

import org.openrndr.application
import org.openrndr.color.ColorRGBa
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package examples.`04_Drawing_basics`
package examples.`04_Drawing`

import org.openrndr.application
import org.openrndr.color.ColorRGBa
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package examples.`04_Drawing_basics`
package examples.`04_Drawing`

import org.openrndr.application
import org.openrndr.color.ColorRGBa
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package examples.`04_Drawing_basics`
package examples.`04_Drawing`

import org.openrndr.application
import org.openrndr.color.ColorRGBa
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package examples.`04_Drawing_basics`
package examples.`04_Drawing`

import org.openrndr.application
import org.openrndr.color.ColorRGBa
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package examples.`04_Drawing_basics`
package examples.`04_Drawing`

import org.openrndr.application
import org.openrndr.color.ColorRGBa
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package examples.`04_Drawing_basics`
package examples.`04_Drawing`

import org.openrndr.application
import org.openrndr.color.ColorRGBa
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package examples.`04_Drawing_basics`
package examples.`04_Drawing`

import org.openrndr.application
import org.openrndr.color.ColorRGBa
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package examples.`04_Drawing_basics`
package examples.`04_Drawing`

import org.openrndr.application
import org.openrndr.color.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package examples.`04_Drawing_basics`
package examples.`04_Drawing`

import org.openrndr.application
import org.openrndr.color.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package examples.`04_Drawing_basics`
package examples.`04_Drawing`

import org.openrndr.application
import org.openrndr.color.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package examples.`04_Drawing_basics`
package examples.`04_Drawing`

import org.openrndr.application
import org.openrndr.color.*
Expand Down
62 changes: 62 additions & 0 deletions src/main/kotlin/examples/04_Drawing/C150_CurvesAndShapes000.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

package examples.`04_Drawing`

import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.LineJoin
import org.openrndr.draw.loadFont
import org.openrndr.extra.shapes.hobbyCurve
import org.openrndr.math.Vector2
import org.openrndr.math.transforms.transform
import org.openrndr.shape.*
import kotlin.math.cos
import kotlin.math.sin

fun main() {
application {
configure {
height = 200
}
program {
val font = loadFont("data/fonts/default.otf", 16.0)
val pts = listOf(Vector2(50.0, 55.0), Vector2(100.0, height - 40.0), Vector2(200.0, 35.0), Vector2(280.0, 50.0), Vector2(250.0, height - 40.0), Vector2(500.0, 35.0), Vector2(550.0, height * 0.5), Vector2(400.0, height * 0.6), Vector2(450.0, height - 40.0))
val off = Vector2(10.0, 0.0)
val off2 = Vector2(-20.0, 20.0)
extend {
drawer.clear(ColorRGBa.WHITE)
drawer.fontMap = font

drawer.stroke = null
drawer.fill = ColorRGBa.fromHex("#ff7990")
drawer.circles(pts.subList(0, 2), 4.0)
drawer.fill = ColorRGBa.fromHex("#70e1e1")
drawer.circles(pts.subList(2, 5), 4.0)
drawer.fill = ColorRGBa.fromHex("#ff9b41")
drawer.circles(pts.subList(5, 9), 4.0)


drawer.fill = ColorRGBa.BLACK
drawer.text("start", pts[0] + off)
drawer.text("end", pts[1] + off)
drawer.text("Linear", pts[1] + off2)

drawer.text("start", pts[2] + off)
drawer.text("control point", pts[3] + off)
drawer.text("end", pts[4] + off)
drawer.text("Quadratic", pts[4] + off2)

drawer.text("start", pts[5] + off)
drawer.text("cp 1", pts[6] + off)
drawer.text("cp 2", pts[7] + off)
drawer.text("end", pts[8] + off)
drawer.text("Cubic", pts[8] + off2)

drawer.stroke = ColorRGBa.BLACK
drawer.segment(Segment(pts[0], pts[1]))
drawer.segment(Segment(pts[2], pts[3], pts[4]))
drawer.segment(Segment(pts[5], pts[6], pts[7], pts[8]))
}
}
}
}

43 changes: 43 additions & 0 deletions src/main/kotlin/examples/04_Drawing/C150_CurvesAndShapes001.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

package examples.`04_Drawing`

import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.LineJoin
import org.openrndr.draw.loadFont
import org.openrndr.extra.shapes.hobbyCurve
import org.openrndr.math.Vector2
import org.openrndr.math.transforms.transform
import org.openrndr.shape.*
import kotlin.math.cos
import kotlin.math.sin

fun main() {
application {
configure {
height = 160
}
program {
val font = loadFont("data/fonts/default.otf", 16.0)
val contours = listOf(Circle(100.0, height / 2.0, 50.0).contour, Rectangle.fromCenter(Vector2(280.0, height / 2.0), 100.0).contour, hobbyCurve(listOf(Vector2(400.0, 50.0), Vector2(450.0, 120.0), Vector2(500.0, 80.0), Vector2(600.0, 130.0), Vector2(550.0, 80.0))))

extend {
drawer.clear(ColorRGBa.WHITE)
drawer.fontMap = font

drawer.stroke = null
drawer.fill = ColorRGBa.PINK
drawer.circles(contours.map { c ->
c.segments.map { seg ->
seg.start
} + c.position(1.0)
}.flatten(), 5.0)

drawer.fill = null
drawer.stroke = ColorRGBa.BLACK
drawer.contours(contours)
}
}
}
}

Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@

package examples.`04_Drawing_basics`
package examples.`04_Drawing`

import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.LineJoin
import org.openrndr.extra.noise.uniform
import org.openrndr.draw.loadFont
import org.openrndr.extra.shapes.hobbyCurve
import org.openrndr.math.Vector2
import org.openrndr.math.transforms.transform
import org.openrndr.shape.*
import kotlin.math.cos
import kotlin.math.sin

fun main() {
application {
configure {
width = 770
height = 578
}
program {
extend {
val c = contour {
moveTo(Vector2(width / 2.0 - 150.0, height / 2.0 - 150.00))
moveTo(Vector2(width / 2.0 - 120.0, height / 2.0 - 120.00))
// -- here `cursor` points to the end point of the previous command
lineTo(cursor + Vector2(300.0, 0.0))
lineTo(cursor + Vector2(0.0, 300.0))
lineTo(cursor + Vector2(240.0, 0.0))
lineTo(cursor + Vector2(0.0, 240.0))
lineTo(anchor)
close()
}
drawer.clear(ColorRGBa.WHITE)
drawer.fill = ColorRGBa.PINK
drawer.stroke = null
drawer.contour(c)
Expand Down
38 changes: 38 additions & 0 deletions src/main/kotlin/examples/04_Drawing/C150_CurvesAndShapes003.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

package examples.`04_Drawing`

import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.LineJoin
import org.openrndr.draw.loadFont
import org.openrndr.extra.shapes.hobbyCurve
import org.openrndr.math.Vector2
import org.openrndr.math.transforms.transform
import org.openrndr.shape.*
import kotlin.math.cos
import kotlin.math.sin

fun main() {
application {
program {
val points = List(20) {
Vector2(20.0 + it * 32.0, 100.0 + sin(it * 1.0) * it * 3)
}
val wavyContour = ShapeContour.fromPoints(points, closed = false)
val smoothContour = hobbyCurve(points, closed = false)

extend {
drawer.clear(ColorRGBa.WHITE)
drawer.fill = null
drawer.strokeWeight = 5.0
drawer.stroke = ColorRGBa.PINK
drawer.contour(wavyContour)

drawer.translate(0.0, 10.0) // displace 10px down
drawer.stroke = ColorRGBa.BLACK.opacify(0.5)
drawer.contour(smoothContour)
}
}
}
}

Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@

package examples.`04_Drawing_basics`
package examples.`04_Drawing`

import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.LineJoin
import org.openrndr.extra.noise.uniform
import org.openrndr.draw.loadFont
import org.openrndr.extra.shapes.hobbyCurve
import org.openrndr.math.Vector2
import org.openrndr.math.transforms.transform
import org.openrndr.shape.*
import kotlin.math.cos
import kotlin.math.sin

fun main() {
application {
program {
val points = List(30) {
Vector2(20.0 + it * 20.0, 300.0 + sin(it * 0.8) * 100.0)
}
val wavyContour = ShapeContour.fromPoints(points, closed = true)

val segments = listOf(Segment(Vector2(10.0, 100.0), Vector2(200.0, 80.0)), // Linear Segment
val segments = listOf(Segment(Vector2(10.0, 100.0), Vector2(200.0, 80.0)), // Linear Bézier Segment
Segment(Vector2(200.0, 80.0), Vector2(250.0, 280.0), Vector2(400.0, 80.0)), // Quadratic Bézier segment
Segment(Vector2(400.0, 80.0), Vector2(450.0, 180.0), Vector2(500.0, 0.0), Vector2(630.0, 80.0))) // Cubic Bézier segment
val horizontalContour = ShapeContour.fromSegments(segments, closed = false)

extend {
drawer.fill = ColorRGBa.PINK
drawer.contour(wavyContour)

drawer.clear(ColorRGBa.WHITE)
drawer.strokeWeight = 5.0
drawer.stroke = ColorRGBa.PINK
drawer.contour(horizontalContour)
Expand Down

0 comments on commit 38504ca

Please sign in to comment.