### Configuration Dialog Flow (OpenRNDR) Source: https://guide.openrndr.org/advancedTopics/applicationFlow This example demonstrates how to implement a startup configuration dialog in OpenRNDR before the main application starts. It involves defining settings, using an initial application block to potentially gather user input (though not shown here), and then a second application block to configure the main window using those settings. ```kotlin fun main() { val settings = object { var width: Int = 640 } // -- configuration application { program {// -- somehow get values in the settings object } } // -- application blocks until the window is closed application { // -- configure using the settings object configure { width = settings.width } program { } } } ``` -------------------------------- ### openFrameworks FPS Display Extension Example Source: https://guide.openrndr.org/extensions/writingExtensions An example of a simple `Extension` that displays the frames per second (FPS) on the program output. It overrides `setup` to initialize timing and `afterDraw` to render the FPS counter. ```kotlin class FPSDisplay : Extension { override var enabled: Boolean = true var frames = 0 var startTime: Double = 0.0 override fun setup(program: Program) { startTime = program.seconds } override fun afterDraw(drawer: Drawer, program: Program) { frames++ drawer.isolated { // -- set view and projections drawer.view = Matrix44.IDENTITY drawer.ortho() drawer.text("fps: ${frames / (program.seconds - startTime)}") } } } ``` -------------------------------- ### Setup Screenshots Extension - Kotlin Source: https://guide.openrndr.org/extensions/screenshots This code snippet demonstrates the basic setup for the Screenshots extension in an OpenRNDR application. It involves extending the program with the `Screenshots()` functionality. No external dependencies are required beyond the OpenRNDR library. ```kotlin fun main() = application { program { extend(Screenshots()) extend {// -- draw here } } } ``` -------------------------------- ### Configure Screenshots Extension - Kotlin Source: https://guide.openrndr.org/extensions/screenshots This example shows how to configure the Screenshots extension with custom options such as changing the triggering key, specifying a different output folder, and disabling asynchronous saving. It extends the basic setup with specific parameters within the `extend` block. ```kotlin fun main() = application { program { extend(Screenshots()) { key = "s" folder = "work-in-progress" async = false } extend {// -- draw here } } } ``` -------------------------------- ### Play Video from Camera Device with VideoPlayerFFMPEG Source: https://guide.openrndr.org/drawing/video Illustrates how to capture and display video from a default camera device using VideoPlayerFFMPEG.fromDevice(). The example initializes the player, starts playback, and renders the camera feed. For listing devices, VideoPlayerFFMPEG.listDeviceNames can be used. ```kotlin fun main() = application { program { val videoPlayer = VideoPlayerFFMPEG.fromDevice() videoPlayer.play() extend { drawer.clear(ColorRGBa.BLACK) videoPlayer.draw(drawer) } } } ``` -------------------------------- ### Basic Structure for Custom Application Configuration Source: https://guide.openrndr.org/programBasics/configure A template illustrating the basic structure for starting an OPENRNDR application with a custom configuration block, including placeholders for setup and drawing code. ```kotlin fun main() = application { configure { // settings go here } program { // -- one time set-up code goes here extend { // -- drawing code goes here } } } ``` -------------------------------- ### Basic OPENRNDR Extension Usage Source: https://guide.openrndr.org/extensions/extensions Demonstrates the fundamental way to add an extension, specifically the Screenshots extension, to an OPENRNDR application. This setup allows the extension to be active during the program's execution. ```kotlin fun main() = application { program { // -- one time setup code goes here extend(Screenshots()) extend { // -- drawing code goes here } } } ``` -------------------------------- ### Sequencing Animations with `complete()` in OpenRNDR Source: https://guide.openrndr.org/animation/interactiveAnimations This example demonstrates how to create a sequence of property animations using the `.complete()` method in OpenRNDR. It animates the 'x' property, completes it, and then animates the 'y' property, ensuring they run one after the other. ```kotlin fun main() = application { program { val animation = object : Animatable() { var x = 0.0 var y = 0.0 } animation.apply { ::x.animate(width.toDouble(), 5000) ::x.complete() ::y.animate(height.toDouble(), 5000) } extend { animation.updateAnimation() drawer.fill = ColorRGBa.PINK drawer.stroke = null drawer.circle(animation.x, animation.y, 100.0) } } } ``` -------------------------------- ### Listen to OSC Messages with Wildcards in Kotlin Source: https://guide.openrndr.org/ORX/OSC This snippet shows how to start an OSC server and install a listener for incoming OSC messages using the `orx-osc` library in Kotlin. It demonstrates listening to a specific address and extracting data, as well as using wildcard characters like '*' and '?' for pattern matching in OSC addresses. Dependencies include the `orx-osc` library. ```kotlin fun main() = application { program { val osc = OSC() osc.listen("/live/track/2") { addr, it -> // -- get the first value val firstValue = it[0] as Float } extend { } } } ``` -------------------------------- ### Equivalent Sequential Transforms in OPENRNDR Source: https://guide.openrndr.org/drawing/transformations Shows the equivalent sequential application of individual transformation operations that result in the same final model matrix as the `transform {}` builder example. ```kotlin drawer.rotate(32.0) drawer.rotate(Vector3(1.0, 1.0, 0.0).normalized, 43.0) drawer.translate(4.0, 2.0) drawer.scale(2.0) ``` -------------------------------- ### ValueNoise Generator Example in Kotlin Source: https://guide.openrndr.org/ORX/noise Shows how to utilize the ValueNoise filter to generate fractal noise. The example configures parameters like scale, gain, and octaves, then applies the noise to a color buffer for display. The noise parameters are adjusted within the extend block. ```kotlin fun main() = application { program { val cb = colorBuffer(width, height) val vn = ValueNoise() extend { vn.scale = Vector2.ONE * 4.0 vn.gain = Vector4.ONE * 0.5 vn.octaves = 8 vn.apply(emptyArray(), cb) drawer.image(cb) } } } ``` -------------------------------- ### Configuring OPENRNDR Extension Options Source: https://guide.openrndr.org/extensions/extensions Shows how to configure specific options for an OPENRNDR extension. In this example, the `contentScale` property of the Screenshots extension is set to 4.0. ```kotlin fun main() = application { program { extend(Screenshots()) { contentScale = 4.0 } } } ``` -------------------------------- ### Apply ApproximateGaussianBlur Filter using Kotlin Source: https://guide.openrndr.org/ORX/imageFilters This example shows how to use the ApproximateGaussianBlur filter. It loads an image, sets up the blur with adjustable window size and sigma, applies the filter, and displays the blurred image. ```kotlin fun main() = application { program { val image = loadImage("data/images/cheeta.jpg") val blurred = colorBuffer(image.width, image.height) val blur = ApproximateGaussianBlur() extend { blur.window = 25 blur.sigma = cos(seconds * 2) * 10.0 + 10.1 blur.apply(image, blurred) drawer.image(blurred) } } } ``` -------------------------------- ### Setup ScreenRecorder Extension in OpenRNDR Source: https://guide.openrndr.org/extensions/screenRecorder This snippet demonstrates the basic setup for the `ScreenRecorder` extension in an OpenRNDR application. It extends the program with the recorder, which will capture the program's output to a video file. The video file is automatically named and saved in the 'video/' directory. ```kotlin fun main() = application { program { extend(ScreenRecorder()) extend {// -- whatever you draw here ends up in the video } } } ``` -------------------------------- ### Animated Compositor with Blend and Post-Processing Source: https://guide.openrndr.org/ORX/compositor Shows how parameters for blends and post-processing filters, as well as layer contents, can be animated over time within the OpenRNDR compositor. This example animates circle positions and blur sigma. ```kotlin fun main() = application { program { val composite = compose { draw { drawer.fill = ColorRGBa.PINK drawer.stroke = null drawer.circle(width / 2.0 + sin(seconds * 2) * 100.0, height / 2.0, 175.0) } layer { blend(Add()) { clip = true } draw { drawer.fill = ColorRGBa.PINK drawer.stroke = null drawer.circle(width / 2.0, height / 2.0 + cos(seconds * 2) * 100.0, 100.0) } post(ApproximateGaussianBlur()) { // -- this is actually a function called for every draw window = 25 sigma = cos(seconds) * 10.0 + 10.01 } } } ``` -------------------------------- ### Drawing Lines with OpenRNDR Source: https://guide.openrndr.org/drawing/circlesRectanglesLines Shows how to draw single line segments using `lineSegment`. This example demonstrates setting the stroke color, stroke weight, and different line cap styles (ROUND, BUTT, SQUARE) to alter the appearance of the line endings. ```kotlin fun main() = application { configure { height = 300 } program { extend { drawer.clear(ColorRGBa.PINK) // -- setup line appearance drawer.stroke = ColorRGBa.BLACK drawer.strokeWeight = 5.0 drawer.lineCap = LineCap.ROUND drawer.lineSegment(10.0, height / 2.0 - 20.0, width - 10.0, height / 2.0 - 20.0) drawer.lineCap = LineCap.BUTT drawer.lineSegment(10.0, height / 2.0, width - 10.0, height / 2.0) drawer.lineCap = LineCap.SQUARE drawer.lineSegment(10.0, height / 2.0 + 20.0, width - 10.0, height / 2.0 + 20.0) } } } ``` -------------------------------- ### OPENRNDR: Integer-Sampled ColorBuffer Example Source: https://guide.openrndr.org/advancedTopics/integerColorBuffers This example demonstrates how to create a 1x1 ColorBuffer storing unsigned 16-bit integers, configure it for nearest-neighbor sampling, and use it with a shader that utilizes `usampler2D` to sample integer values directly. It also shows writing and reading byte data to/from the ColorBuffer. ```kotlin fun main() = application { configure { width = 640 height = 480 } program { val magicNumber: Byte = 42 // 1x1-pixel buffer holding one unsigned short / uint16 value val intColorBuffer = colorBuffer(1, 1, format = ColorFormat.R, type = ColorType.UINT16_INT) // the following line is crucial, non-nearest filtering will result in // sampling texels always equal to 0 in shaders intColorBuffer.filter(MinifyingFilter.NEAREST, MagnifyingFilter.NEAREST) // standard color buffer to match the output window size, with ColorType.UINT8 // by default, which is still sampled as a floating point number in shaders val imageColorBuffer = colorBuffer(width, height) // fragment shader to transform integer data into something visible // if input is matching the magic number, we are outputting whiteness // usampler2D is used for unsigned integer values val intInputRenderer = Filter(Shader.createFromCode(fsCode = """ #version 330 uniform usampler2D tex0; out vec4 color; const uint EXPECTED_VALUE = uint($magicNumber); void main() { uvec4 texel = texelFetch(tex0, ivec2(0), 0); color = vec4( vec3((texel.r == EXPECTED_VALUE) ? 1.0 : 0.0), 1.0 ); } """.trimIndent(), vsCode = Filter.filterVertexCode, name = "shader with usampler2D as input")) // in the same example we are also testing texture write / read val inData = ByteBuffer.allocateDirect(2) // 2 because we are storing shorts val outData = ByteBuffer.allocateDirect(2) inData.rewind() inData.put(magicNumber) inData.put(0) inData.rewind() intColorBuffer.write(inData) outData.rewind() intColorBuffer.read(outData) outData.rewind() println("outData should contain $magicNumber, is: ${outData.short}") extend { intInputRenderer.apply(intColorBuffer, imageColorBuffer) drawer.image(imageColorBuffer, 0.0, 0.0, width.toDouble(), height.toDouble()) } } } ``` -------------------------------- ### Apply PoissonFill to an Image Source: https://guide.openrndr.org/ORX/poissonFills This example shows how to apply the PoissonFill filter to an image. It loads an image and draws it, then applies the PoissonFill filter to the layer. This is useful for filling transparent or masked areas within an image. ```kotlin fun main() = application { program { val c = compose { layer { val image = loadImage("data/images/cheeta.jpg") draw { drawer.image(image, Rectangle((cos(seconds) * 0.5 + 0.5) * 100.0, (sin(seconds) * 0.5 + 0.5) * 100.0, 200.0, 200.0), Rectangle(width / 2 - 100.0, height / 2.0 - 100.0, 200.0, 200.0)) } post(PoissonFill()) } } extend { c.draw(drawer) } } } ``` -------------------------------- ### Basic Live Coding with orx-olive Source: https://guide.openrndr.org/useCases/liveCoding This example demonstrates the fundamental usage of orx-olive for live coding. It sets up a basic application window and allows for immediate visual updates when drawing properties, such as fill color, are modified in the script. ```kotlin fun main() = application { configure { width = 768 height = 576 } oliveProgram { extend { // drawer.fill = ColorRGBa.PINK drawer.rectangle(0.0, 0.0, 100.0, 200.0) } } } ``` -------------------------------- ### Initialize GUI Extension in OpenRNDR Source: https://guide.openrndr.org/ORX/quickUIs Demonstrates the basic workflow for initializing the orx-gui extension within an OpenRNDR application. It shows how to create a GUI instance and extend the program with it. ```kotlin fun main() = application { program { val gui = GUI() extend(gui) } } ``` -------------------------------- ### Enable MIDI Extension in build.gradle.kts Source: https://guide.openrndr.org/kotlinLanguageAndTools/gradle This example shows how to enable a specific extension, MIDI, within a Gradle build configuration file written in Kotlin. It involves uncommenting a line in the `build.gradle.kts` file. After the change, syncing Gradle projects in the IDE is necessary to download the required libraries. ```kotlin // Uncomment the line below to enable MIDI support // implementation("org.openrndr.extra:midi:0.4.0") ``` -------------------------------- ### Listen for MIDI Events with orx-midi Source: https://guide.openrndr.org/ORX/midiControllers This example illustrates how to listen for various MIDI events from a connected controller, such as note on/off, control changes, channel pressure, pitch bend, and program changes. It uses the `.listen` method on different event types provided by the `MidiDevice` object. Each listener prints details specific to the detected MIDI event. ```kotlin fun main() = application { program { val controller = openMidiDevice("BCR2000 [hw:2,0,0]") controller.controlChanged.listen { println("[control change] channel: ${it.channel}, control: ${it.control}, value: ${it.value}") } controller.noteOn.listen { println("[note on] channel: ${it.channel}, key: ${it.note}, velocity: ${it.velocity}") } controller.noteOff.listen { println("[note off] channel: ${it.channel}, key: ${it.note},") } controller.channelPressure.listen { println("[channel pressure] channel: ${it.channel}, pressure: ${it.pressure}") } controller.pitchBend.listen { println("[pitch bend] channel: ${it.channel}, pitch: ${it.pitchBend}") } controller.programChanged.listen { println("[program change] channel: ${it.channel}, program: ${it.program}") } } } ``` -------------------------------- ### Combine Multiple Translations in OpenRNDR Source: https://guide.openrndr.org/drawing/transformations Illustrates stacking multiple translation transformations to achieve complex movements. This example creates a combined horizontal and vertical motion, including a cosine wave effect. ```kotlin fun main() = application { configure { width = 770 height = 578 } program { extend { drawer.fill = ColorRGBa.PINK drawer.stroke = null // move the object to the vertical center of the screen drawer.translate(0.0, height / 2.0) // set up horizontal translation drawer.translate(seconds * 100.0, 0.0) // set up vertical translation drawer.translate(0.0, cos(seconds * Math.PI * 2.0) * 50.00) drawer.rectangle(-50.0, -50.0, 100.0, 100.00) } } } ``` -------------------------------- ### Play Video from File with VideoPlayerFFMPEG Source: https://guide.openrndr.org/drawing/video Demonstrates how to load a video file and play it using the VideoPlayerFFMPEG class. It initializes the player, starts playback, and draws the video frame in each program cycle. Assumes 'data/video.mp4' exists. ```kotlin fun main() = application { program { val videoPlayer = VideoPlayerFFMPEG.fromFile("data/video.mp4") videoPlayer.play() extend { drawer.clear(ColorRGBa.BLACK) videoPlayer.draw(drawer) } } } ``` -------------------------------- ### Applying Easing to Animations in OpenRNDR Source: https://guide.openrndr.org/animation/interactiveAnimations This example shows how to add easing to animations in OpenRNDR to make them less stiff. It applies `Easing.CubicInOut` to both the 'x' and 'y' property animations of a circle, creating a smoother visual effect. ```kotlin fun main() = application { program { val animation = object : Animatable() { var x = 0.0 var y = 0.0 } animation.apply { ::x.animate(width.toDouble(), 5000, Easing.CubicInOut) ::y.animate(height.toDouble(), 5000, Easing.CubicInOut) } extend { animation.updateAnimation() drawer.fill = ColorRGBa.PINK drawer.stroke = null drawer.circle(animation.x, animation.y, 100.0) } } } ``` -------------------------------- ### List Available MIDI Controllers with orx-midi Source: https://guide.openrndr.org/ORX/midiControllers This snippet demonstrates how to list all available MIDI devices connected to the system using the `listMidiDevices()` function. It iterates through the discovered devices and prints their name, vendor, and whether they support receiving or transmitting MIDI data. No external dependencies beyond the orx-midi library are required. ```kotlin fun main() = application { program { listMidiDevices().forEach { println("name: '${it.name}', vendor: '${it.vendor}', receiver:${it.receive}, transmitter:${it.transmit}") } } } ``` -------------------------------- ### Load and Draw Image - openFrameworks Source: https://guide.openrndr.org/drawing/images Demonstrates loading an image using `loadImage` and drawing it to the screen using `drawer.image`. Assumes an image file named 'cheeta.jpg' exists in the 'data/images/' directory. No specific input or output types are mentioned beyond the image data itself. ```kotlin fun main() = application { configure {} program { val image = loadImage("data/images/cheeta.jpg") extend { drawer.image(image) } } } ``` -------------------------------- ### Apply ColorCorrection Filter to Image using Kotlin Source: https://guide.openrndr.org/ORX/imageFilters This example demonstrates the ColorCorrection filter for adjusting hue, saturation, and brightness. It loads an image, initializes the ColorCorrection filter, and applies dynamic adjustments to these properties before displaying the result. ```kotlin fun main() = application { program { val image = loadImage("data/images/cheeta.jpg") val filter = ColorCorrection() val filtered = colorBuffer(image.width, image.height) extend { filter.hueShift = cos(seconds * 1) * 180.0 filter.saturation = cos(seconds * 2) filter.brightness = sin(seconds * 3) * 0.1 filter.apply(image, filtered) drawer.image(filtered) } } } ``` -------------------------------- ### Persistent State Management with orx-olive Source: https://guide.openrndr.org/useCases/liveCoding This example illustrates how to maintain persistent state across script reloads using orx-olive. It demonstrates persisting a Camera2D instance and a webcam connection, ensuring their state survives live code modifications. ```kotlin fun main() = application { oliveProgram { val camera by Once { persistent { Camera2D() } } extend(camera) extend { drawer.rectangle(0.0, 0.0, 100.0, 200.0) } } } ``` ```kotlin fun main() = application { oliveProgram { val webcam by Once { persistent { VideoPlayerFFMPEG.fromDevice() } } webcam.play() extend { webcam.colorBuffer?.let { drawer.image(it, 0.0, 0.0, 128.0, 96.0) } } } } ``` -------------------------------- ### Get Clipboard Content in OPENRNDR Source: https://guide.openrndr.org/interaction/clipboard This snippet shows how to retrieve the current text content from the system clipboard using the OPENRNDR clipboard API. The content is optional and may be null if the clipboard is empty or contains non-text data. ```kotlin fun main() = application { program { clipboard.contents?.let { println("the clipboard contents: $it") } } } ``` -------------------------------- ### Creating Div Layouts in Panel Source: https://guide.openrndr.org/interaction/userInterfaces Shows how to use the `Div` element, the primary building block for layouts in the OPENRNDR Panel library. This example demonstrates creating a `Div` with specified CSS classes and indicates where child elements would be placed within it, utilizing the `div {}` builder syntax. ```kotlin fun main() = application { program { controlManager { layout { div("some-class-here", "another-class-here") {// -- children here } } } } } ``` -------------------------------- ### Handle Character Input and Backspace in OPENRNDR Source: https://guide.openrndr.org/interaction/mouseAndKeyboardEvents Provides an example of using keyboard character events to build a string and handling the backspace key to remove characters. It combines listening for character input and key down events. ```kotlin fun main() = application { var input = "" program { keyboard.character.listen { input += it.character } keyboard.keyDown.listen { // -- it refers to a KeyEvent instance here // -- compare the key value to a predefined key constant if (it.key == KEY_BACKSPACE) { if (input.isNotEmpty()) { input = input.substring(0, input.length - 1) } } } } } ``` -------------------------------- ### Basic OPENRNDR Program Structure Source: https://guide.openrndr.org/programBasics/application This is the standard structure for an OPENRNDR program. It includes the main application block, which contains configuration and program execution logic. The 'configure' block is for setting up options, while the 'program' block contains the main loop executed by the 'extend' block. ```kotlin fun main() = application { configure { // set Configuration options here } program { // -- what is here is executed once extend { // -- what is here is executed 'as often as possible' } } } ``` -------------------------------- ### ADither Filter in OpenRNDR Source: https://guide.openrndr.org/ORX/imageFilters This example shows the ADither filter for creating dithered effects. It dynamically adjusts the filter's pattern and levels based on the elapsed time, producing varying dithering patterns and intensity. The filtered image is then displayed. ```kotlin fun main() = application { program { val image = loadImage("data/images/cheeta.jpg") val filter = ADither() val filtered = colorBuffer(image.width, image.height) extend { filter.pattern = ((seconds / 5.0) * 4).toInt().coerceAtMost(3) filter.levels = ((seconds % 1.0) * 3).toInt() + 1 filter.apply(image, filtered) drawer.image(filtered) } } } ``` -------------------------------- ### Apply HashBlur Filter to Image using Kotlin Source: https://guide.openrndr.org/ORX/imageFilters This example utilizes the HashBlur filter for applying a blur effect. It loads an image, sets up the HashBlur filter with adjustable samples and radius, applies it to a color buffer, and displays the blurred output. ```kotlin fun main() = application { program { val image = loadImage("data/images/cheeta.jpg") val blurred = colorBuffer(image.width, image.height) val blur = HashBlur() extend { blur.samples = 50 blur.radius = cos(seconds * 2) * 25.0 + 25.0 blur.apply(image, blurred) drawer.image(blurred) } } } ``` -------------------------------- ### Drawing Rectangles with OpenRNDR Source: https://guide.openrndr.org/drawing/circlesRectanglesLines Illustrates how to draw rectangles with different combinations of fill and stroke. It shows examples of rectangles with fill and stroke, only stroke, and only fill. The rectangle's position and dimensions are defined by x, y, width, and height parameters. ```kotlin fun main() = application { configure { height = 300 } program { extend { drawer.clear(ColorRGBa.PINK) // -- draw rectangle with white fill and black stroke drawer.fill = ColorRGBa.WHITE drawer.stroke = ColorRGBa.BLACK drawer.strokeWeight = 1.0 drawer.rectangle(width / 6.0 - width / 8.0, height / 2.0 - width / 8.0, width / 4.0, width / 4.0) // -- draw rectangle without fill, but with black stroke drawer.fill = null drawer.stroke = ColorRGBa.BLACK drawer.strokeWeight = 1.0 drawer.rectangle(width / 6.0 - width / 8.0 + width / 3.0, height / 2.0 - width / 8.0, width / 4.0, width / 4.0) // -- draw a rectangle with white fill, but without stroke drawer.fill = ColorRGBa.WHITE drawer.stroke = null drawer.strokeWeight = 1.0 drawer.rectangle(width / 6.0 - width / 8.0 + 2.0 * width / 3.0, height / 2.0 - width / 8.0, width / 4.0, width / 4.0) } } } ``` -------------------------------- ### Main Application Listening to Blob Events (Kotlin) Source: https://guide.openrndr.org/interaction/events A simple OpenRNDR application that instantiates the `Blob` class and listens to its `timeEvent` and `doneWaiting` events. The `extend` block is used to call the `blob.update()` method each frame. This setup demonstrates basic event listening. ```kotlin fun main() = application { program { val blob = Blob(this) extend { blob.update() } blob.timeEvent.listen { println("timeEvent triggered! $it") } blob.doneWaiting.listen { println("done waiting") } } } ``` -------------------------------- ### Process Video with Render Targets and Filters using VideoPlayerFFMPEG Source: https://guide.openrndr.org/drawing/video Demonstrates combining video playback with render targets and filters. This example blurs the video output before displaying it by drawing the video to a render target, applying a BoxBlur filter, and then drawing the blurred result. Assumes 'data/video.mp4' exists and 'width', 'height' are defined. ```kotlin fun main() = application { program { val videoPlayer = VideoPlayerFFMPEG.fromFile("data/video.mp4") val blur = BoxBlur() val renderTarget = renderTarget(width, height) { colorBuffer() } videoPlayer.play() extend { drawer.clear(ColorRGBa.BLACK) // -- draw the video on the render target drawer.withTarget(renderTarget) { videoPlayer.draw(drawer) } // -- apply a blur on the render target's color attachment blur.apply(renderTarget.colorBuffer(0), renderTarget.colorBuffer(0)) // -- draw the blurred color attachment drawer.image(renderTarget.colorBuffer(0)) } } } ``` -------------------------------- ### DisplaceBlend Composite Layer in OpenRNDR Source: https://guide.openrndr.org/ORX/imageFilters This example demonstrates creating a composite layer using DisplaceBlend. It layers an image with a dynamically sized animated rectangle, then applies the DisplaceBlend filter to blend them. The gain and rotation of the blend are animated, and the final composite is drawn. ```kotlin fun main() = application { program { val composite = compose { colorType = ColorType.FLOAT16 layer { val image = loadImage("data/images/cheeta.jpg") draw { drawer.imageFit(image, 0.0, 0.0, width * 1.0, height * 1.0) } } layer { draw { drawer.shadeStyle = linearGradient(ColorRGBa.BLACK, ColorRGBa.WHITE) drawer.stroke = null val size = cos(seconds * PI / 3) * 100.0 + 200.0 drawer.rectangle(width / 2.0 - size / 2, height / 2.0 - size / 2, size, size) } blend(DisplaceBlend()) { gain = cos(seconds * PI / 3) * 0.5 + 0.5 rotation = seconds * 60.0 } } } extend { composite.draw(drawer) } } } ``` -------------------------------- ### Apply Multiple Post-Effects to a Layer in OpenRNDR Source: https://guide.openrndr.org/ORX/compositor Demonstrates how to chain multiple post-processing effects (distortion, blur) to a single layer within an OpenRNDR application. This allows for complex visual transformations by applying effects sequentially. The example uses HorizontalWave, VerticalWave, and ApproximateGaussianBlur. ```Kotlin fun main() = application { program { val composite = compose { layer { // -- load the image inside the layer val image = loadImage("data/images/cheeta.jpg") draw { drawer.image(image) } } // -- add a second layer with text and a drop shadow layer { // -- notice how we load the font inside the layer // -- this only happens once val font = loadFont("data/fonts/default.otf", 112.0) draw { drawer.fill = ColorRGBa.BLACK drawer.fontMap = font val message = "HELLO WORLD" writer { box = Rectangle(0.0, 0.0, width * 1.0, height * 1.0) val w = textWidth(message) cursor = Cursor((width - w) / 2.0, height / 2.0) text(message) } } // -- this effect is processed first post(HorizontalWave()) { amplitude = cos(seconds * 3) * 0.1 frequency = sin(seconds * 2) * 4 segments = (1 + Math.random() * 20).toInt() phase = seconds } // -- this is the second effect post(VerticalWave()) { amplitude = sin(seconds * 3) * 0.1 frequency = cos(seconds * 2) * 4 segments = (1 + Math.random() * 20).toInt() phase = seconds } // -- and this effect is processed last post(ApproximateGaussianBlur()) { sigma = cos(seconds * 2) * 5.0 + 5.01 window = 25 } } } extend { composite.draw(drawer) } } } ``` -------------------------------- ### Apply ZoomBlur Filter to Image using Kotlin Source: https://guide.openrndr.org/ORX/imageFilters This example demonstrates the ZoomBlur filter for creating a zooming blur effect. It loads an image, initializes the ZoomBlur filter, and applies it with dynamic center and strength parameters, displaying the resulting zoomed blur. ```kotlin fun main() = application { program { val image = loadImage("data/images/cheeta.jpg") val blurred = colorBuffer(image.width, image.height) val blur = ZoomBlur() extend { blur.center = Vector2(cos(seconds) * 0.5 + 0.5, sin(seconds * 2) * 0.5 + 0.5) blur.strength = cos(seconds * 2) * 0.5 + 0.5 blur.apply(image, blurred) drawer.image(blurred) } } } ``` -------------------------------- ### DropShadow Image Filter in OpenRNDR Source: https://guide.openrndr.org/ORX/imageFilters Applies a drop shadow effect to an image using the DropShadow filter. The shadow's size and shift are animated. The filter can introduce transparency, hence a pink background is used in the example. It uses a render target to isolate the image before applying the shadow. ```kotlin fun main() = application { program { val image = loadImage("data/images/cheeta.jpg") val filter = DropShadow() val filtered = colorBuffer(image.width, image.height) val rt = renderTarget(width, height) { colorBuffer() } extend { drawer.isolatedWithTarget(rt) { drawer.clear(ColorRGBa.TRANSPARENT) drawer.image(image, (image.width - image.width * 0.8) / 2, (image.height - image.height * 0.8) / 2, image.width * 0.8, image.height * 0.8) } // -- need a pink background because the filter introduces transparent areas drawer.clear(ColorRGBa.PINK) filter.window = (cos(seconds) * 16 + 16).toInt() filter.xShift = cos(seconds * 2) * 16.0 filter.yShift = sin(seconds * 2) * 16.0 filter.apply(rt.colorBuffer(0), filtered) drawer.image(filtered) } } } ``` -------------------------------- ### Compositor Workflow with GUI in Kotlin Source: https://guide.openrndr.org/ORX/quickUIs Demonstrates setting up a GUI with custom parameters and using them to control a composited drawing. This workflow allows for real-time adjustment of visual elements like colors, positions, and effects through a graphical interface. It utilizes `orx-gui` for UI elements and `orx-compositor` for scene composition. ```kotlin fun main() = application { program { val gui = GUI() val settings = object { @DoubleParameter("x", 0.0, 770.0) var x: Double = 385.0 @DoubleParameter("y", 0.0, 500.0) var y: Double = 385.0 @DoubleParameter("separation", -150.0, 150.0) var separation: Double = 0.0 @ColorParameter("background") var background = ColorRGBa.PINK } gui.add(settings, "Settings") // -- create a composite val composite = compose { layer { draw { drawer.clear(settings.background) } } layer { layer { draw { drawer.fill = ColorRGBa.RED drawer.circle(settings.x - settings.separation, settings.y, 200.0) } } layer { draw { drawer.fill = ColorRGBa.BLUE drawer.circle(settings.x + settings.separation, settings.y, 200.0) } // -- add blend to layer and sidebar blend(gui.add(Multiply(), "Multiply blend"))// -- add a layer to the sidebar to toggle it on / off }.addTo(gui, "Blue layer") // -- add post to layer and sidebar post(gui.add(ApproximateGaussianBlur())) { sigma = sin(seconds) * 10.0 + 10.01 window = 25 } } } extend(gui) extend { composite.draw(drawer) } } } ``` -------------------------------- ### Looping Animations with Animatable in OpenRNDR Source: https://guide.openrndr.org/animation/interactiveAnimations Achieve looping animations in OpenRNDR by chaining animation sequences. This example shows how to continuously animate a property back and forth by calling 'animate' multiple times and using 'complete()' to ensure sequential execution. It requires the 'Animatable' class and a program loop. ```kotlin fun main() = application { val animation = object : Animatable() { var x: Double = 0.0 } program { extend { animation.updateAnimation() if (!animation.hasAnimations()) { animation.apply { ::x.animate(width.toDouble(), 1000, Easing.CubicInOut) ::x.complete() ::x.animate(0.0, 1000, Easing.CubicInOut) ::x.complete() } } drawer.fill = ColorRGBa.PINK drawer.stroke = null drawer.circle(animation.x, height / 2.0, 100.0) } } } ``` -------------------------------- ### SpeckleNoise Generator Example in Kotlin Source: https://guide.openrndr.org/ORX/noise Demonstrates how to use the SpeckleNoise generator to create speckle patterns on a color buffer. It initializes the generator, applies it to the buffer, and displays the result. The 'seed' parameter is updated dynamically with the elapsed time. ```kotlin fun main() = application { program { val cb = colorBuffer(width, height) val sn = SpeckleNoise() extend { sn.seed = seconds sn.apply(emptyArray(), cb) drawer.image(cb) } } } ``` -------------------------------- ### Slider Element Configuration and Events in Panel Source: https://guide.openrndr.org/interaction/userInterfaces Demonstrates the implementation of a `Slider` UI element in the OPENRNDR Panel library. This example configures the slider's label, range, initial value, and precision, and shows how to listen for the `valueChanged` event to react to user interactions. It also advises setting the range before the value for predictable behavior. ```kotlin fun main() = application { program { extend(ControlManager()) { layout { slider { label = "Slide me" range = Range(0.0, 1.0) value = 0.50 precision = 2 events.valueChanged.listen { println("the new value is ${it.newValue}") } } } } } } ``` -------------------------------- ### Basic Circle Animation with OpenRNDR Animatable Source: https://guide.openrndr.org/animation/interactiveAnimations This snippet shows a basic animation setup using OpenRNDR's Animatable class to move a circle horizontally across the screen. It initializes an animation object, applies a property animation to the 'x' property, and updates the animation in the drawing loop. ```kotlin fun main() = application { program { // -- create an animation object val animation = object : Animatable() { var x = 0.0 var y = 360.0 } animation.apply { ::x.animate(width.toDouble(), 5000) } extend { animation.updateAnimation() drawer.fill = ColorRGBa.PINK drawer.stroke = null drawer.circle(animation.x, animation.y, 100.0) } } } ``` -------------------------------- ### Load Binary File to ByteArray Source: https://guide.openrndr.org/fileIO Reads the entire content of a file as raw binary data into a ByteArray. This is typically used for non-text files like images or other binary assets. For large binary files, consider using `File.bufferedReader()`. ```kotlin val bytes = File("/path/to/file.txt").readBytes() ``` -------------------------------- ### Load Text File to String Source: https://guide.openrndr.org/fileIO Reads the entire content of a text file into a single String. This is suitable for smaller text files. For larger files, consider using `File.bufferedReader()`. ```kotlin val fileContent = File("/path/to/file.txt").readText() ``` -------------------------------- ### Slit Scanning Demonstration with Array Textures and Multiple Render Targets in OpenRNDR Source: https://guide.openrndr.org/drawing/arrayTextures This example demonstrates a slit scanning effect by utilizing a single array texture and a list of render targets, each rendering to a different layer of the array texture. It dynamically draws content to the current render target and then displays the array texture, creating a time-based visual effect. This technique is suitable for creating visualizers or effects that evolve over time. ```kotlin fun main() = application { program { val at = arrayTexture(770, 576, 116) val renderTargets = List(at.layers) { renderTarget(at.width, at.height) { arrayTexture(at, it) } } var index = 0 extend { drawer.clear(ColorRGBa.BLACK) drawer.isolatedWithTarget(renderTargets[index % renderTargets.size]) { drawer.clear(ColorRGBa.BLACK) drawer.fill = ColorRGBa.PINK.opacify(0.5) drawer.stroke = null for (i in 0 until 20) { drawer.circle(cos(seconds * 5.0 + i) * 256 + width / 2.0, sin(i + seconds * 6.32) * 256 + height / 2.0, 100.0) } } val layers = (0 until at.layers).map { (index - it).mod(at.layers) } val rectangles = (0 until at.layers).map { val span = Rectangle(0.0, it * 5.0, at.width * 1.0, 5.0) span to span } drawer.image(at, layers, rectangles) index++ } } } ``` -------------------------------- ### Using the Draw Style Stack Source: https://guide.openrndr.org/drawing/managingDrawStyle This example shows how to manage the draw style using a stack. `drawer.pushStyle()` saves the current style, modifications are applied, and `drawer.popStyle()` restores the previous style. This ensures style changes are localized. ```kotlin extend { drawer.pushStyle() drawer.fill = ColorRGBa.PINK drawer.rectangle(100.0, 100.0, 100.0, 100.0) drawer.popStyle() // colorMatrix, channelWriteMask, blendMode, quality, stencil, frontStencil, backStencil, clip drawer.drawStyle } ``` -------------------------------- ### ShapeContour Property Usage Example (Kotlin) Source: https://guide.openrndr.org/drawing/curvesAndShapes An example demonstrating the use of `.position()` and `.equidistantPositions()` methods of ShapeContour to draw animated circles along circular paths. It uses `seconds` for time-based animation and trigonometric functions to vary parameters. ```kotlin fun main() = application { program { extend { drawer.clear(ColorRGBa.WHITE) drawer.stroke = null drawer.fill = ColorRGBa.PINK val point = Circle(185.0, height / 2.0, 90.0).contour.position((seconds * 0.1) % 1.0) drawer.circle(point, 10.0) val points0 = Circle(385.0, height / 2.0, 90.0).contour.equidistantPositions(20) drawer.circles(points0, 10.0) val points1 = Circle(585.0, height / 2.0, 90.0).contour.equidistantPositions((cos(seconds) * 10.0 + 30.0).toInt()) drawer.circles(points1, 10.0) } } } ``` -------------------------------- ### Configure Window Size, Resizability, and Title Source: https://guide.openrndr.org/programBasics/configure This snippet demonstrates how to set the initial dimensions, enable window resizing, and define the title for an OPENRNDR application window using the `configure` block. ```kotlin fun main() = application { configure { width = 1280 height = 720 windowResizable = true title = "OPENRNDR Example" } program {} } ``` -------------------------------- ### Parse HTML/XML with Jsoup Source: https://guide.openrndr.org/fileIO Fetches a web page (e.g., Wikipedia) and parses its HTML content to extract specific elements, such as news headlines. The `jsoup` library is used for this purpose. Ensure the library is enabled in your `build.gradle.kts`. ```kotlin fun main() = application { program { val doc = Jsoup.connect("https://en.wikipedia.org/").get() println(doc.title()) val newsHeadlines = doc.select("#mp-itn b a") newsHeadlines.forEach { println(it.attr("title")) println(it.absUrl("href")) } } } ``` -------------------------------- ### Load Text File to List of Strings Source: https://guide.openrndr.org/fileIO Reads a text file line by line and returns each line as an element in a List. This is useful for processing files with multiple lines of text. For very large files, `File.bufferedReader()` might be more memory-efficient. ```kotlin val lines = File("/path/to/file.txt").readLines() ``` -------------------------------- ### Listen for 'a' Key Press in OPENRNDR Source: https://guide.openrndr.org/interaction/mouseAndKeyboardEvents Demonstrates listening for the `keyDown` event and checking if the pressed key's name is 'a'. ```kotlin fun main() = application { program { keyboard.keyDown.listen { // -- it refers to a KeyEvent instance here // -- compare the name value against "a" if (it.name == "a") {} } } } ```