Thread for useful tricks when working with plotters and OPENRNDR.
1. Boolean operations (clipMode)
A useful operation when generating designs to plot is using boolean operations. Here some examples:
ClipMode.REVERSE_DIFFERENCE
draws shapes as occluded by (behind) existing content
imports
import aBeLibs.geometry.dedupe
import org.openrndr.KEY_SPACEBAR
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.dialogs.saveFileDialog
import org.openrndr.shape.ClipMode
import org.openrndr.shape.drawComposition
import org.openrndr.svg.saveToFile
fun main() {
application {
program {
// create design
val svg = drawComposition {
fill = null
circle(width / 2.0 - 100.0, height / 2.0, 100.0)
circle(width / 2.0 + 100.0, height / 2.0, 100.0)
clipMode = ClipMode.REVERSE_DIFFERENCE
circle(width / 2.0, height / 2.0, 100.0)
}
extend {
drawer.clear(ColorRGBa.WHITE)
// render design
drawer.composition(svg)
}
keyboard.keyDown.listen {
when (it.key) {
KEY_SPACEBAR -> saveFileDialog(supportedExtensions = listOf("SVG" to listOf("svg"))) { file ->
// save design for plotting
svg.saveToFile(file)
}
}
}
}
}
}
ClipMode.UNION
combines shapes
val svg = drawComposition {
fill = null // note that there's no fill!
circle(width / 2.0 - 100.0, height / 2.0, 100.0)
clipMode = ClipMode.UNION
circle(width / 2.0, height / 2.0, 100.0)
circle(width / 2.0 + 100.0, height / 2.0, 100.0)
}
ClipMode.INTERSECTION
keeps the areas in which a new shape overlaps with existing ones
ClipMode.DIFFERENCE
uses a shape to delete parts of the existing shapes