Fixes and move to jvmDemo (#286)

This commit is contained in:
Vechro
2023-01-15 16:27:19 +02:00
committed by GitHub
parent e27f7eb4cb
commit 47d4293a57
117 changed files with 75 additions and 310 deletions

View File

@@ -0,0 +1,29 @@
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()
}
}
}

View File

@@ -0,0 +1,110 @@
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.*
import org.openrndr.extensions.SingleScreenshot
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()
}
// 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))
}
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
}
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)
// 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

@@ -0,0 +1,16 @@
import org.openrndr.application
import org.openrndr.draw.createEquivalent
import org.openrndr.draw.loadImage
import org.openrndr.extra.fx.edges.CannyEdgeDetector
fun main() = application {
program {
val image = loadImage("demo-data/images/image-001.png")
val ced = CannyEdgeDetector()
val edges = image.createEquivalent()
extend {
ced.apply(image, edges)
drawer.image(edges)
}
}
}

View File

@@ -0,0 +1,26 @@
import org.openrndr.extra.fx.color.Duotone
import org.openrndr.application
import org.openrndr.draw.createEquivalent
import org.openrndr.draw.loadImage
import org.openrndr.math.mod_
fun main() {
application {
program {
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)
}
}
}
}

View File

@@ -0,0 +1,25 @@
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.createEquivalent
import org.openrndr.draw.loadImage
import org.openrndr.extra.fx.color.DuotoneGradient
fun main() = application {
program {
val image = loadImage("demo-data/images/image-001.png")
val filteredImage = image.createEquivalent()
val duotone = DuotoneGradient()
duotone.labInterpolation = false
extend {
duotone.labInterpolation = true
duotone.backgroundColor0 = ColorRGBa.BLACK
duotone.foregroundColor0 = ColorRGBa.RED
duotone.backgroundColor1 = ColorRGBa.BLUE
duotone.foregroundColor1 = ColorRGBa.WHITE
duotone.rotation = seconds * 45.0
duotone.apply(image, filteredImage)
drawer.image(filteredImage)
}
}
}

View File

@@ -0,0 +1,25 @@
import org.openrndr.extra.fx.color.Duotone
import org.openrndr.application
import org.openrndr.draw.createEquivalent
import org.openrndr.draw.loadImage
import org.openrndr.extra.fx.color.Posterize
import org.openrndr.math.mod_
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)
}
}
}
}

View File

@@ -0,0 +1,63 @@
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.ColorType
import org.openrndr.draw.colorBuffer
import org.openrndr.draw.loadImage
import org.openrndr.extra.fx.Post
import org.openrndr.extra.fx.blur.DirectionalBlur
import org.openrndr.extra.fx.composite.then
import org.openrndr.extra.fx.grain.FilmGrain
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)
}
}
s.upload()
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
}
}
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

@@ -0,0 +1,38 @@
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.*
import org.openrndr.extra.fx.blur.DirectionalBlur
import org.openrndr.math.smoothstep
import kotlin.math.cos
import kotlin.math.sin
fun main() = application {
program {
val db = DirectionalBlur()
val rt = renderTarget(width, height) {
colorBuffer()
}
val blurred = colorBuffer(width, height)
val direction = colorBuffer(width, height, type = ColorType.FLOAT32)
val s = direction.shadow
for (y in 0 until height) {
for (x in 0 until width) {
val a = smoothstep(0.45, 0.55, cos((x + y) * 0.01) * 0.5 + 0.5)
s[x, y] = ColorRGBa(cos(y * .1) * a, sin(x * 0.1) * a, 0.0, 1.0)
}
}
s.upload()
val image = loadImage("demo-data/images/image-001.png")
extend {
drawer.isolatedWithTarget(rt) {
clear(ColorRGBa.BLACK)
drawer.image(image)
}
db.window = 10
db.apply(arrayOf(rt.colorBuffer(0), direction), blurred)
drawer.image(blurred)
}
}
}

View File

@@ -0,0 +1,24 @@
import org.openrndr.application
import org.openrndr.draw.createEquivalent
import org.openrndr.draw.loadImage
import org.openrndr.extra.fx.distort.Lenses
fun main() = application {
configure {
width = 640
height = 480
}
program {
val image = loadImage("demo-data/images/image-001.png")
val lenses = Lenses()
val edges = image.createEquivalent()
extend {
lenses.rotation = 0.0
lenses.scale = 1.5
lenses.apply(image, edges)
drawer.image(edges)
}
}
}

View File

@@ -0,0 +1,26 @@
import org.openrndr.application
import org.openrndr.draw.createEquivalent
import org.openrndr.draw.loadImage
import org.openrndr.extra.fx.dither.LumaHalftone
import org.openrndr.math.mod_
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

@@ -0,0 +1,31 @@
import org.openrndr.application
import org.openrndr.draw.colorBuffer
import org.openrndr.draw.createEquivalent
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()
val image = colorBuffer(width, height)
val distorted = image.createEquivalent()
checkers.size = 64.0
checkers.apply(emptyArray(), image)
if (System.getProperty("takeScreenshot") == "true") {
extend(SingleScreenshot()) {
this.outputFile = System.getProperty("screenshotPath")
}
}
extend {
fd.blend = mouse.position.x/width
fd.apply(image, distorted)
drawer.image(distorted)
}
}
}
}

View File

@@ -0,0 +1,64 @@
//import org.openrndr.application
//import org.openrndr.color.ColorRGBa
//import org.openrndr.extensions.SingleScreenshot
//import org.openrndr.extra.compositor.compose
//import org.openrndr.extra.compositor.draw
//import org.openrndr.extra.compositor.layer
//import org.openrndr.extra.compositor.post
//import org.openrndr.extra.fx.blur.GaussianBloom
//import org.openrndr.extra.fx.blur.LaserBlur
//import org.openrndr.extra.gui.GUI
//import org.openrndr.extra.gui.addTo
//import org.openrndr.extra.noise.simplex
//import org.openrndr.math.Vector2
//import kotlin.math.absoluteValue
//
//fun main() = application {
// configure {
// width = 1280
// height = 720
// }
//
// program {
// if (System.getProperty("takeScreenshot") == "true") {
// extend(SingleScreenshot()) {
// this.outputFile = System.getProperty("screenshotPath")
// }
// }
//
// val gui = GUI()
// val c = compose {
// layer {
// draw {
// drawer.fill = null
// drawer.strokeWeight = 4.0
// drawer.translate(width/2.0, height/2.0)
// drawer.rotate(seconds*45.0 + simplex(0, seconds)*45.0)
// drawer.translate(-width/2.0, -height/2.0)
// for (y in -1..1) {
// for (x in -1..1) {
// drawer.stroke = ColorRGBa.RED.toHSVa()
// .shiftHue(0.0 + simplex(500+x+y,seconds)*5.0)
// .shade(0.5 + 0.5 * simplex(300+x+y,seconds*4.0).absoluteValue)
// .toRGBa()
// val r = simplex(400+x+y, seconds) * 150.0 + 150.0
// drawer.circle(width / 2.0 + x * 100.0, height / 2.0 + y * 100.0, r)
// }
// }
// }
// post(LaserBlur()) {
// center = Vector2(simplex(2, seconds*0.1), simplex(100, seconds*0.1))
// aberration = simplex(5, seconds) * 0.01
// radius = simplex(7, seconds)
// }.addTo(gui)
// post(GaussianBloom()).addTo(gui)
// }
// }
// extend(gui) {
// doubleBind = true
// }
// extend {
// c.draw(drawer)
// }
// }
//}

View File

@@ -0,0 +1,27 @@
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
/**
* 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)
}
}
}
}

View File

@@ -0,0 +1,29 @@
import org.openrndr.WindowMultisample
import org.openrndr.application
import org.openrndr.extra.fx.Post
import org.openrndr.extra.fx.blend.Add
import org.openrndr.extra.fx.blur.ApproximateGaussianBlur
import org.openrndr.shape.Circle
import kotlin.math.cos
fun main() = application {
configure {
windowResizable = true
}
program {
extend(Post()) {
val blur = ApproximateGaussianBlur()
val add = Add()
post { input, output ->
blur.window = 50
blur.sigma = 50.0 * (cos(seconds) * 0.5 + 0.5)
blur.apply(input, intermediate[0])
add.apply(arrayOf(input, intermediate[0]), output)
}
}
extend {
drawer.circle(width / 2.0, height / 2.0, 100.0)
}
}
}