forked from g-harel/blobs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
126 lines (108 loc) · 2.95 KB
/
index.html
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
<!DOCTYPE html>
<head lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<title>blobs</title>
<script src="https://unpkg.com/blobs"></script>
</head>
<body>
<style>
body {
display: table;
font-family: monospace;
font-size: 1.1em;
height: 100%;
left: 0;
margin: 0;
position: absolute;
top: 0;
width: 100%;
}
.middle {
display: table-cell;
text-align: center;
vertical-align: middle;
}
main {
display: inline-block;
margin: 0 auto;
}
#blob {
display: inline-block;
vertical-align: middle;
}
#options {
display: inline-block;
font-size: 2em;
text-align: left;
vertical-align: middle;
}
#error {
color: #ec576b;
font-family: monospace;
font-size: 1.5em;
text-align: center;
}
@media (max-width: 320px) {
#blob {
display: block;
}
}
</style>
<div class="middle">
<main>
<div id="blob"></div><!--
--><pre id="options" contenteditable oninput="changed()">{
size: 600,
complexity: 0.2,
contrast: 0.4,
color: "#ec576b",
stroke: {
width: 0,
color: "black",
},
guides: false,
seed: "1234",
}</pre>
<div id="error"> </div>
</main>
</div>
<!-- Regenerate the blob from current options. -->
<script>
var blobElem = document.getElementById("blob");
var optionsElem = document.getElementById("options");
var errorElem = document.getElementById("error");
function refresh() {
if (!blobElem || !optionsElem || !errorElem) return;
var options = optionsElem.innerHTML;
var parsedOptions;
try {
parsedOptions = eval("(" + options + ")");
} catch (e) {
errorElem.innerHTML = "Could not parse options: " + e.toString();
console.warn(e);
return;
}
try {
blobElem.innerHTML = blobs(parsedOptions);
} catch (e) {
errorElem.innerHTML = e.toString();
console.warn(e);
}
}
// Immediate update when page is loaded.
refresh();
</script>
<!-- Wait for a pause in typing to refresh. -->
<script>
var delay = 400;
var timeout;
function changed() {
// Error state is removed when new input is detected.
errorElem.innerHTML = " ";
clearTimeout(timeout);
timeout = setTimeout(refresh, delay);
}
</script>
</body>
</html>