-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAnimation003.kt
123 lines (111 loc) · 4.09 KB
/
Animation003.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
111
112
113
114
115
116
117
118
119
120
121
122
123
package examples.framework
import archives.LoadedArticle
import archives.localArchive
import org.openrndr.animatable.Animatable
import org.openrndr.animatable.easing.Easing
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.color.rgb
import org.openrndr.draw.loadFont
import org.openrndr.draw.tint
import org.openrndr.events.Event
import org.openrndr.extra.compositor.compose
import org.openrndr.extra.compositor.layer
import org.openrndr.extra.compositor.draw
import org.openrndr.extra.compositor.post
import org.openrndr.extra.fx.blur.ApproximateGaussianBlur
import org.openrndr.extra.fx.shadow.DropShadow
import org.openrndr.extra.gui.GUI
import org.openrndr.extra.gui.addTo
import org.openrndr.extra.parameters.ActionParameter
import org.openrndr.extra.parameters.Description
import org.openrndr.extras.imageFit.imageFit
import org.openrndr.shape.Rectangle
import org.openrndr.writer
// This demonstrates animating post filter properties
fun main() = application {
configure {
width = 600
height = 800
}
program {
val archive = localArchive("archives/example-poetry").iterator()
var article = archive.next()
val gui = GUI()
val onNewArticle = Event<LoadedArticle>()
val settings = @Description("Settings") object {
@ActionParameter("Next article")
fun nextArticle() {
article = archive.next()
onNewArticle.trigger(article)
}
}
val composite = compose {
var background = ColorRGBa.PINK
onNewArticle.listen {
background = rgb(Math.random(), Math.random(), Math.random())
}
// -- image layer
layer {
val animatable = object : Animatable() {
var opacity = 0.0
var blur = 0.0
}
onNewArticle.listen {
animatable.cancel()
animatable.opacity = 0.0
animatable.blur = 4.0
animatable.apply {
animate(::opacity, 1.0, 1000, Easing.CubicInOut)
animate(::blur, 0.0, 4000, Easing.CubicInOut)
}
}
draw {
animatable.updateAnimation()
if (article.images.isNotEmpty()) {
drawer.drawStyle.colorMatrix = tint(ColorRGBa.WHITE.opacify(animatable.opacity))
drawer.imageFit(article.images[0], 0.0, 0.0, width * 1.0, height * 1.0)
}
}
post(ApproximateGaussianBlur()) {
this.sigma = 0.001 + animatable.blur
this.window = 10
}
}
// -- text layer
layer {
val animatable = object : Animatable() {
var opacity = 0.0
}
onNewArticle.listen {
animatable.cancel()
animatable.delay(500)
animatable.opacity = 0.0
animatable.apply {
animate(::opacity, 1.0, 1000, Easing.CubicInOut)
}
}
val font = loadFont("data/fonts/IBMPlexMono-Bold.ttf", 32.0)
draw {
animatable.updateAnimation()
if (article.texts.isNotEmpty()) {
drawer.fontMap = font
drawer.fill = ColorRGBa.WHITE.opacify(animatable.opacity)
writer {
box = Rectangle(40.0, 40.0, width - 80.0, height - 80.0)
gaplessNewLine()
text(article.texts[0])
}
}
}
post(DropShadow()).addTo(gui, "2. Drop shadow")
}
}
onNewArticle.trigger(article)
gui.add(settings)
extend(gui)
extend {
composite.draw(drawer)
}
}
}