forked from fxhash/fxhash-simple-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
91 lines (85 loc) · 1.94 KB
/
index.js
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
console.log(fxhash)
console.log(fxrand())
const sp = new URLSearchParams(window.location.search);
console.log(sp);
// this is how to define parameters
$fx.params([
{
id: "number_id",
name: "A number",
type: "number",
default: 1.2,
options: {
min: -2,
max: 10,
step: 0.1,
},
},
{
id: "select_id",
name: "A selection",
type: "select",
default: "pear",
options: {
options: ["apple", "orange", "pear"],
}
},
{
id: "color_id",
name: "A color",
type: "color",
default: "ff0000",
},
{
id: "boolean_id",
name: "A boolean",
type: "boolean",
default: true,
},
{
id: "string_id",
name: "A string",
type: "string",
default: "hello",
options: {
minLength: 1,
maxLength: 5
}
},
]);
// this is how features can be defined
$fx.features({
"A random feature": Math.floor($fx.rand() * 10),
"A random boolean": $fx.rand() > 0.5,
"A random string": ["A", "B", "C", "D"].at(Math.floor($fx.rand()*4)),
"Feature from params, its a number": $fx.getParam("number_id"),
})
// log the parameters, for debugging purposes, artists won't have to do that
console.log("Current param values:")
// Raw deserialize param values
console.log($fx.getRawParams())
// Added addtional transformation to the parameter for easier usage
// e.g. color.hex.rgba, color.obj.rgba.r, color.arr.rgb[0]
console.log($fx.getParams())
// how to read a single raw parameter
console.log("Single raw value:")
console.log($fx.getRawParam("color_id"));
// how to read a single transformed parameter
console.log("Single transformed value:")
console.log($fx.getParam("color_id"));
// update the document based on the parameters
document.body.style.background = $fx.getParam("color_id").hex.rgba
document.body.innerHTML = `
<p>
url: ${window.location.href}
</p>
<p>
hash: ${$fx.hash}
</p>
<p>
params:
</p>
<pre>
${JSON.stringify($fx.getRawParams(), null, 2)}
</pre>
`