-
Notifications
You must be signed in to change notification settings - Fork 2
/
Mask002.kt
94 lines (86 loc) · 3.04 KB
/
Mask002.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
package examples.framework
import FilmGrain
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.*
import org.openrndr.extra.fx.blur.ApproximateGaussianBlur
import org.openrndr.extra.fx.patterns.Checkers
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 layer masking
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())
}
layer {
draw {
if (article.images.isNotEmpty()) {
drawer.imageFit(article.images[0], 0.0, 0.0, width * 1.0, height * 1.0)
}
}
post(FilmGrain())
}
layer {
// a layer inside a layer!
// I do this because the post() filters are applied before masking
// In the outer layer I use a drop shadow
layer {
draw {
if (article.images.isNotEmpty()) {
drawer.imageFit(article.images[0], 0.0, 0.0, width * 1.0, height * 1.0)
}
}
val font = loadFont("data/fonts/IBMPlexMono-Bold.ttf", 128.0)
mask {
drawer.fontMap = font
writer {
box = Rectangle(40.0, 40.0, width * 2 - 80.0, height * 2 - 80.0)
gaplessNewLine()
text(article.texts[0])
}
}
post(ApproximateGaussianBlur()).addTo(gui)
}
post(DropShadow()).addTo(gui)
}
}
onNewArticle.trigger(article)
gui.add(settings)
extend(gui)
extend {
composite.draw(drawer)
}
}
}