-
Notifications
You must be signed in to change notification settings - Fork 2
/
LocalArchiveSkeleton.kt
82 lines (74 loc) · 2.47 KB
/
LocalArchiveSkeleton.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
package skeletons
import archives.LoadedArticle
import archives.localArchive
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.color.rgb
import org.openrndr.draw.loadFont
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.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
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 {
draw {
if (article.images.isNotEmpty()) {
drawer.imageFit(article.images[0], 0.0, 0.0, width * 1.0, height * 1.0)
}
}
}
// -- text layer
layer {
val font = loadFont("data/fonts/IBMPlexMono-Bold.ttf", 32.0)
draw {
if (article.texts.isNotEmpty()) {
drawer.fontMap = font
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)
}
}
}