-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathDemoPresets01.kt
66 lines (60 loc) · 2.07 KB
/
DemoPresets01.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
import org.openrndr.KeyModifier
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.gui.GUI
import org.openrndr.extra.parameters.ColorParameter
import org.openrndr.extra.parameters.Description
import org.openrndr.extra.parameters.IntParameter
/**
* Shows how to store and retrieve in-memory gui presets.
* Keyboard controls:
* [Left Shift] + [0]..[9] => store current gui values to a preset
* [0]..[9] => recall a preset
*/
fun main() = application {
program {
val gui = GUI()
gui.compartmentsCollapsedByDefault = false
val presets = MutableList(10) {
gui.toObject()
}
val settings = @Description("Settings") object {
@IntParameter("a", 1, 10)
var a = 7
@IntParameter("b", 1, 10)
var b = 3
@ColorParameter("foreground")
var foreground = ColorRGBa.fromHex("654062")
@ColorParameter("background")
var background = ColorRGBa.fromHex("ff9c71")
}
gui.add(settings)
extend(gui)
extend {
drawer.clear(settings.background)
drawer.stroke = settings.background
drawer.fill = settings.foreground
// Draw a pattern based on modulo
for (i in 0 until 100) {
if (i % settings.a == 0 || i % settings.b == 0) {
val x = (i % 10) * 64.0
val y = (i / 10) * 48.0
drawer.rectangle(x, y, 64.0, 48.0)
}
}
}
keyboard.keyDown.listen {
when (it.name) {
in "0".."9" -> {
if (KeyModifier.SHIFT in it.modifiers) {
// 1. Get the current gui state, store it in a list
presets[it.name.toInt()] = gui.toObject()
} else {
// 2. Set the gui state
gui.fromObject(presets[it.name.toInt()])
}
}
}
}
}
}