Add descriptions to demos
This commit is contained in:
@@ -12,6 +12,18 @@ import org.openrndr.draw.loadImage
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.sin
|
||||
|
||||
/**
|
||||
* Demonstrates how to convert a PNG image into `ShapeContour`s using BoofCV.
|
||||
*
|
||||
* Two helper methods help convert data types between BoofCV and OPENRNDR.
|
||||
*
|
||||
* The `ColorBuffer.toGrayF32()` method converts an OPENRNDR `ColorBuffer` to `GrayF32` format,
|
||||
* required by BoofCV.
|
||||
*
|
||||
* The `.toShapeContours()` converts BoofCV contours to OPENRNDR `ShapeContour` instances.
|
||||
*
|
||||
* The resulting contours are animated zooming in and out while their colors change slowly.
|
||||
*/
|
||||
fun main() = application {
|
||||
program {
|
||||
// Load an image, convert to BoofCV format using orx-boofcv
|
||||
|
||||
@@ -2,19 +2,31 @@ import org.openrndr.application
|
||||
import org.openrndr.boofcv.binding.resizeBy
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.loadImage
|
||||
import org.openrndr.math.Vector2
|
||||
|
||||
/**
|
||||
* Demonstrates how to scale down images using the `resizeBy` BoofCV-based
|
||||
* method.
|
||||
*/
|
||||
fun main() = application {
|
||||
program {
|
||||
// Load an image, convert to BoofCV format using orx-boofcv
|
||||
val input = loadImage("demo-data/images/image-001.png")
|
||||
|
||||
val scaled = input.resizeBy(0.5)
|
||||
val scaled2 = input.resizeBy(0.25, convertToGray = true)
|
||||
val scaled3 = input.resizeBy(0.1)
|
||||
|
||||
println("${input.width} x ${input.height}")
|
||||
println("${scaled.width} x ${scaled.height}")
|
||||
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.BLACK)
|
||||
drawer.translate(0.0, (height - scaled.bounds.height) / 2.0)
|
||||
|
||||
// Display the loaded image to the right of `scaled` matching its size
|
||||
drawer.image(input, scaled.bounds.movedBy(Vector2.UNIT_X * scaled.bounds.width))
|
||||
|
||||
// Display actually scaled down versions of the loaded image
|
||||
drawer.image(scaled)
|
||||
drawer.image(scaled2, scaled.bounds.width, scaled.bounds.height - scaled2.height)
|
||||
drawer.image(scaled3, scaled.bounds.width + scaled2.bounds.width, scaled.bounds.height - scaled3.height)
|
||||
|
||||
@@ -3,17 +3,29 @@ import org.openrndr.boofcv.binding.resizeTo
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.loadImage
|
||||
|
||||
/**
|
||||
* Demonstrates how to scale down images using the `resizeTo` BoofCV-based
|
||||
* method.
|
||||
*
|
||||
* If only the `newWidth` or the `newHeight` arguments are specified,
|
||||
* the resizing happens maintaining the original aspect ratio.
|
||||
*/
|
||||
fun main() = application {
|
||||
program {
|
||||
// Load an image, convert to BoofCV format using orx-boofcv
|
||||
val input = loadImage("demo-data/images/image-001.png")
|
||||
|
||||
val scaled = input.resizeTo(input.width / 3)
|
||||
val scaled2 = input.resizeTo(newHeight = input.height / 4, convertToGray = true)
|
||||
val scaled3 = input.resizeTo(input.width / 5, input.height / 5)
|
||||
|
||||
println("${input.width} x ${input.height}")
|
||||
println("${scaled.width} x ${scaled.height}")
|
||||
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.BLACK)
|
||||
drawer.translate(0.0, (height - scaled.bounds.height) / 2.0)
|
||||
|
||||
// Display actually scaled down versions of the loaded image
|
||||
drawer.image(scaled)
|
||||
drawer.image(scaled2, scaled.bounds.width, scaled.bounds.height - scaled2.height)
|
||||
drawer.image(scaled3, scaled.bounds.width + scaled2.bounds.width, scaled.bounds.height - scaled3.height)
|
||||
|
||||
@@ -17,6 +17,18 @@ import org.openrndr.math.Vector2
|
||||
import org.openrndr.shape.Rectangle
|
||||
import org.openrndr.shape.ShapeContour
|
||||
|
||||
/**
|
||||
* When converting a `ColorBuffer` to `ShapeContour` instances using
|
||||
* `BoofCV`, simple shapes can have hundreds of segments and vertices.
|
||||
*
|
||||
* This demo shows how to use the `simplify()` method to greatly
|
||||
* reduce the number of vertices.
|
||||
*
|
||||
* Then it uses the simplified vertex lists to create smooth curves
|
||||
* (using `CatmullRomChain2`) and polygonal curves (using `ShapeContour.fromPoints`).
|
||||
*
|
||||
* Study the console to learn about the number of segments before and after simplification.
|
||||
*/
|
||||
fun main() = application {
|
||||
program {
|
||||
// Create a buffer where to draw something for boofcv
|
||||
@@ -41,6 +53,7 @@ fun main() = application {
|
||||
rectangle(0.0, -200.0, 60.0, 60.0)
|
||||
circle(0.0, 190.0, 60.0)
|
||||
}
|
||||
|
||||
// Convert the bitmap buffer into ShapeContours
|
||||
val vectorized = imageToContours(rt.colorBuffer(0))
|
||||
|
||||
@@ -73,8 +86,11 @@ fun main() = application {
|
||||
extend {
|
||||
drawer.run {
|
||||
fill = null // ColorRGBa.PINK.opacify(0.15)
|
||||
|
||||
stroke = ColorRGBa.PINK.opacify(0.7)
|
||||
contours(polygonal)
|
||||
|
||||
stroke = ColorRGBa.GREEN.opacify(0.7)
|
||||
contours(smooth)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user