forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdat-gui-tests.ts
175 lines (143 loc) · 4.24 KB
/
dat-gui-tests.ts
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/////////////////////////////////////////////////////////////
// http://workshop.chromeexperiments.com/examples/gui/
//////////////////////////////////////////////////////////////
/// <reference path="dat-gui.d.ts" />
// ------------ config
var FizzyText = function () {
return {
message: 'dat.gui',
speed: 0.8,
displayOutline: false,
explode: function () {},
noiseStrength: 0.5
// Define render logic ...
}
};
// ------------ 1. Basic Usage
() => {
window.onload = function () {
var text = FizzyText();
var gui = new dat.GUI();
gui.add(text, 'message');
gui.add(text, 'speed', -5, 5);
gui.add(text, 'displayOutline');
gui.add(text, 'explode');
};
}
// ------------ 2. Constraining Input
() => {
var text = FizzyText();
var gui = new dat.GUI();
gui.add(text, 'noiseStrength').step(5); // Increment amount
gui.add(text, 'growthSpeed', -5, 5); // Min and max
gui.add(text, 'maxSize').min(0).step(0.25); // Mix and match
// Choose from accepted values
gui.add(text, 'message', ['pizza', 'chrome', 'hooray']);
// Choose from named values
gui.add(text, 'speed', {Stopped: 0, Slow: 0.1, Fast: 5});
}
// ------------ 3. Folders
() => {
var text = FizzyText();
var gui = new dat.GUI();
var f1 = gui.addFolder('Flow Field');
f1.add(text, 'speed');
f1.add(text, 'noiseStrength');
var f2 = gui.addFolder('Letters');
f2.add(text, 'growthSpeed');
f2.add(text, 'maxSize');
f2.add(text, 'message');
f2.open();
}
// ------------ 4. Color Controllers
() => {
var FizzyText = function () {
return {
color0: "#ffae23", // CSS string
color1: [0, 128, 255], // RGB array
color2: [0, 128, 255, 0.3], // RGB with alpha
color3: {h: 350, s: 0.9, v: 0.3} // Hue, saturation, value
// Define render logic ...
}
};
window.onload = function () {
var text = FizzyText();
var gui = new dat.GUI();
gui.addColor(text, 'color0');
gui.addColor(text, 'color1');
gui.addColor(text, 'color2');
gui.addColor(text, 'color3');
};
}
// ------------ 5. Saving Values
() => {
var fizzyText = FizzyText();
var gui = new dat.GUI();
gui.remember(fizzyText);
}
// ------------ 6. Presets
() => {
var gui = new dat.GUI({
load: JSON,
preset: 'Flow'
});
}
// ------------ 7. Events
() => {
var fizzyText = FizzyText();
var gui = new dat.GUI();
var controller = gui.add(fizzyText, 'maxSize', 0, 10);
controller.onChange(function (value) {
// Fires on every change, drag, keypress, etc.
});
controller.onFinishChange(function (value) {
// Fires when a controller loses focus.
alert("The new value is " + value);
});
}
// ------------ 8. Custom Placement
() => {
var gui = new dat.GUI({autoPlace: false});
var customContainer = document.getElementById('my-gui-container');
customContainer.appendChild(gui.domElement);
}
// ------------ 9. Updating the Display Automatically
() => {
var fizzyText = FizzyText();
var gui = new dat.GUI();
gui.add(fizzyText, 'noiseStrength', 0, 100).listen();
var update = function () {
requestAnimationFrame(update);
fizzyText.noiseStrength = Math.random();
};
update();
}
// ------------ 10. Updating the Display Manually
() => {
var fizzyText = FizzyText();
var gui = new dat.GUI();
gui.add(fizzyText, 'noiseStrength', 0, 100);
var update = function () {
var dt = new Date();
requestAnimationFrame(update);
fizzyText.noiseStrength = Math.cos(dt.getTime());
// Iterate over all controllers
for (var i in gui.__controllers) {
gui.__controllers[i].updateDisplay();
}
};
update();
}
// ------------ 11. Object Literal Tests
() => {
var obj = {a:1,b:1};
var gui = new dat.GUI();
var controller = gui.add(obj, 'maxSize', 0, 10);
controller.onChange(function (value) {
// Fires on every change, drag, keypress, etc.
});
controller.onFinishChange(function (value) {
// Fires when a controller loses focus.
alert("The new value is " + value);
});
}