Display a grid of dragged and dropped images

Imports
import org.openrndr.application
import org.openrndr.draw.ColorBuffer
import org.openrndr.draw.loadImage
import org.openrndr.extra.imageFit.FitMethod
import org.openrndr.extra.imageFit.imageFit
import org.openrndr.extra.shapes.primitives.grid
import kotlin.math.ceil
import kotlin.math.roundToInt
import kotlin.math.sqrt
fun main() = application {
    configure {
        width = 1920
        height = 1920
    }
    program {
        val images = mutableListOf<ColorBuffer>()

        extend {
            val side = ceil(sqrt(images.size.toDouble())).roundToInt()
            drawer.bounds.grid(
                side, side, 50.0, 50.0, 20.0, 20.0
            ).flatten().take(images.size).forEachIndexed { i, rect ->
                drawer.imageFit(images[i], rect)
            }
        }

        window.drop.listen { event ->
            event.files.forEach {
                when(File(it).extension.lowercase()) {
                    "jpg", "jpeg", "png" -> images.add(loadImage(it))
                }
            }
        }
    }
}

I just started a program and thought this early version might show some interesting things, so sharing it here.

The only thing it does is to react to files dropped onto the program window. You can drop a bunch of files, and it will try to load and display jpg and png images as a grid. That’s it.

I like how simple it is :slight_smile: