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:
Abe Pazos
2025-01-26 20:57:04 +01:00
parent 1975a820fc
commit c8f7dd52c6
116 changed files with 2889 additions and 2942 deletions

View File

@@ -1,29 +1,28 @@
import org.openrndr.application
import org.openrndr.extra.fx.blend.*
fun main() {
application {
program {
val add = Add()
val colorBurn = ColorBurn()
val colorDodge = ColorDodge()
val darken = Darken()
val destIn = DestinationIn()
val destOut = DestinationOut()
val destAtop = DestinationAtop()
val hardLight = HardLight()
val lighten = Lighten()
val multiply = Multiply()
val multiplyContrast = MultiplyContrast()
val normal = Normal()
val overlay = Overlay()
val passthrough = Passthrough()
val screen = Screen()
val sourceIn = SourceIn()
val sourceAtop = SourceAtop()
val sourceOut = SourceOut()
val subtract = Subtract()
val xor = Xor()
application.exit()
}
fun main() = application {
program {
val add = Add()
val colorBurn = ColorBurn()
val colorDodge = ColorDodge()
val darken = Darken()
val destIn = DestinationIn()
val destOut = DestinationOut()
val destAtop = DestinationAtop()
val hardLight = HardLight()
val lighten = Lighten()
val multiply = Multiply()
val multiplyContrast = MultiplyContrast()
val normal = Normal()
val overlay = Overlay()
val passthrough = Passthrough()
val screen = Screen()
val sourceIn = SourceIn()
val sourceAtop = SourceAtop()
val sourceOut = SourceOut()
val subtract = Subtract()
val xor = Xor()
application.exit()
}
}
}

View File

@@ -5,106 +5,117 @@ import org.openrndr.extra.fx.blur.*
import org.openrndr.math.Polar
import kotlin.math.sin
fun main() {
application {
program {
// In this buffer we will draw some simple shapes
val dry = renderTarget(width / 3, height / 3) {
colorBuffer()
fun main() = application {
program {
// In this buffer we will draw some simple shapes
val dry = renderTarget(width / 3, height / 3) {
colorBuffer()
}
// The list of effects to demo
val effects = listOf(
BoxBlur(),
ApproximateGaussianBlur(),
HashBlur(),
GaussianBlur(),
GaussianBloom(),
FrameBlur(),
ZoomBlur(),
LaserBlur()
)
// On this buffer we will draw the dry buffer with an effect applied
val wet = colorBuffer(dry.width, dry.height)
val font = loadFont("demo-data/fonts/IBMPlexMono-Regular.ttf", 16.0)
extend {
// Draw two moving circles
drawer.isolatedWithTarget(dry) {
clear(ColorRGBa.BLACK)
fill = null
stroke = ColorRGBa.PINK
strokeWeight = 25.0
circle(
bounds.center +
Polar(seconds * 50.0, 100.0).cartesian,
200.0 + 50.0 * sin(seconds * 2.0)
)
fill = ColorRGBa.PINK
stroke = null
circle(
bounds.center +
Polar(seconds * 50.0 + 60, 100.0).cartesian,
100.0 + 20.0 * sin(seconds * 2.0 + 1)
)
}
// The list of effects to demo
val effects = listOf(
BoxBlur(),
ApproximateGaussianBlur(),
HashBlur(),
GaussianBlur(),
GaussianBloom(),
FrameBlur(),
ZoomBlur(),
LaserBlur()
)
effects.forEachIndexed { i, blur ->
// Adjust the effect settings.
// All the values could be animated.
when (blur) {
is BoxBlur -> {
blur.window = 30
}
// On this buffer we will draw the dry buffer with an effect applied
val wet = colorBuffer(dry.width, dry.height)
is ApproximateGaussianBlur -> {
blur.window = 25
blur.sigma = 15.0
}
val font = loadFont("demo-data/fonts/IBMPlexMono-Regular.ttf", 16.0)
is HashBlur -> {
blur.samples = 50
blur.radius = 5.0
blur.time = seconds
}
extend {
// Draw two moving circles
drawer.isolatedWithTarget(dry) {
clear(ColorRGBa.BLACK)
is GaussianBlur -> {
blur.window = 25
blur.sigma = 15.0
}
fill = null
stroke = ColorRGBa.PINK
strokeWeight = 25.0
circle(bounds.center +
Polar(seconds * 50.0, 100.0).cartesian,
200.0 + 50.0 * sin(seconds * 2.0))
is GaussianBloom -> {
blur.window = 5
blur.sigma = 3.0
blur.gain = 3.0
blur.noiseSeed = seconds
}
fill = ColorRGBa.PINK
stroke = null
circle(bounds.center +
Polar(seconds * 50.0 + 60, 100.0).cartesian,
100.0 + 20.0 * sin(seconds * 2.0 + 1))
is FrameBlur -> {
blur.blend = 0.05
}
is ZoomBlur -> {
blur.center = Polar(seconds * 77.0, 0.5)
.cartesian
blur.strength = 0.8
}
is LaserBlur -> {
blur.center = Polar(seconds * 77.0, 0.5)
.cartesian
blur.aberration = 0.03
blur.radius = 0.5
}
}
effects.forEachIndexed { i, blur ->
// Adjust the effect settings.
// All the values could be animated.
when (blur) {
is BoxBlur -> {
blur.window = 30
}
is ApproximateGaussianBlur -> {
blur.window = 25
blur.sigma = 15.0
}
is HashBlur -> {
blur.samples = 50
blur.radius = 5.0
blur.time = seconds
}
is GaussianBlur -> {
blur.window = 25
blur.sigma = 15.0
}
is GaussianBloom -> {
blur.window = 5
blur.sigma = 3.0
blur.gain = 3.0
blur.noiseSeed = seconds
}
is FrameBlur -> {
blur.blend = 0.05
}
is ZoomBlur -> {
blur.center = Polar(seconds * 77.0, 0.5)
.cartesian
blur.strength = 0.8
}
is LaserBlur -> {
blur.center = Polar(seconds * 77.0, 0.5)
.cartesian
blur.aberration = 0.03
blur.radius = 0.5
// Apply the effect on `dry` writing the result to `wet`
blur.apply(dry.colorBuffer(0), wet)
}
}
// Apply the effect on `dry` writing the result to `wet`
blur.apply(dry.colorBuffer(0), wet)
// Draw `wet` and write the effect name on top
drawer.isolated {
translate((i % 3) * width / 3.0,
(i / 3) * height / 3.0)
image(wet)
fontMap = font
text(blur.javaClass.simpleName, 20.0, 30.0)
}
// Draw `wet` and write the effect name on top
drawer.isolated {
translate(
(i % 3) * width / 3.0,
(i / 3) * height / 3.0
)
image(wet)
fontMap = font
text(blur.javaClass.simpleName, 20.0, 30.0)
}
}
}
}
}
}

View File

@@ -3,19 +3,17 @@ import org.openrndr.draw.createEquivalent
import org.openrndr.draw.loadImage
import org.openrndr.extra.fx.color.Duotone
fun main() {
application {
program {
fun main() = application {
program {
val image = loadImage("demo-data/images/image-001.png")
val filteredImage = image.createEquivalent()
val duotone = Duotone()
val image = loadImage("demo-data/images/image-001.png")
val filteredImage = image.createEquivalent()
val duotone = Duotone()
extend {
duotone.labInterpolation = seconds.mod(2.0) < 1.0
duotone.apply(image, filteredImage)
drawer.image(filteredImage)
}
extend {
duotone.labInterpolation = seconds.mod(2.0) < 1.0
duotone.apply(image, filteredImage)
drawer.image(filteredImage)
}
}
}
}

View File

@@ -3,18 +3,16 @@ import org.openrndr.draw.createEquivalent
import org.openrndr.draw.loadImage
import org.openrndr.extra.fx.color.Posterize
fun main() {
application {
program {
val image = loadImage("demo-data/images/image-001.png")
val filteredImage = image.createEquivalent()
val posterize = Posterize()
fun main() = application {
program {
val image = loadImage("demo-data/images/image-001.png")
val filteredImage = image.createEquivalent()
val posterize = Posterize()
extend {
posterize.levels = 2
posterize.apply(image, filteredImage)
drawer.image(filteredImage)
}
extend {
posterize.levels = 2
posterize.apply(image, filteredImage)
drawer.image(filteredImage)
}
}
}
}

View File

@@ -5,17 +5,15 @@ import org.openrndr.draw.loadImage
import org.openrndr.extra.fx.colormap.GrayscaleColormap
import kotlin.math.sin
fun main() {
application {
program {
val colormap = GrayscaleColormap()
val image = loadImage("demo-data/images/image-001.png")
val colormapImage = image.createEquivalent(type = ColorType.FLOAT32)
extend {
colormap.curve = 1.0 + sin(seconds) * .5
colormap.apply(image, colormapImage)
drawer.image(colormapImage)
}
fun main() = application {
program {
val colormap = GrayscaleColormap()
val image = loadImage("demo-data/images/image-001.png")
val colormapImage = image.createEquivalent(type = ColorType.FLOAT32)
extend {
colormap.curve = 1.0 + sin(seconds) * .5
colormap.apply(image, colormapImage)
drawer.image(colormapImage)
}
}
}
}

View File

@@ -5,17 +5,15 @@ import org.openrndr.draw.loadImage
import org.openrndr.extra.fx.colormap.SpectralZucconiColormap
import kotlin.math.sin
fun main() {
application {
program {
val colormap = SpectralZucconiColormap()
val image = loadImage("demo-data/images/image-001.png")
val colormapImage = image.createEquivalent(type = ColorType.FLOAT32)
extend {
colormap.curve = 1.0 + sin(seconds) * .5
colormap.apply(image, colormapImage)
drawer.image(colormapImage)
}
fun main() = application {
program {
val colormap = SpectralZucconiColormap()
val image = loadImage("demo-data/images/image-001.png")
val colormapImage = image.createEquivalent(type = ColorType.FLOAT32)
extend {
colormap.curve = 1.0 + sin(seconds) * .5
colormap.apply(image, colormapImage)
drawer.image(colormapImage)
}
}
}
}

View File

@@ -5,17 +5,15 @@ import org.openrndr.draw.loadImage
import org.openrndr.extra.fx.colormap.TurboColormap
import kotlin.math.sin
fun main() {
application {
program {
val colormap = TurboColormap()
val image = loadImage("demo-data/images/image-001.png")
val colormapImage = image.createEquivalent(type = ColorType.FLOAT32)
extend {
colormap.curve = 1.0 + sin(seconds) * .5
colormap.apply(image, colormapImage)
drawer.image(colormapImage)
}
fun main() = application {
program {
val colormap = TurboColormap()
val image = loadImage("demo-data/images/image-001.png")
val colormapImage = image.createEquivalent(type = ColorType.FLOAT32)
extend {
colormap.curve = 1.0 + sin(seconds) * .5
colormap.apply(image, colormapImage)
drawer.image(colormapImage)
}
}
}
}

View File

@@ -11,53 +11,55 @@ import org.openrndr.extra.noise.*
import org.openrndr.math.smoothstep
import kotlin.math.cos
fun main() {
application {
program {
extend(Post()) {
// -- create a color buffer and fill it with random direction vectors
val direction = colorBuffer(width, height, type = ColorType.FLOAT32)
val s = direction.shadow
val n = simplex2D.bipolar().fbm().scaleShiftInput(0.01, 0.0, 0.01, 0.0).withVector2Output()
val ng = simplex2D.unipolar().scaleShiftInput(0.005, 0.0, 0.005, 0.0)
for (y in 0 until height) {
for (x in 0 until width) {
val a = smoothstep(0.4, 0.6, cos((x + y) * 0.01) * 0.5 + 0.5)
val nv = n(2320, x.toDouble(), y.toDouble()) * smoothstep(0.45, 0.55, ng(1032, x.toDouble(), y.toDouble()))
s[x, y] = ColorRGBa(nv.x, nv.y, 0.0, 1.0)
}
fun main() = application {
program {
extend(Post()) {
// -- create a color buffer and fill it with random direction vectors
val direction = colorBuffer(width, height, type = ColorType.FLOAT32)
val s = direction.shadow
val n = simplex2D.bipolar().fbm().scaleShiftInput(0.01, 0.0, 0.01, 0.0).withVector2Output()
val ng = simplex2D.unipolar().scaleShiftInput(0.005, 0.0, 0.005, 0.0)
for (y in 0 until height) {
for (x in 0 until width) {
val a = smoothstep(0.4, 0.6, cos((x + y) * 0.01) * 0.5 + 0.5)
val nv = n(2320, x.toDouble(), y.toDouble()) * smoothstep(
0.45,
0.55,
ng(1032, x.toDouble(), y.toDouble())
)
s[x, y] = ColorRGBa(nv.x, nv.y, 0.0, 1.0)
}
s.upload()
}
s.upload()
val directional = DirectionalBlur()
val directional = DirectionalBlur()
// -- create a bidirectional composite filter by using a directional filter twice
val bidirectional = directional.then(directional) {
firstParameters {
window = 50
perpendicular = false
}
secondParameters {
window = 3
perpendicular = true
}
// -- create a bidirectional composite filter by using a directional filter twice
val bidirectional = directional.then(directional) {
firstParameters {
window = 50
perpendicular = false
}
val grain = FilmGrain()
grain.grainStrength = 1.0
// -- create a grain-blur composite filter
val grainBlur = grain.then(bidirectional)
post { input, output ->
grainBlur.apply(arrayOf(input, direction), output)
secondParameters {
window = 3
perpendicular = true
}
}
val image = loadImage("demo-data/images/image-001.png")
extend {
drawer.image(image)
val grain = FilmGrain()
grain.grainStrength = 1.0
// -- create a grain-blur composite filter
val grainBlur = grain.then(bidirectional)
post { input, output ->
grainBlur.apply(arrayOf(input, direction), output)
}
}
val image = loadImage("demo-data/images/image-001.png")
extend {
drawer.image(image)
}
}
}
}

View File

@@ -3,23 +3,21 @@ import org.openrndr.draw.createEquivalent
import org.openrndr.draw.loadImage
import org.openrndr.extra.fx.dither.LumaHalftone
fun main() {
application {
program {
val image = loadImage("demo-data/images/image-001.png")
val filteredImage = image.createEquivalent()
val lumaHalftone = LumaHalftone()
extend {
lumaHalftone.rotation = -15.0
lumaHalftone.freq0 = 100.0
lumaHalftone.gain1 = 1.0
lumaHalftone.threshold = 0.5
lumaHalftone.phase0 = seconds*0.1
lumaHalftone.phase1 = -seconds*0.1
lumaHalftone.apply(image, filteredImage)
lumaHalftone.invert = seconds.mod(2.0) < 1.0
drawer.image(filteredImage)
}
fun main() = application {
program {
val image = loadImage("demo-data/images/image-001.png")
val filteredImage = image.createEquivalent()
val lumaHalftone = LumaHalftone()
extend {
lumaHalftone.rotation = -15.0
lumaHalftone.freq0 = 100.0
lumaHalftone.gain1 = 1.0
lumaHalftone.threshold = 0.5
lumaHalftone.phase0 = seconds * 0.1
lumaHalftone.phase1 = -seconds * 0.1
lumaHalftone.apply(image, filteredImage)
lumaHalftone.invert = seconds.mod(2.0) < 1.0
drawer.image(filteredImage)
}
}
}
}

View File

@@ -5,28 +5,26 @@ import org.openrndr.extensions.SingleScreenshot
import org.openrndr.extra.fx.distort.FluidDistort
import org.openrndr.extra.fx.patterns.Checkers
fun main() {
application {
program {
val fd = FluidDistort()
val checkers = Checkers()
fun main() = application {
program {
val fd = FluidDistort()
val checkers = Checkers()
val image = colorBuffer(width, height)
val distorted = image.createEquivalent()
checkers.size = 64.0
checkers.apply(emptyArray(), image)
val image = colorBuffer(width, height)
val distorted = image.createEquivalent()
checkers.size = 64.0
checkers.apply(emptyArray(), image)
if (System.getProperty("takeScreenshot") == "true") {
extensions.filterIsInstance<SingleScreenshot>().forEach {
it.delayFrames = 150
}
}
extend {
// Ensure >0.01 for a better screenshot
fd.blend = (mouse.position.x / width).coerceAtLeast(0.01)
fd.apply(image, distorted)
drawer.image(distorted)
if (System.getProperty("takeScreenshot") == "true") {
extensions.filterIsInstance<SingleScreenshot>().forEach {
it.delayFrames = 150
}
}
extend {
// Ensure >0.01 for a better screenshot
fd.blend = (mouse.position.x / width).coerceAtLeast(0.01)
fd.apply(image, distorted)
drawer.image(distorted)
}
}
}
}

View File

@@ -1,27 +1,25 @@
import org.openrndr.extra.fx.color.RgbToOkLab
import org.openrndr.extra.fx.color.OkLabToRgb
import org.openrndr.application
import org.openrndr.draw.ColorType
import org.openrndr.draw.createEquivalent
import org.openrndr.draw.loadImage
import org.openrndr.extra.fx.color.OkLabToRgb
import org.openrndr.extra.fx.color.RgbToOkLab
/**
* This demonstrates converting a [ColorBuffer] from and to (OK)LAB color space using the [RgbToOkLab] and [OkLabToRgb]
* filters. The (OK)Lab representation is signed and requires a floating point representation.
*/
fun main() {
application {
program {
val rgbToOkLab = RgbToOkLab()
val okLabToRgb = OkLabToRgb()
val image = loadImage("demo-data/images/image-001.png")
val labImage = image.createEquivalent(type = ColorType.FLOAT32)
rgbToOkLab.apply(image, labImage)
okLabToRgb.apply(labImage, image)
extend {
drawer.image(image)
}
fun main() = application {
program {
val rgbToOkLab = RgbToOkLab()
val okLabToRgb = OkLabToRgb()
val image = loadImage("demo-data/images/image-001.png")
val labImage = image.createEquivalent(type = ColorType.FLOAT32)
rgbToOkLab.apply(image, labImage)
okLabToRgb.apply(labImage, image)
extend {
drawer.image(image)
}
}
}
}

View File

@@ -8,38 +8,36 @@ import org.openrndr.extra.fx.patterns.Checkers
import org.openrndr.math.Vector2
import kotlin.math.sin
fun main() {
application {
configure {
width = 800
height = 800
fun main() = application {
configure {
width = 800
height = 800
}
program {
val a = drawImage(width, height) {
drawer.stroke = null
drawer.fill = ColorRGBa.BLUE
drawer.circle(drawer.bounds.center - Vector2(100.0, 0.0), drawer.width * 0.25)
}
program {
val a = drawImage(width, height) {
drawer.stroke = null
drawer.fill = ColorRGBa.BLUE
drawer.circle(drawer.bounds.center - Vector2(100.0, 0.0), drawer.width * 0.25)
}
val b = drawImage(width, height) {
drawer.clear(ColorRGBa.TRANSPARENT)
drawer.stroke = ColorRGBa.RED
drawer.strokeWeight = 10.0
drawer.fill = ColorRGBa.YELLOW.opacify(1.0)
drawer.circle(drawer.bounds.center + Vector2(100.0, 0.0), drawer.width * 0.25)
}
BoxBlur().apply { window = 10 }.apply(b, b)
val checked = a.createEquivalent()
Checkers().apply(emptyArray(), checked)
val b = drawImage(width, height) {
drawer.clear(ColorRGBa.TRANSPARENT)
drawer.stroke = ColorRGBa.RED
drawer.strokeWeight = 10.0
drawer.fill = ColorRGBa.YELLOW.opacify(1.0)
drawer.circle(drawer.bounds.center + Vector2(100.0, 0.0), drawer.width * 0.25)
}
BoxBlur().apply { window = 10 }.apply(b, b)
val checked = a.createEquivalent()
Checkers().apply(emptyArray(), checked)
val mixed = a.createEquivalent()
val blendSpectral = BlendSpectral()
extend {
drawer.image(checked)
blendSpectral.fill = sin(seconds) * 0.5 + 0.5
blendSpectral.clip = seconds.mod(4.0) > 2.0
blendSpectral.apply(a, b, mixed)
drawer.image(mixed)
}
val mixed = a.createEquivalent()
val blendSpectral = BlendSpectral()
extend {
drawer.image(checked)
blendSpectral.fill = sin(seconds) * 0.5 + 0.5
blendSpectral.clip = seconds.mod(4.0) > 2.0
blendSpectral.apply(a, b, mixed)
drawer.image(mixed)
}
}
}
}