-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathDemoTextWriter01.kt
53 lines (52 loc) · 2.04 KB
/
DemoTextWriter01.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
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.TextSettingMode
import org.openrndr.draw.isolated
import org.openrndr.draw.loadFont
import org.openrndr.extra.textwriter.writer
import org.openrndr.shape.Rectangle
import kotlin.math.cos
/**
* This demo features the drawing of a centered rectangle and the addition of styled text inside
* the rectangle. The application manages the drawing of shapes and implementation of text rendering
* with specific font and settings.
*
* The following operations are performed:
* - A rectangle is created from the center of the drawing bounds.
* - The rectangle is drawn without a fill and with a white stroke.
* - A custom font is loaded and applied to the drawer.
* - A `TextWriter` is utilized to display the text "hello world" inside the rectangle, adhering to
* specific styling and formatting rules.
*
* Key Components:
* - `application` establishes the visual environment.
* - `Rectangle` provides a way to define the rectangular area.
* - `drawer` enables isolated operations for drawing elements.
* - `writer` facilitates text rendering with alignment and spacing adjustments.
*/
fun main() {
application {
program {
extend {
val r = Rectangle.fromCenter(drawer.bounds.center, 200.0, 200.0)
drawer.isolated {
drawer.fill = null
drawer.stroke = ColorRGBa.WHITE
drawer.rectangle(r)
}
drawer.fontMap = loadFont("demo-data/fonts/IBMPlexMono-Regular.ttf", 24.0)
writer {
drawer.drawStyle.textSetting = TextSettingMode.SUBPIXEL
style.horizontalAlign = cos(seconds) * 0.5 + 0.5
box = r.offsetEdges(-10.0)
newLine()
text("hello world")
newLine()
text("this is a test")
newLine()
text("centered")
}
}
}
}
}