-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
326 lines (273 loc) · 10.8 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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<title>LeWitt QR Code Generator</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="">
<style>
body {
font-family: 'Source Code Pro', monospace;
}
.inputClass {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
margin-top: 30vh;
text-align: center;
padding-left: 5vw;
padding-right: 5vw;
}
.result {
display: 'flex';
align-items: 'center';
justify-content: 'center';
text-align: left;
margin-top: 8vh;
padding-left: 10vw;
padding-right: 10vw;
margin-bottom: 10vh
}
a {
color: black
}
@import url('https://web.archive.org/web/20230512043741cs_/https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap');
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js" integrity="sha512-CNgIRecGo7nphbeZ04Sc13ka07paqdeTu0WR1IM4kNcpmBAUSHSQX0FslNhTDadL4O5SAGapGt4FodqL8My0mA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<body>
<div id="input" class="inputClass">
<h3>Hello, welcome to the Sol LeWitt QR Code Generator</h3>
<p>Input the QR code you want to make (max 8 characters) and you will get instructions for how to draw it.</p><br/>
<form id="qrForm">
<input type="text" id="qrSource" class="form-control" placeholder="max 8 characters">
<button type="submit">Submit</button>
</form>
</div>
<div id="result" class="result" hidden>
<!-- I would like this qrcode to be below the toggle, but it doesnt show if i do that -->
<div id="instructions" class="instructions">
<h2>Instructions for a QR Code</h2>
<h4><i>By WTTDOTM and you</i></h4>
<h5>Text and HTML/CSS/JS, 2024. <a href="javascript:toggleQRCode()">Toggle QR Code On/Off</a>. <a href="javascript:toggleInputVsInstructions()">Make a different code.</a></h4>
<div id="qrcode"></div>
<br/>
<hr>
<br/>
<p>Make a 21x21 square grid</p>
<p>Divide it into nine squares of 7x7 units each</p>
Within the upper left, upper right, and bottom left squares, make the same shape, a square with:<br/>
An internal black border one unit thick<br/>
A white border one unit thick within that black border<br/>
A black 3x3 square within that white border<br/>
</div>
<div id="fullInstructions"></div>
</div>
<script type="text/javascript">
//our only real variable
let qrText = ''
//utils
function toggleQRCode () {
if (document.getElementById('qrcode').style.display !== 'none') document.getElementById('qrcode').style.display = 'none'
else document.getElementById('qrcode').removeAttribute('style')
// document.getElementById('qrcode').hidden = !document.getElementById('qrcode').hidden
// document.getElementById('qrcode').hidden = !document.getElementById('qrcode').hidden
}
function toggleInputVsInstructions () {
//starting point:
if (document.getElementById('result').hidden) {
//idk why but the display setting works better than setting hidden
document.getElementById('input').style.display = 'none'
document.getElementById('result').hidden = false
} else {
document.getElementById('input').style.display = 'flex'
document.getElementById('result').hidden = true
}
console.log("after", document.getElementById('input').hidden)
}
//we rewrite this every time bc im lazy
const baseHTML = ` <h2>Instructions for a QR Code</h2>
<h4><i>By WTTDOTM and you</i></h4>
<h5>Text and HTML/CSS/JS, 2024. <a href="javascript:toggleQRCode()">Toggle QR Code On/Off</a>. <a href="javascript:toggleInputVsInstructions()">Make a different code.</a></h4>
<hr>
<p>Make a 21x21 square grid</p>
<p>Divide it into nine squares of 7x7 units each</p>
Within the upper left, upper right, and bottom left squares, make the same shape, a square with:<br/>
An internal black border one unit thick<br/>
A white border one unit thick within that black border<br/>
A black 3x3 square within that white border<br/>`
//meat of it
function makeNewQRInstructions () {
//Clear out old stuff
// document.getElementById('full').innerHTML = baseHTML
document.getElementById("fullInstructions").innerHTML = ''
document.getElementById("qrcode").innerHTML = ''
// const searchParams = new URLSearchParams(window.location.search);
// const qrText = searchParams.get('qrCode')
var qrcode = new QRCode(document.getElementById("qrcode"), {
text: qrText || "69",
width: 128,
height: 128,
colorDark : "#000000",
colorLight : "#ffffff",
correctLevel : QRCode.CorrectLevel.Q
});
// console.log(qrcode)
// document.getElementById('qrcode').hidden = true
document.getElementById('qrcode').style.display = 'none'
let qrAsTFArray = qrcode._oQRCode.modules
if (qrAsTFArray.length > 21) alert('2 big')
// console.log(qrcode._oQRCode.modules)
let positionToWordArr = ['first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'final']
function moreBlack (arr) {
let totalBlack = 0
let totalWhite = 0
arr.forEach(el => {
if (el) totalBlack++
else totalWhite++
})
return totalBlack > totalWhite ? true : false
}
function colToArr (arr, col) {
let colArr = []
arr.forEach(el => {
colArr.push(el[col])
})
return colArr
}
function describeArr (arr) {
let isMoreBlack = moreBlack(arr)
//this .find method is a bad way to do this but oh well
//row is all black
if (isMoreBlack && arr.find(el => el !== isMoreBlack) === undefined) return "black"
//row is all white
if (!isMoreBlack && arr.find(el => el !== isMoreBlack) === undefined) return "white"
//find all instances of minorityCells
let minorityCells = []
arr.forEach((cell, ind) => {
if (isMoreBlack && !cell) minorityCells.push(ind)
if (!isMoreBlack && cell) minorityCells.push(ind)
})
//cases (ironically the oxford comma makes this annoying):
switch (minorityCells.length) {
//1 min cell (__)
case 1:
return `${isMoreBlack ? 'black' : 'white'}, except the ${positionToWordArr[minorityCells[0]]} cell, which should be ${!isMoreBlack ? 'black' : 'white'}`
break
//2 min cells (_ and _)
case 2:
return `${isMoreBlack ? 'black' : 'white'}, except the ${positionToWordArr[minorityCells[0]]} and ${positionToWordArr[minorityCells[1]]} cells, which should be ${!isMoreBlack ? 'black' : 'white'}`
break
//3 min cells (_, __, and )
case 3:
return `${isMoreBlack ? 'black' : 'white'}, except the ${positionToWordArr[minorityCells[0]]}, ${positionToWordArr[minorityCells[1]]}, and ${positionToWordArr[minorityCells[2]]} cells, which should be ${!isMoreBlack ? 'black' : 'white'}`
}
}
function describeColumn (arr, col) {
let colAsArr = colToArr(arr, col)
let secondHalf = describeArr(colAsArr)
let returnedString = `Fill in the ${positionToWordArr[col]} column with ${secondHalf}`
document.getElementById("fullInstructions").innerHTML += returnedString + '<br>';
// console.log(returnedString)
}
function describeRow (arr, ind) {
let secondHalf = describeArr(arr)
let returnedString = `Fill in the ${positionToWordArr[ind]} row with ${secondHalf}`
document.getElementById("fullInstructions").innerHTML += returnedString + '<br>';
// console.log(returnedString)
}
// array splitting tedium
let topMiddleArr = []
for (let i = 0; i < 7; i++) {
let arrToPush = []
for (let j = 7; j < 14; j++) {
arrToPush.push(qrAsTFArray[i][j])
}
topMiddleArr.push(arrToPush)
}
let centerLeftArr = []
for (let i = 7; i < 14; i++) {
let arrToPush = []
for (let j = 0; j < 7; j++) {
arrToPush.push(qrAsTFArray[i][j])
}
centerLeftArr.push(arrToPush)
}
let centerMiddleArr = []
for (let i = 7; i < 14; i++) {
let arrToPush = []
for (let j = 7; j < 14; j++) {
arrToPush.push(qrAsTFArray[i][j])
}
centerMiddleArr.push(arrToPush)
}
let centerRightArr = []
for (let i = 7; i < 14; i++) {
let arrToPush = []
for (let j = 14; j < 21; j++) {
arrToPush.push(qrAsTFArray[i][j])
}
centerRightArr.push(arrToPush)
}
let bottomMiddleArr = []
for (let i = 14; i < 21; i++) {
let arrToPush = []
for (let j = 7; j < 14; j++) {
arrToPush.push(qrAsTFArray[i][j])
}
bottomMiddleArr.push(arrToPush)
}
let bottomRightArr = []
for (let i = 14; i < 21; i++) {
let arrToPush = []
for (let j = 14; j < 21; j++) {
arrToPush.push(qrAsTFArray[i][j])
}
bottomRightArr.push(arrToPush)
}
// row-based ones:
// centerLeftArr, centerRightArr, centerMiddleArr (either but easier to keep a row for middle consistency)
// col-based ones:
// topMiddleArr, bottomMiddleArr, bottomRightArr
function processColBasedArr (arr, pos) {
// console.log(`For the ${pos} square, fill it in as follows:`)
document.getElementById("fullInstructions").innerHTML += `<br/> For the ${pos} square, fill it in as follows: <br/>`;
// not using a forEach here bc we are technically not iterating thru the parent arr
for (let i = 0; i < arr.length; i++) {
describeColumn(arr, i)
}
}
function processRowBasedArr (arr, pos) {
// console.log(`For the ${pos} square, fill it in as follows:`)
document.getElementById("fullInstructions").innerHTML += `<br/> For the ${pos} square, fill it in as follows: <br/>`;
arr.forEach((el, ind) => describeRow(el, ind))
}
//do these in order, top to bottom, ltr
processColBasedArr(topMiddleArr, 'upper middle')
processRowBasedArr(centerLeftArr, 'center left')
processRowBasedArr(centerMiddleArr, 'center')
processRowBasedArr(centerRightArr, 'center right')
processColBasedArr(bottomMiddleArr, 'lower middle')
processColBasedArr(bottomRightArr, 'lower right')
}
//set up the QR Form after everything else has been defined
let qrForm = document.getElementById("qrForm");
// console.log(qrForm)
qrForm.addEventListener("submit", (e) => {
e.preventDefault();
let qrSource = document.getElementById("qrSource");
if (qrSource.value == "") {
alert('lol u forgot to enter something')
return
} else if (qrSource.length > 8) {
alert('too long plz choose dif input')
return
} else {
qrText = qrSource.value
toggleInputVsInstructions()
makeNewQRInstructions()
}
return
});
</script>
</body>
</html>