-
Notifications
You must be signed in to change notification settings - Fork 37
/
DemoBlur01.kt
110 lines (99 loc) · 3.95 KB
/
DemoBlur01.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.*
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
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)
// 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)
}
}
}
}
}
}