Demos: ensure all use fun main() = application {
- Adjust some demo window sizes. - Replace Random.double by Double.uniform - Tweak some demos so screenshots look more interesting
This commit is contained in:
@@ -12,54 +12,56 @@ import org.openrndr.draw.loadImage
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.sin
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
// Load an image, convert to BoofCV format using orx-boofcv
|
||||
val input = loadImage("demo-data/images/image-001.png").toGrayF32()
|
||||
fun main() = application {
|
||||
program {
|
||||
// Load an image, convert to BoofCV format using orx-boofcv
|
||||
val input = loadImage("demo-data/images/image-001.png").toGrayF32()
|
||||
|
||||
// BoofCV: calculate a good threshold for the loaded image
|
||||
val threshold = GThresholdImageOps.computeOtsu(input, 0.0, 255.0)
|
||||
// BoofCV: calculate a good threshold for the loaded image
|
||||
val threshold = GThresholdImageOps.computeOtsu(input, 0.0, 255.0)
|
||||
|
||||
// BoofCV: use the threshold to convert the image to black and white
|
||||
val binary = GrayU8(input.width, input.height)
|
||||
ThresholdImageOps.threshold(input, binary, threshold.toFloat(), false)
|
||||
// BoofCV: use the threshold to convert the image to black and white
|
||||
val binary = GrayU8(input.width, input.height)
|
||||
ThresholdImageOps.threshold(input, binary, threshold.toFloat(), false)
|
||||
|
||||
// BoofCV: Contract and expand the white areas to remove noise
|
||||
var filtered = BinaryImageOps.erode8(binary, 1, null)
|
||||
filtered = BinaryImageOps.dilate8(filtered, 1, null)
|
||||
// BoofCV: Contract and expand the white areas to remove noise
|
||||
var filtered = BinaryImageOps.erode8(binary, 1, null)
|
||||
filtered = BinaryImageOps.dilate8(filtered, 1, null)
|
||||
|
||||
// BoofCV: Calculate contours as vector data
|
||||
val contours = BinaryImageOps.contour(filtered, ConnectRule.EIGHT, null)
|
||||
// BoofCV: Calculate contours as vector data
|
||||
val contours = BinaryImageOps.contour(filtered, ConnectRule.EIGHT, null)
|
||||
|
||||
// orx-boofcv: convert vector data to OPENRNDR ShapeContours
|
||||
val externalShapes = contours.toShapeContours(true,
|
||||
internal = false, external = true)
|
||||
val internalShapes = contours.toShapeContours(true,
|
||||
internal = true, external = false)
|
||||
// orx-boofcv: convert vector data to OPENRNDR ShapeContours
|
||||
val externalShapes = contours.toShapeContours(
|
||||
true,
|
||||
internal = false, external = true
|
||||
)
|
||||
val internalShapes = contours.toShapeContours(
|
||||
true,
|
||||
internal = true, external = false
|
||||
)
|
||||
|
||||
extend {
|
||||
drawer.run {
|
||||
// Zoom in and out over time
|
||||
translate(bounds.center)
|
||||
scale(1.5 + 0.5 * cos(seconds * 0.2))
|
||||
translate(-bounds.center)
|
||||
extend {
|
||||
drawer.run {
|
||||
// Zoom in and out over time
|
||||
translate(bounds.center)
|
||||
scale(1.5 + 0.5 * cos(seconds * 0.2))
|
||||
translate(-bounds.center)
|
||||
|
||||
stroke = null
|
||||
stroke = null
|
||||
|
||||
// Draw all external shapes
|
||||
fill = rgb(0.2)
|
||||
contours(externalShapes)
|
||||
// Draw all external shapes
|
||||
fill = rgb(0.2)
|
||||
contours(externalShapes)
|
||||
|
||||
// Draw internal shapes one by one to set unique colors
|
||||
internalShapes.forEachIndexed { i, shp ->
|
||||
val shade = 0.2 + (i % 7) * 0.1 +
|
||||
0.1 * sin(i + seconds)
|
||||
fill = ColorRGBa.PINK.shade(shade)
|
||||
contour(shp)
|
||||
}
|
||||
// Draw internal shapes one by one to set unique colors
|
||||
internalShapes.forEachIndexed { i, shp ->
|
||||
val shade = 0.2 + (i % 7) * 0.1 +
|
||||
0.1 * sin(i + seconds)
|
||||
fill = ColorRGBa.PINK.shade(shade)
|
||||
contour(shp)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,24 +3,21 @@ import org.openrndr.boofcv.binding.resizeBy
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.loadImage
|
||||
|
||||
fun main() = application {
|
||||
program {
|
||||
// Load an image, convert to BoofCV format using orx-boofcv
|
||||
val input = loadImage("demo-data/images/image-001.png")
|
||||
|
||||
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)
|
||||
|
||||
val scaled = input.resizeBy(0.5)
|
||||
val scaled2 = input.resizeBy(0.25, convertToGray = true)
|
||||
val scaled3 = input.resizeBy(0.1)
|
||||
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.BLACK)
|
||||
drawer.translate(0.0, (height - scaled.bounds.height) / 2.0)
|
||||
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)
|
||||
}
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.BLACK)
|
||||
drawer.translate(0.0, (height - scaled.bounds.height) / 2.0)
|
||||
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,23 +3,20 @@ import org.openrndr.boofcv.binding.resizeTo
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.loadImage
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.BLACK)
|
||||
drawer.translate(0.0, (height - scaled.bounds.height) / 2.0)
|
||||
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)
|
||||
}
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.BLACK)
|
||||
drawer.translate(0.0, (height - scaled.bounds.height) / 2.0)
|
||||
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,63 +17,65 @@ import org.openrndr.math.Vector2
|
||||
import org.openrndr.shape.Rectangle
|
||||
import org.openrndr.shape.ShapeContour
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
// Create a buffer where to draw something for boofcv
|
||||
val rt = renderTarget(width, height) {
|
||||
colorBuffer()
|
||||
depthBuffer()
|
||||
}
|
||||
// Draw some shapes on that buffer
|
||||
drawer.isolatedWithTarget(rt) {
|
||||
clear(ColorRGBa.BLACK)
|
||||
fill = ColorRGBa.WHITE
|
||||
stroke = null
|
||||
rectangle(Rectangle.fromCenter(bounds.position(0.33, 0.5),
|
||||
150.0, 150.0))
|
||||
translate(bounds.position(0.62, 0.5))
|
||||
rotate(30.0)
|
||||
rectangle(Rectangle.fromCenter(Vector2.ZERO, 200.0, 200.0))
|
||||
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))
|
||||
fun main() = application {
|
||||
program {
|
||||
// Create a buffer where to draw something for boofcv
|
||||
val rt = renderTarget(width, height) {
|
||||
colorBuffer()
|
||||
depthBuffer()
|
||||
}
|
||||
// Draw some shapes on that buffer
|
||||
drawer.isolatedWithTarget(rt) {
|
||||
clear(ColorRGBa.BLACK)
|
||||
fill = ColorRGBa.WHITE
|
||||
stroke = null
|
||||
rectangle(
|
||||
Rectangle.fromCenter(
|
||||
bounds.position(0.33, 0.5),
|
||||
150.0, 150.0
|
||||
)
|
||||
)
|
||||
translate(bounds.position(0.62, 0.5))
|
||||
rotate(30.0)
|
||||
rectangle(Rectangle.fromCenter(Vector2.ZERO, 200.0, 200.0))
|
||||
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))
|
||||
|
||||
// Show amount of segments in each shape (high number)
|
||||
vectorized.forEachIndexed { i, it ->
|
||||
println("boofcv shape $i: ${it.segments.size} segments")
|
||||
}
|
||||
// Show amount of segments in each shape (high number)
|
||||
vectorized.forEachIndexed { i, it ->
|
||||
println("boofcv shape $i: ${it.segments.size} segments")
|
||||
}
|
||||
|
||||
// Make a simplified list of points
|
||||
val simplePoints = vectorized.map {
|
||||
simplify(it.adaptivePositions(), 4.0)
|
||||
}.filter { it.size >= 3 }
|
||||
// Make a simplified list of points
|
||||
val simplePoints = vectorized.map {
|
||||
simplify(it.adaptivePositions(), 4.0)
|
||||
}.filter { it.size >= 3 }
|
||||
|
||||
// Use the simplified list to make a smooth contour
|
||||
val smooth = simplePoints.map {
|
||||
CatmullRomChain2(it, 0.0, true).toContour()
|
||||
}
|
||||
// Use the simplified list to make a smooth contour
|
||||
val smooth = simplePoints.map {
|
||||
CatmullRomChain2(it, 0.0, true).toContour()
|
||||
}
|
||||
|
||||
// Use the simplified list to make a polygonal contour
|
||||
val polygonal = simplePoints.map {
|
||||
ShapeContour.fromPoints(it, true)
|
||||
}
|
||||
// Use the simplified list to make a polygonal contour
|
||||
val polygonal = simplePoints.map {
|
||||
ShapeContour.fromPoints(it, true)
|
||||
}
|
||||
|
||||
// Show amount of segments in simplified shapes (low number).
|
||||
// Note: `smooth` and `polygonal` have the same number of segments
|
||||
smooth.forEachIndexed { i, it ->
|
||||
println("simplified shape $i: ${it.segments.size} segments")
|
||||
}
|
||||
// Show amount of segments in simplified shapes (low number).
|
||||
// Note: `smooth` and `polygonal` have the same number of segments
|
||||
smooth.forEachIndexed { i, it ->
|
||||
println("simplified shape $i: ${it.segments.size} segments")
|
||||
}
|
||||
|
||||
extend {
|
||||
drawer.run {
|
||||
fill = null // ColorRGBa.PINK.opacify(0.15)
|
||||
stroke = ColorRGBa.PINK.opacify(0.7)
|
||||
contours(polygonal)
|
||||
contours(smooth)
|
||||
}
|
||||
extend {
|
||||
drawer.run {
|
||||
fill = null // ColorRGBa.PINK.opacify(0.15)
|
||||
stroke = ColorRGBa.PINK.opacify(0.7)
|
||||
contours(polygonal)
|
||||
contours(smooth)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,4 +99,4 @@ fun imageToContours(input: ColorBuffer): List<ShapeContour> {
|
||||
|
||||
// orx-boofcv: convert vector data to OPENRNDR ShapeContours
|
||||
return contours.toShapeContours(true, internal = true, external = true)
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ private fun SceneRenderer.processVoxelConeTracing(drawer: Drawer, scene: Scene,
|
||||
val position = Vector3.ZERO
|
||||
drawer.lookAt(position + side.forward*40.0, position , side.up)
|
||||
drawPass(drawer, pass, materialContext, context) {
|
||||
it.parameter("voxelMap", feature.voxelMap!!.imageBinding(0, ImageAccess.WRITE))
|
||||
it.image("voxelMap", feature.voxelMap!!.imageBinding(0, ImageAccess.WRITE))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,25 +4,23 @@ import org.openrndr.extra.parameters.Description
|
||||
import org.openrndr.extra.parameters.PathParameter
|
||||
import org.openrndr.extra.propertywatchers.watchingImagePath
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
val gui = GUI()
|
||||
gui.compartmentsCollapsedByDefault = false
|
||||
fun main() = application {
|
||||
program {
|
||||
val gui = GUI()
|
||||
gui.compartmentsCollapsedByDefault = false
|
||||
|
||||
val settings = @Description("Settings") object {
|
||||
@PathParameter("image", extensions = ["jpg", "png"], order = 10)
|
||||
var imagePath = "demo-data/images/image-001.png"
|
||||
val settings = @Description("Settings") object {
|
||||
@PathParameter("image", extensions = ["jpg", "png"], order = 10)
|
||||
var imagePath = "demo-data/images/image-001.png"
|
||||
|
||||
val image by watchingImagePath(::imagePath) {
|
||||
it
|
||||
}
|
||||
}
|
||||
gui.add(settings)
|
||||
extend(gui)
|
||||
extend {
|
||||
drawer.image(settings.image)
|
||||
val image by watchingImagePath(::imagePath) {
|
||||
it
|
||||
}
|
||||
}
|
||||
gui.add(settings)
|
||||
extend(gui)
|
||||
extend {
|
||||
drawer.image(settings.image)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.openrndr.*
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.dialogs.*
|
||||
import org.openrndr.draw.Drawer
|
||||
import org.openrndr.extra.noise.random
|
||||
import org.openrndr.extra.noise.uniform
|
||||
import org.openrndr.extra.parameters.*
|
||||
import org.openrndr.internal.Driver
|
||||
@@ -1077,7 +1076,7 @@ open class GUI(
|
||||
val min = parameter.doubleRange!!.start
|
||||
val max = parameter.doubleRange!!.endInclusive
|
||||
val currentValue = (parameter.property as KMutableProperty1<Any, Double>).get(labeledObject.obj)
|
||||
val randomValue = random(min, max)
|
||||
val randomValue = Double.uniform(min, max)
|
||||
val newValue = mix(currentValue, randomValue, strength)
|
||||
(parameter.property as KMutableProperty1<Any, Double>).set(labeledObject.obj, newValue)
|
||||
}
|
||||
@@ -1086,7 +1085,7 @@ open class GUI(
|
||||
val min = parameter.intRange!!.first
|
||||
val max = parameter.intRange!!.last
|
||||
val currentValue = (parameter.property as KMutableProperty1<Any, Int>).get(labeledObject.obj)
|
||||
val randomValue = random(min.toDouble(), max.toDouble())
|
||||
val randomValue = Double.uniform(min.toDouble(), max.toDouble())
|
||||
val newValue = mix(currentValue.toDouble(), randomValue, strength).roundToInt()
|
||||
(parameter.property as KMutableProperty1<Any, Int>).set(labeledObject.obj, newValue)
|
||||
}
|
||||
|
||||
@@ -9,33 +9,31 @@ import org.openrndr.math.Vector2
|
||||
/**
|
||||
* Demonstration of two-way binding using [bindMidiControl]
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
val midi = openMidiDevice("MIDI2x2 [hw:3,0,0]")
|
||||
val settings = object {
|
||||
@DoubleParameter("radius", 0.0, 100.0)
|
||||
var radius = 0.0
|
||||
fun main() = application {
|
||||
program {
|
||||
val midi = openMidiDevice("MIDI2x2 [hw:3,0,0]")
|
||||
val settings = object {
|
||||
@DoubleParameter("radius", 0.0, 100.0)
|
||||
var radius = 0.0
|
||||
|
||||
@DoubleParameter("x", -100.0, 100.0)
|
||||
var x = 0.0
|
||||
@DoubleParameter("x", -100.0, 100.0)
|
||||
var x = 0.0
|
||||
|
||||
@DoubleParameter("y", -100.0, 100.0)
|
||||
var y = 0.0
|
||||
@DoubleParameter("y", -100.0, 100.0)
|
||||
var y = 0.0
|
||||
|
||||
@ColorParameter("fill")
|
||||
var color = ColorRGBa.WHITE
|
||||
}
|
||||
@ColorParameter("fill")
|
||||
var color = ColorRGBa.WHITE
|
||||
}
|
||||
|
||||
bindMidiControl(settings::radius, midi, 0, 1)
|
||||
bindMidiControl(settings::x, midi, 0, 2)
|
||||
bindMidiControl(settings::y, midi, 0, 3)
|
||||
bindMidiControl(settings::color, midi, 0, 4)
|
||||
bindMidiControl(settings::radius, midi, 0, 1)
|
||||
bindMidiControl(settings::x, midi, 0, 2)
|
||||
bindMidiControl(settings::y, midi, 0, 3)
|
||||
bindMidiControl(settings::color, midi, 0, 4)
|
||||
|
||||
extend {
|
||||
drawer.fill = settings.color
|
||||
drawer.circle(drawer.bounds.center + Vector2(settings.x, settings.y), settings.radius)
|
||||
}
|
||||
extend {
|
||||
drawer.fill = settings.color
|
||||
drawer.circle(drawer.bounds.center + Vector2(settings.x, settings.y), settings.radius)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,14 +6,12 @@ import org.openrndr.extra.midi.openMidiDevice
|
||||
/**
|
||||
* Demonstration of [MidiConsole]
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
listMidiDevices().forEach { println(it.toString()) }
|
||||
val midi = openMidiDevice("Launchpad [hw:4,0,0]")
|
||||
extend(MidiConsole()) {
|
||||
register(midi)
|
||||
}
|
||||
fun main() = application {
|
||||
program {
|
||||
listMidiDevices().forEach { println(it.toString()) }
|
||||
val midi = openMidiDevice("Launchpad [hw:4,0,0]")
|
||||
extend(MidiConsole()) {
|
||||
register(midi)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,98 +13,96 @@ import kotlin.random.Random
|
||||
* Hold the mouse button to randomize the frequencies.
|
||||
* Press keys 'a' or 'b' for less random frequencies.
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
val minim = minim()
|
||||
val out = minim.lineOut
|
||||
fun main() = application {
|
||||
program {
|
||||
val minim = minim()
|
||||
val out = minim.lineOut
|
||||
|
||||
if (out == null) {
|
||||
application.exit()
|
||||
if (out == null) {
|
||||
application.exit()
|
||||
}
|
||||
|
||||
// generates a random frequency value biased down
|
||||
fun randomFreq() = 20f + Random.nextFloat().pow(3) * 1000
|
||||
|
||||
// If one didn't want to visualize or control the synths we
|
||||
// wouldn't need a data structure to store them. Here we store
|
||||
// Pairs, so we have access both to the frequency of the wave
|
||||
// and the current amplitude defined by the lfo (low frequency
|
||||
// oscillator).
|
||||
val synths = List(20) {
|
||||
// By default, Oscil creates sine waves, but it can be changed.
|
||||
val lfo = Oscil(
|
||||
Random.nextFloat() * 0.1f + 0.005f,
|
||||
0.05f
|
||||
).apply {
|
||||
// Here we set the center of the lfo to 0.05f.
|
||||
// Since the amplitude is also 0.05f, it moves between
|
||||
// 0.00f and 0.10f.
|
||||
offset.lastValue = 0.05f
|
||||
|
||||
// Have the sine waves to not start in sync.
|
||||
//phase.lastValue = Random.nextFloat() * 6.28f
|
||||
}
|
||||
val wave = Oscil(randomFreq(), 0f)
|
||||
// The `lfo` Oscil controls the `wave` Oscil's amplitude.
|
||||
lfo.patch(wave.amplitude)
|
||||
// Random pan to avoid a mono sound.
|
||||
val pan = Pan(Random.nextFloat() * 2 - 1)
|
||||
wave.patch(pan)
|
||||
pan.patch(out)
|
||||
// Store a [Pair] in `synths`.
|
||||
Pair(wave, lfo)
|
||||
}
|
||||
val bgColor = rgb(0.094, 0.188, 0.349)
|
||||
val lineColor = rgb(0.992, 0.918, 0.671)
|
||||
val mouseTracker = MouseTracker(mouse)
|
||||
|
||||
// generates a random frequency value biased down
|
||||
fun randomFreq() = 20f + Random.nextFloat().pow(3) * 1000
|
||||
|
||||
// If one didn't want to visualize or control the synths we
|
||||
// wouldn't need a data structure to store them. Here we store
|
||||
// Pairs, so we have access both to the frequency of the wave
|
||||
// and the current amplitude defined by the lfo (low frequency
|
||||
// oscillator).
|
||||
val synths = List(20) {
|
||||
// By default, Oscil creates sine waves, but it can be changed.
|
||||
val lfo = Oscil(
|
||||
Random.nextFloat() * 0.1f + 0.005f,
|
||||
0.05f
|
||||
).apply {
|
||||
// Here we set the center of the lfo to 0.05f.
|
||||
// Since the amplitude is also 0.05f, it moves between
|
||||
// 0.00f and 0.10f.
|
||||
offset.lastValue = 0.05f
|
||||
|
||||
// Have the sine waves to not start in sync.
|
||||
//phase.lastValue = Random.nextFloat() * 6.28f
|
||||
extend {
|
||||
drawer.clear(bgColor)
|
||||
drawer.translate(drawer.bounds.center)
|
||||
drawer.rotate(seconds)
|
||||
// A CircleBatchBuilder for faster drawing of circles.
|
||||
drawer.circles {
|
||||
// For each synth draw a circle.
|
||||
synths.forEachIndexed { i, (wave, lfo) ->
|
||||
stroke = lineColor.opacify(Random.nextDouble(0.4) + 0.6)
|
||||
fill = lineColor.opacify(Random.nextDouble() * 0.04)
|
||||
// A Polar arrangement centered on the screen.
|
||||
// Higher pitch circles are farther away from the center.
|
||||
val pos = Polar(
|
||||
360.0 * i / synths.size,
|
||||
50.0 + wave.frequency.lastValue * 0.2
|
||||
).cartesian
|
||||
// The size of the circle depends on the current volume
|
||||
// set by the lfo.
|
||||
circle(pos, 500 * lfo.lastValues.last().toDouble())
|
||||
}
|
||||
val wave = Oscil(randomFreq(), 0f)
|
||||
// The `lfo` Oscil controls the `wave` Oscil's amplitude.
|
||||
lfo.patch(wave.amplitude)
|
||||
// Random pan to avoid a mono sound.
|
||||
val pan = Pan(Random.nextFloat() * 2 - 1)
|
||||
wave.patch(pan)
|
||||
pan.patch(out)
|
||||
// Store a [Pair] in `synths`.
|
||||
Pair(wave, lfo)
|
||||
}
|
||||
val bgColor = rgb(0.094, 0.188, 0.349)
|
||||
val lineColor = rgb(0.992, 0.918, 0.671)
|
||||
val mouseTracker = MouseTracker(mouse)
|
||||
|
||||
extend {
|
||||
drawer.clear(bgColor)
|
||||
drawer.translate(drawer.bounds.center)
|
||||
drawer.rotate(seconds)
|
||||
// A CircleBatchBuilder for faster drawing of circles.
|
||||
drawer.circles {
|
||||
// For each synth draw a circle.
|
||||
synths.forEachIndexed { i, (wave, lfo) ->
|
||||
stroke = lineColor.opacify(Random.nextDouble(0.4) + 0.6)
|
||||
fill = lineColor.opacify(Random.nextDouble() * 0.04)
|
||||
// A Polar arrangement centered on the screen.
|
||||
// Higher pitch circles are farther away from the center.
|
||||
val pos = Polar(
|
||||
360.0 * i / synths.size,
|
||||
50.0 + wave.frequency.lastValue * 0.2
|
||||
).cartesian
|
||||
// The size of the circle depends on the current volume
|
||||
// set by the lfo.
|
||||
circle(pos, 500 * lfo.lastValues.last().toDouble())
|
||||
if (mouseTracker.pressedButtons.isNotEmpty()) {
|
||||
synths.random().first.setFrequency(randomFreq())
|
||||
}
|
||||
}
|
||||
keyboard.keyDown.listen { key ->
|
||||
when (key.name) {
|
||||
"a" -> {
|
||||
// make all frequencies close to a base frequency
|
||||
// (circular arrangement)
|
||||
val baseFreq = 20 + Random.nextFloat() * 200
|
||||
synths.forEach {
|
||||
it.first.setFrequency(baseFreq + Random.nextFloat() * 20)
|
||||
}
|
||||
}
|
||||
if (mouseTracker.pressedButtons.isNotEmpty()) {
|
||||
synths.random().first.setFrequency(randomFreq())
|
||||
}
|
||||
}
|
||||
keyboard.keyDown.listen { key ->
|
||||
when (key.name) {
|
||||
"a" -> {
|
||||
// make all frequencies close to a base frequency
|
||||
// (circular arrangement)
|
||||
val baseFreq = 20 + Random.nextFloat() * 200
|
||||
synths.forEach {
|
||||
it.first.setFrequency(baseFreq + Random.nextFloat() * 20)
|
||||
}
|
||||
}
|
||||
|
||||
"b" -> {
|
||||
// make all frequencies follow an exponential series
|
||||
// (spiral arrangement)
|
||||
val inc = Random.nextFloat() * 0.1f
|
||||
synths.forEachIndexed { i, (wave, _) ->
|
||||
wave.setFrequency(25f.pow(1f + i * inc))
|
||||
}
|
||||
"b" -> {
|
||||
// make all frequencies follow an exponential series
|
||||
// (spiral arrangement)
|
||||
val inc = Random.nextFloat() * 0.1f
|
||||
synths.forEachIndexed { i, (wave, _) ->
|
||||
wave.setFrequency(25f.pow(1f + i * inc))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,35 @@
|
||||
import ddf.minim.Minim
|
||||
import ddf.minim.analysis.FFT
|
||||
import ddf.minim.analysis.LanczosWindow
|
||||
|
||||
import org.openrndr.application
|
||||
import org.openrndr.extra.minim.minim
|
||||
import org.openrndr.math.map
|
||||
import kotlin.math.ln
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 1280
|
||||
height = 720
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 1280
|
||||
height = 720
|
||||
}
|
||||
|
||||
program {
|
||||
val minim = minim()
|
||||
if (minim.lineOut == null) {
|
||||
application.exit()
|
||||
}
|
||||
|
||||
program {
|
||||
val minim = minim()
|
||||
if (minim.lineOut == null) {
|
||||
application.exit()
|
||||
}
|
||||
|
||||
val lineIn = minim.getLineIn(Minim.MONO, 2048, 48000f)
|
||||
if (lineIn == null) {
|
||||
application.exit()
|
||||
}
|
||||
val fft = FFT(lineIn.bufferSize(), lineIn.sampleRate())
|
||||
fft.window(LanczosWindow())
|
||||
extend {
|
||||
fft.forward(lineIn.mix)
|
||||
for (i in 0 until 200) {
|
||||
val bandDB = 20.0 * ln(2.0 * fft.getBand(i) / fft.timeSize())
|
||||
drawer.rectangle(i * 5.0, height / 2.0, 5.0, bandDB.map(0.0, -150.0, 0.0, -height / 8.0))
|
||||
}
|
||||
val lineIn = minim.getLineIn(Minim.MONO, 2048, 48000f)
|
||||
if (lineIn == null) {
|
||||
application.exit()
|
||||
}
|
||||
val fft = FFT(lineIn.bufferSize(), lineIn.sampleRate())
|
||||
fft.window(LanczosWindow())
|
||||
extend {
|
||||
fft.forward(lineIn.mix)
|
||||
for (i in 0 until 200) {
|
||||
val bandDB = 20.0 * ln(2.0 * fft.getBand(i) / fft.timeSize())
|
||||
drawer.rectangle(i * 5.0, height / 2.0, 5.0, bandDB.map(0.0, -150.0, 0.0, -height / 8.0))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,26 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.extra.minim.minim
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
val minim = minim()
|
||||
if (minim.lineOut == null) {
|
||||
application.exit()
|
||||
}
|
||||
fun main() = application {
|
||||
program {
|
||||
val minim = minim()
|
||||
if (minim.lineOut == null) {
|
||||
application.exit()
|
||||
}
|
||||
|
||||
val player = minim.loadFile(
|
||||
"demo-data/sounds/26777__junggle__btn402.mp3"
|
||||
)
|
||||
val player = minim.loadFile(
|
||||
"demo-data/sounds/26777__junggle__btn402.mp3"
|
||||
)
|
||||
|
||||
// fade gain to -40dB in 15 seconds
|
||||
player.shiftGain(player.gain, -40f, 15000)
|
||||
// fade gain to -40dB in 15 seconds
|
||||
player.shiftGain(player.gain, -40f, 15000)
|
||||
|
||||
extend {
|
||||
if(frameCount % 30 == 0) {
|
||||
player.rewind()
|
||||
//player.gain = Random.nextDouble(-20.0, 0.0).toFloat()
|
||||
player.play()
|
||||
}
|
||||
extend {
|
||||
if (frameCount % 30 == 0) {
|
||||
player.rewind()
|
||||
//player.gain = Random.nextDouble(-20.0, 0.0).toFloat()
|
||||
player.play()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,39 +8,37 @@ import kotlin.math.cos
|
||||
/**
|
||||
* Live-coding with [oliveProgram]
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 1280
|
||||
height = 720
|
||||
}
|
||||
oliveProgram {
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.PINK)
|
||||
drawer.fill = ColorRGBa.WHITE
|
||||
for (i in 0 until 100) {
|
||||
drawer.circle(
|
||||
width / 2.0 + cos(seconds + i) * 320.0,
|
||||
i * 7.2,
|
||||
cos(i + seconds * 0.5) * 20.0 + 20.0
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
// -- this is only needed for the automated screenshots
|
||||
.olive.scriptLoaded.listen {
|
||||
if (System.getProperty("takeScreenshot") == "true") {
|
||||
// -- this is a bit of hack, we need to push the screenshot extension in front of the olive one
|
||||
fun <T : Extension> extendHead(extension: T, configure: T.() -> Unit): T {
|
||||
program.extensions.add(0, extension)
|
||||
extension.configure()
|
||||
extension.setup(program)
|
||||
return extension
|
||||
}
|
||||
extendHead(SingleScreenshot()) {
|
||||
this.outputFile = System.getProperty("screenshotPath")
|
||||
}
|
||||
}
|
||||
}
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 1280
|
||||
height = 720
|
||||
}
|
||||
}
|
||||
oliveProgram {
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.PINK)
|
||||
drawer.fill = ColorRGBa.WHITE
|
||||
for (i in 0 until 100) {
|
||||
drawer.circle(
|
||||
width / 2.0 + cos(seconds + i) * 320.0,
|
||||
i * 7.2,
|
||||
cos(i + seconds * 0.5) * 20.0 + 20.0
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
// -- this is only needed for the automated screenshots
|
||||
.olive.scriptLoaded.listen {
|
||||
if (System.getProperty("takeScreenshot") == "true") {
|
||||
// -- this is a bit of hack, we need to push the screenshot extension in front of the olive one
|
||||
fun <T : Extension> extendHead(extension: T, configure: T.() -> Unit): T {
|
||||
program.extensions.add(0, extension)
|
||||
extension.configure()
|
||||
extension.setup(program)
|
||||
return extension
|
||||
}
|
||||
extendHead(SingleScreenshot()) {
|
||||
this.outputFile = System.getProperty("screenshotPath")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.openrndr.draw.colorBuffer
|
||||
import org.openrndr.draw.isolatedWithTarget
|
||||
import org.openrndr.draw.renderTarget
|
||||
import org.openrndr.extra.noise.Random
|
||||
import org.openrndr.extra.noise.uniform
|
||||
import org.openrndr.math.Polar
|
||||
import org.openrndr.math.clamp
|
||||
import org.openrndr.poissonfill.PoissonFill
|
||||
@@ -34,11 +35,11 @@ fun main() {
|
||||
val things = List(10) {
|
||||
Thing(
|
||||
ColorHSVa(it * 182.0,
|
||||
Random.double(0.3, 0.6),
|
||||
Random.double(0.1, 0.9)).toRGBa(),
|
||||
Polar(Random.double0(360.0),
|
||||
Double.uniform(0.3, 0.6),
|
||||
Double.uniform(0.1, 0.9)).toRGBa(),
|
||||
Polar(Double.uniform(0.0, 360.0),
|
||||
100.0 + it * 10.0),
|
||||
Polar(Random.double(-1.0, 1.0), 0.0))
|
||||
Polar(Double.uniform(-1.0, 1.0), 0.0))
|
||||
}
|
||||
val mouseTracker = MouseTracker(mouse)
|
||||
|
||||
|
||||
@@ -6,29 +6,27 @@ import org.openrndr.draw.colorBuffer
|
||||
import org.openrndr.draw.tint
|
||||
import org.openrndr.extra.realsense2.RS2Sensor
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
val sensors = RS2Sensor.listSensors()
|
||||
val depthFrame = colorBuffer(640, 480, format = ColorFormat.R, type = ColorType.UINT16)
|
||||
for (sensor in sensors) {
|
||||
println(sensor)
|
||||
}
|
||||
val sensor = RS2Sensor.openFirstOrDummy()
|
||||
fun main() = application {
|
||||
program {
|
||||
val sensors = RS2Sensor.listSensors()
|
||||
val depthFrame = colorBuffer(640, 480, format = ColorFormat.R, type = ColorType.UINT16)
|
||||
for (sensor in sensors) {
|
||||
println(sensor)
|
||||
for (stream in sensor.streams) {
|
||||
println(stream.intrinsics)
|
||||
}
|
||||
}
|
||||
val sensor = RS2Sensor.openFirstOrDummy()
|
||||
println(sensor)
|
||||
for (stream in sensor.streams) {
|
||||
println(stream.intrinsics)
|
||||
}
|
||||
|
||||
|
||||
sensor.depthFrameReceived.listen {
|
||||
it.copyTo(depthFrame)
|
||||
}
|
||||
extend {
|
||||
sensor.waitForFrames()
|
||||
drawer.drawStyle.colorMatrix = tint(ColorRGBa.WHITE.shade(20.0))
|
||||
drawer.image(depthFrame)
|
||||
}
|
||||
sensor.depthFrameReceived.listen {
|
||||
it.copyTo(depthFrame)
|
||||
}
|
||||
extend {
|
||||
sensor.waitForFrames()
|
||||
drawer.drawStyle.colorMatrix = tint(ColorRGBa.WHITE.shade(20.0))
|
||||
drawer.image(depthFrame)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,35 +11,33 @@ import org.openrndr.extra.realsense2.RS2Sensor
|
||||
*
|
||||
* Tested with two sensors, only uses depth stream now
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 1280
|
||||
height = 720
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 1280
|
||||
height = 720
|
||||
}
|
||||
program {
|
||||
val sensorDescriptions = RS2Sensor.listSensors()
|
||||
|
||||
val sensors = sensorDescriptions.map {
|
||||
it.open()
|
||||
}
|
||||
program {
|
||||
val sensorDescriptions = RS2Sensor.listSensors()
|
||||
|
||||
val sensors = sensorDescriptions.map {
|
||||
it.open()
|
||||
val depthFrames = sensors.map {
|
||||
colorBuffer(640, 480, format = ColorFormat.R, type = ColorType.UINT16)
|
||||
}
|
||||
sensors.forEachIndexed { index, it ->
|
||||
it.depthFrameReceived.listen {
|
||||
it.copyTo(depthFrames[index])
|
||||
}
|
||||
|
||||
val depthFrames = sensors.map {
|
||||
colorBuffer(640, 480, format = ColorFormat.R, type = ColorType.UINT16)
|
||||
}
|
||||
sensors.forEachIndexed { index, it ->
|
||||
it.depthFrameReceived.listen {
|
||||
it.copyTo(depthFrames[index])
|
||||
}
|
||||
}
|
||||
extend {
|
||||
drawer.drawStyle.colorMatrix = tint(ColorRGBa.WHITE.shade(20.0))
|
||||
for ((index, sensor) in sensors.withIndex()) {
|
||||
sensor.waitForFrames()
|
||||
drawer.image(depthFrames[index])
|
||||
drawer.translate(640.0, 0.0)
|
||||
}
|
||||
}
|
||||
extend {
|
||||
drawer.drawStyle.colorMatrix = tint(ColorRGBa.WHITE.shade(20.0))
|
||||
for ((index, sensor) in sensors.withIndex()) {
|
||||
sensor.waitForFrames()
|
||||
drawer.image(depthFrames[index])
|
||||
drawer.translate(640.0, 0.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import org.openrndr.application
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
fun main() = application {
|
||||
program {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user