-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
250 lines (213 loc) · 7.79 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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<title>
LED Matrix Simulator
</title>
<meta content="width=device-width, initial-scale=1" name="viewport">
<style>
body {
background-color: #2c3e50;
color: white;
}
button {
height: 25px;
width: 25px;
background-color: #0404047a;
border-radius: 50%;
display: inline-block;
border-style: none;
margin: 2px;
}
button:focus {
outline: 0;
}
.lit {
background-color: #ff0000;
}
a:visited {
color: green;
}
a:link {
color: red;
}
#framenumber {
width: 40px;
}
#framenum {
width: 40px;
}
#framespeed {
width: 60px;
}
#wh {
margin-top: 10px;
}
#frames {
margin-top: 5px;
}
</style>
</head>
<body>
<div style="text-align:center">
<h3>
LED Matrix Simulator
</h3>Click or click and drag across the LEDs to light them (Dragging wont work on mobile) - <a href="https://github.com/ToXIcGaming/LED-Matrix-Simulator" target="_blank">Fork on Github</a>
<br>
<form id="wh">
Width:
<input id="width" name="w" size="2" type="text" value=""> Height:
<input id="height" name="h" size="2" type="text" value="">
<input type="submit" value="Submit">
</form>
<br>
<input type="button" onclick="Clear()" value="Clear Lit LEDs"></input> |
<input type="button" onclick="ClearFrames()" value="Clear Saved Frames"> </input>
<br>
<br>
<input type="button" id="b2" onclick="FrameSave()" value="Frame Save"> </input> |
<input id="framenum" name="frame" type="number" value="">
<input type="button" id="b2" onclick="FrameUpdate(document.getElementById('framenum').value)" value="Frame Update"> </input> |
<input type="button" onclick="FramesPlay()" value="Play Saved Frames"> </input> |
<input type="button" onclick="FramesStop()" value="Stop Playing"> </input>
<br>
<br>
<div id="grid"></div>
<br> Enter Frame:
<input id="framenumber" name="frame" type="number" value="">
<input type="button" value="Load" onclick="Clear(); FrameLoad(document.getElementById('framenumber').value)"> Animation Speed (In ms):
<input id="framespeed" name="frspeed" type="number" value="350"> Loop:
<input type="checkbox" id="floop" checked>
<br>
<div id="frames"></div>
</div>
<script>
var url_string = window.location.href;
var url = new URL(url_string);
var MWidth = url.searchParams.get("w");
var MHeight = url.searchParams.get("h");
if (MWidth == null) {
var MWidth = 17
}
if (MHeight == null) {
var MHeight = 7
}
var MWidth = ++MWidth
var MHeight = ++MHeight
for (var i = 1; i < MHeight; i++) {
for (var i2 = 1; i2 < MWidth; i2++) {
var node = document.createElement("BUTTON");
node.setAttribute("id", i + "-" + i2);
document.getElementById("grid").appendChild(node);
}
var br = document.createElement("br");
document.getElementById("grid").appendChild(br);
}
$("button").on("mousedown mouseover", function(e) {
if (e.buttons == 1 || e.buttons == 3) {
$(this).toggleClass("lit")
}
})
function Clear() {
var elems = document.querySelectorAll(".lit");
[].forEach.call(elems, function(el) {
el.classList.remove("lit");
});
}
var FrameNum = 0
var FrameArr = [0];
function FrameSave() {
FrameNum++;
var className = document.getElementsByClassName('lit');
var classnameCount = className.length;
var IdStore = new Array();
for (var j = 0; j < classnameCount; j++) {
IdStore.push(className[j].id);
}
var json_str = JSON.stringify(IdStore);
localStorage.setItem('LMS_FR' + FrameNum, json_str);
Frame(FrameNum);
Frame();
}
function FrameUpdate(frame) {
var className = document.getElementsByClassName('lit');
var classnameCount = className.length;
var IdStore = new Array();
for (var j = 0; j < classnameCount; j++) {
IdStore.push(className[j].id);
}
var json_str = JSON.stringify(IdStore);
localStorage.setItem('LMS_FR' + frame, json_str);
}
function ClearFrames() {
var r = confirm("Are you sure you want to delete all saved frames?");
if (r == true) {
document.getElementById('frames').innerHTML = "Frames: 0";
FrameNum = 0
FrameArr = [0];
localStorage.clear();
} else {
}
}
function Frame(variable) {
if (typeof variable !== 'undefined') {
FrameArr.push(variable);
var json_str2 = JSON.stringify(FrameArr);
localStorage.setItem('LMS_FRAMES', json_str2);
} else {
if (localStorage.getItem('LMS_FRAMES') === null) {
document.getElementById('frames').innerHTML = "Frames: 0"
} else {
frames = localStorage.getItem('LMS_FRAMES');
document.getElementById('frames').innerHTML = "";
framesp = JSON.parse(frames)
document.getElementById('frames').innerHTML = "Frames: " + Math.max(...framesp);
}
}
}
var FTimeout;
var FTimeout2;
function FramesPlay() {
framespeed = document.getElementById('framespeed').value;
floop = document.getElementById("floop");
if (localStorage.getItem('LMS_FRAMES') === null) {
} else {
frames = localStorage.getItem('LMS_FRAMES');
framesp = JSON.parse(frames);
var i = 1, howManyTimes = Math.max(...framesp) + 1;
function f() {
Clear();
LitLed = localStorage.getItem('LMS_FR' + i);
LitLedJS = JSON.parse(LitLed)
LitLedJS.forEach(function(element) {
document.getElementById(element).classList.add('lit');
});
i++;
if (i < howManyTimes) {
FTimeout = setTimeout(f, framespeed);
}
}
f();
if (floop.checked) {
FTimeout2 = setTimeout(FramesPlay, 2000);
}
}
}
function FramesStop() {
clearTimeout(FTimeout);
clearTimeout(FTimeout2);
}
function FrameLoad(frame) {
LitLed = localStorage.getItem('LMS_FR' + frame);
LitLedJS = JSON.parse(LitLed)
LitLedJS.forEach(function(element) {
document.getElementById(element).classList.add('lit');
});
}
window.onload = Frame();
</script>
</body>
</html>