-
Notifications
You must be signed in to change notification settings - Fork 0
/
luxlogo.html
499 lines (448 loc) · 27.6 KB
/
luxlogo.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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="luxlogo.js - Luxeria Logo Generator written in Javascript">
<meta name="author" content="n0ctu">
<title>luxlogo.js - Luxeria Logo Generator</title>
<script src="js/luxlogo.js"></script>
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<!-- Bootstrap is only needed for the form, luxlogo.js does not depend on any external libraries -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
</head>
<body data-bs-theme="dark">
<div class="container py-5 text-center">
<h1>luxlogo.js</h1>
<p class="lead">A Javascript library to generate (per-) versions of the <a
href="https://luxeria.ch/">Luxeria</a> logo as SVG.<br /> This demo site provides a form for all the
parameters. Feel free to play with them!</p>
</div>
<div class="container">
<div class="row row-cols-1 row-cols-md-2 mb-3">
<div class="col-md-6">
<div class="card mb-4 rounded-3 shadow-sm">
<div class="card-header py-3">
<h4 class="my-0 fw-normal">Preview</h4>
</div>
<div class="card-body">
<div id="luxlogo">
<!-- generated SVG goes here -->
</div>
<div class="text-center">
<!--<button type="button" onclick="luxLogoUpdate()" class="btn btn-outline-success mb-2">Update ⟳</button>-->
<button type="button" onclick="luxLogoDownload('svg')" class="btn btn-success mb-2">Save (.svg)</button>
<button type="button" onclick="luxLogoDownload('png')" class="btn btn-success mb-2">Save (.png)</button>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card mb-4 rounded-3 shadow-sm">
<div class="card-header py-3">
<h4 class="my-0 fw-normal">Controls</h4>
</div>
<div class="card-body">
<form id="logoForm" onchange="luxLogoUpdate()" class="needs-validation" novalidate>
<!-- General controls -->
<div class="row">
<div class="col-md-6 mb-2">
<label for="size" class="form-label">Total Size:</label>
<div class="input-group">
<input type="number" id="size" class="form-control" value="512" required>
<span class="input-group-text">px</span>
</div>
<div class="invalid-feedback">Please provide a valid size.</div>
</div>
<div class="col-md-6 mb-2">
<label for="spacing" class="form-label">Spacing:</label>
<div class="input-group">
<input type="number" id="spacing" class="form-control" value="4" step="0.1" required>
<span class="input-group-text">%</span>
</div>
<div class="invalid-feedback">Please provide a valid spacing.</div>
</div>
<div class="col-md-6 mb-2">
<label for="numArrows" class="form-label">Number of Arrows:</label>
<div class="input-group">
<input type="number" id="numArrows" class="form-control" value="3" required>
<span class="input-group-text">#</span>
</div>
<div class="invalid-feedback">Please provide a valid number of arrows.</div>
</div>
<div class="col-md-6 mb-2">
<label for="rotation" class="form-label">Rotation:</label>
<div class="input-group">
<input type="number" id="rotation" class="form-control" value="0" required>
<span class="input-group-text">°</span>
</div>
<div class="invalid-feedback">Please provide a valid rotation.</div>
</div>
<div class="col-md-6 mb-2">
<label for="color2" class="form-label">Border Color:</label>
<div class="input-group">
<input type="color" id="color2" class="form-control" value="#198754" style="height: 38px;" required>
<span class="input-group-text">hex</span>
</div>
<div class="invalid-feedback">Please provide a valid color.</div>
</div>
<div class="col-md-6 mb-2">
<label for="borderThickness" class="form-label">Border Thickness:</label>
<div class="input-group">
<input type="number" id="borderThickness" class="form-control" value="0" step="0.1" required>
<span class="input-group-text">%</span>
</div>
<div class="invalid-feedback">Please provide a valid border thickness.</div>
</div>
<div class="col-md-6 mb-2">
<label for="color1" class="form-label">Fill Color:</label>
<div class="input-group">
<input type="color" id="color1" class="form-control" value="#eeeeee" style="height: 38px;" required>
<span class="input-group-text">hex</span>
</div>
<div class="invalid-feedback">Please provide a valid color.</div>
</div>
</div>
<!-- Circle controls -->
<div class="row mt-4">
<div class="col-md-6 mb-2">
<label for="innerCircleDiameter" class="form-label">Inner Circle Diameter:</label>
<div class="input-group">
<input type="number" id="innerCircleDiameter" class="form-control" value="24" required>
<span class="input-group-text">%</span>
</div>
<div class="invalid-feedback">Please provide a valid inner circle diameter.</div>
</div>
<div class="col-md-6 mb-2">
<label for="arcDiameter" class="form-label">Outer Circle Diameter:</label>
<div class="input-group">
<input type="number" id="arcDiameter" class="form-control" value="84" required>
<span class="input-group-text">%</span>
</div>
<div class="invalid-feedback">Please provide a valid outer circle diameter.</div>
</div>
<div class="col-md-6 mb-2">
<label for="arcThickness" class="form-label">Outer Ring Thickness:</label>
<div class="input-group">
<input type="number" id="arcThickness" class="form-control" value="12" required>
<span class="input-group-text">%</span>
</div>
<div class="invalid-feedback">Please provide a valid outer ring thickness.</div>
</div>
</div>
<!-- Arrow controls -->
<div class="row mt-4">
<div class="col-md-6 mb-2">
<label for="arrowTipWidth" class="form-label">Arrow Tip Width:</label>
<div class="input-group">
<input type="number" id="arrowTipWidth" class="form-control" value="24" required>
<span class="input-group-text">%</span>
</div>
<div class="invalid-feedback">Please provide a valid arrow tip width.</div>
</div>
<div class="col-md-6 mb-2">
<label for="arrowBaseWidth" class="form-label">Arrow Base Width:</label>
<div class="input-group">
<input type="number" id="arrowBaseWidth" class="form-control" value="12" required>
<span class="input-group-text">%</span>
</div>
<div class="invalid-feedback">Please provide a valid arrow base width.</div>
</div>
<div class="col-md-6 mb-2">
<label for="arrowTipStart" class="form-label">Arrow Tip Start (from center):</label>
<div class="input-group">
<input type="number" id="arrowTipStart" class="form-control" value="20" required>
<span class="input-group-text">%</span>
</div>
<div class="invalid-feedback">Please provide a valid arrow tip start position.</div>
</div>
<div class="col-md-6 mb-2">
<label for="arrowTipEnd" class="form-label">Arrow Tip End (from center):</label>
<div class="input-group">
<input type="number" id="arrowTipEnd" class="form-control" value="50" required>
<span class="input-group-text">%</span>
</div>
<div class="invalid-feedback">Please provide a valid arrow tip end position.</div>
</div>
<div class="col-md-6 mb-2">
<label for="arrowNotchOffset" class="form-label">Arrow Notch Offset:</label>
<div class="input-group">
<input type="number" id="arrowNotchOffset" class="form-control" value="2.4" step="0.1" required>
<span class="input-group-text">%</span>
</div>
<div class="invalid-feedback">Please provide a valid arrow notch offset.</div>
</div>
</div>
</form>
</div>
</div>
<div class="card mb-4 rounded-3 shadow-sm">
<div class="card-header py-3">
<h4 class="my-0 fw-normal">
Debug
<a onclick="toggleDebug()" class="text-muted"
style="cursor: pointer;">[toggle]</a>
</h4>
</div>
<div class="card-body" id="debugOutput" style="display: none;">
<h4>SVG XML</h4>
<textarea id="luxLogoXML" class="form-control mt-3" rows="10" readonly></textarea>
<hr />
<h4 class="mt-3">Absolute Dimensions</h4>
<h5 class="mt-3">General</h5>
<table class="table table-striped">
<thead>
<tr>
<th style="width: 50%;">Parameter</th>
<th style="width: 50%;">Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>Total Size:</td>
<td id="sizeOutput"></td>
</tr>
<tr>
<td>Spacing:</td>
<td id="spacingOutput"></td>
</tr>
<tr>
<td>Center is at:</td>
<td id="centerOutput"></td>
</tr>
<tr>
<td>Inner Circle (radius):</td>
<td id="innerCircleDiameterOutput"></td>
</tr>
<tr>
<td>Outer Circle (radius):</td>
<td id="arcDiameterOutput"></td>
</tr>
<tr>
<td>Outer Circle (thickness):</td>
<td id="arcThicknessOutput"></td>
</tr>
<tr>
<td>Arrow Tip Width:</td>
<td id="arrowTipWidthOutput"></td>
</tr>
<tr>
<td>Arrow Tip Start pos. (y):</td>
<td id="arrowTipStartOutput"></td>
</tr>
<tr>
<td>Arrow Tip End pos. (y):</td>
<td id="arrowTipEndOutput"></td>
</tr>
<tr>
<td>Arrow Notch Offset (y):</td>
<td id="arrowNotchOffsetOutput"></td>
</tr>
<tr>
<td>Arrow Base Width:</td>
<td id="arrowBaseWidthOutput"></td>
</tr>
</tbody>
</table>
<h5 class="mt-3">Arrow Calculations</h5>
<table class="table table-striped">
<thead>
<tr>
<th style="width: 50%;">Parameter</th>
<th style="width: 50%;">Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>Arrow Point Left (x / y):</td>
<td id="arrowPointLeftOutput"></td>
</tr>
<tr>
<td>Arrow Point Right (x / y):</td>
<td id="arrowPointRightOutput"></td>
</tr>
<tr>
<td>Arrow Point Tip (x / y):</td>
<td id="arrowPointTipOutput"></td>
</tr>
<tr>
<td>Arrow Point Notch Left (x / y):</td>
<td id="arrowPointNotchLeftOutput"></td>
</tr>
<tr>
<td>Arrow Point Notch Right (x / y):</td>
<td id="arrowPointNotchRightOutput"></td>
</tr>
<tr>
<td>Arrow Arc Radius:</td>
<td id="arrowArcRadiusOutput"></td>
</tr>
<tr>
<td>Arrow Arc Height:</td>
<td id="arrowArcHeightOutput"></td>
</tr>
<tr>
<td>Arrow Point Base Left (x / y):</td>
<td id="arrowPointBaseLeftOutput"></td>
</tr>
<tr>
<td>Arrow Point Base Right (x / y):</td>
<td id="arrowPointBaseRightOutput"></td>
</tr>
</tbody>
</table>
<h5 class="mt-3">Arc Calculations</h5>
<table class="table table-striped">
<thead>
<tr>
<th style="width: 50%;">Parameter</th>
<th style="width: 50%;">Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>Parallel Point 1 (x / y):</td>
<td id="parallelP1Output"></td>
</tr>
<tr>
<td>Parallel Point 2 (x / y):</td>
<td id="parallelP2Output"></td>
</tr>
<tr>
<td>Arc Point 1 (x / y):</td>
<td id="arcPoint1Output"></td>
</tr>
<tr>
<td>Arc Point 2 (x / y):</td>
<td id="arcPoint2Output"></td>
</tr>
<tr>
<td>Arc Point 3 (x / y):</td>
<td id="arcPoint3Output"></td>
</tr>
<tr>
<td>Arc Point 4 (x / y):</td>
<td id="arcPoint4Output"></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<footer class="pt-3 my-5 text-muted text-center">
<a href="https://luxeria.ch/">Luxeria.ch</a> - <a href="https://github.com/luxeria/luxlogo.js">Github</a> -
<a href="https://github.com/luxeria/luxlogo.js/blob/main/LICENSE">GNU GPL v3.0</a>
</footer>
</div>
<script>
// Reads the form and updates the logo
function luxLogoUpdate() {
// Read values from the form
luxLogo.size = parseFloat(document.getElementById("size").value);
luxLogo.color1 = document.getElementById("color1").value;
luxLogo.color2 = document.getElementById("color2").value;
luxLogo.rotation = parseFloat(document.getElementById("rotation").value);
luxLogo.numArrows = parseInt(document.getElementById("numArrows").value);
luxLogo.relSpacing = parseFloat(document.getElementById("spacing").value);
luxLogo.relBorderThickness = parseFloat(document.getElementById("borderThickness").value);
luxLogo.relInnerCircleDiameter = parseFloat(document.getElementById("innerCircleDiameter").value);
luxLogo.relArcDiameter = parseFloat(document.getElementById("arcDiameter").value);
luxLogo.relArcThickness = parseFloat(document.getElementById("arcThickness").value);
luxLogo.relArrowTipWidth = parseFloat(document.getElementById("arrowTipWidth").value);
luxLogo.relArrowTipStart = parseFloat(document.getElementById("arrowTipStart").value);
luxLogo.relArrowTipEnd = parseFloat(document.getElementById("arrowTipEnd").value);
luxLogo.relArrowNotchOffset = parseFloat(document.getElementById("arrowNotchOffset").value);
luxLogo.relArrowBaseWidth = parseFloat(document.getElementById("arrowBaseWidth").value);
// Generate the new SVG
if(luxLogo.generate()) {
// Update the debug output
luxLogoXML.innerHTML = luxLogo.outString;
updateDebugOutput();
}
}
function updateDebugOutput() {
// Update the debugging panel with newly calculated values
document.getElementById("sizeOutput").innerHTML = luxLogo.size + " px";
document.getElementById("spacingOutput").innerHTML = luxLogo.spacing + " px";
document.getElementById("centerOutput").innerHTML = luxLogo.center + " px";
document.getElementById("innerCircleDiameterOutput").innerHTML = luxLogo.innerCircleDiameter + " px";
document.getElementById("arcDiameterOutput").innerHTML = luxLogo.arcDiameter + " px";
document.getElementById("arcThicknessOutput").innerHTML = luxLogo.arcThickness + " px";
document.getElementById("arrowTipWidthOutput").innerHTML = luxLogo.arrowTipWidth + " px";
document.getElementById("arrowTipStartOutput").innerHTML = luxLogo.arrowTipStart + " px";
document.getElementById("arrowTipEndOutput").innerHTML = luxLogo.arrowTipEnd + " px";
document.getElementById("arrowNotchOffsetOutput").innerHTML = luxLogo.arrowNotchOffset + " px";
document.getElementById("arrowBaseWidthOutput").innerHTML = luxLogo.arrowBaseWidth + " px";
document.getElementById("arrowPointLeftOutput").innerHTML = luxLogo.arrowPointLeft.x + " px / " + luxLogo.arrowPointLeft.y + " px";
document.getElementById("arrowPointRightOutput").innerHTML = luxLogo.arrowPointRight.x + " px / " + luxLogo.arrowPointRight.y + " px";
document.getElementById("arrowPointTipOutput").innerHTML = luxLogo.arrowPointTip.x + " px / " + luxLogo.arrowPointTip.y + " px";
document.getElementById("arrowPointNotchLeftOutput").innerHTML = luxLogo.arrowPointNotchLeft.x + " px / " + luxLogo.arrowPointNotchLeft.y + " px";
document.getElementById("arrowPointNotchRightOutput").innerHTML = luxLogo.arrowPointNotchRight.x + " px / " + luxLogo.arrowPointNotchRight.y + " px";
document.getElementById("arrowArcRadiusOutput").innerHTML = luxLogo.arrowArcRadius + " px";
document.getElementById("arrowArcHeightOutput").innerHTML = luxLogo.arrowArcHeight + " px";
document.getElementById("arrowPointBaseLeftOutput").innerHTML = luxLogo.arrowPointBaseLeft.x + " px / " + luxLogo.arrowPointBaseLeft.y + " px";
document.getElementById("arrowPointBaseRightOutput").innerHTML = luxLogo.arrowPointBaseRight.x + " px / " + luxLogo.arrowPointBaseRight.y + " px";
document.getElementById("parallelP1Output").innerHTML = luxLogo.parallelP1.x + " px / " + luxLogo.parallelP1.y + " px";
document.getElementById("parallelP2Output").innerHTML = luxLogo.parallelP2.x + " px / " + luxLogo.parallelP2.y + " px";
document.getElementById("arcPoint1Output").innerHTML = luxLogo.arcPoint1.x + " px / " + luxLogo.arcPoint1.y + " px";
document.getElementById("arcPoint2Output").innerHTML = luxLogo.arcPoint2.x + " px / " + luxLogo.arcPoint2.y + " px";
document.getElementById("arcPoint3Output").innerHTML = luxLogo.arcPoint3.x + " px / " + luxLogo.arcPoint3.y + " px";
document.getElementById("arcPoint4Output").innerHTML = luxLogo.arcPoint4.x + " px / " + luxLogo.arcPoint4.y + " px";
}
function luxLogoDownload(type = 'svg') {
const luxLogoSvg = luxLogo.container.getElementsByTagName("svg")[0];
luxLogoSvg.setAttribute("height", luxLogo.size);
luxLogoSvg.setAttribute("width", luxLogo.size);
// Serialize the SVG element
const serializer = new XMLSerializer();
const svgString = serializer.serializeToString(luxLogoSvg);
// Download handler
function triggerDownload(blob, extension) {
const downloadLink = document.createElement("a");
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = "luxlogo_" + Date.now() + "." + extension;
document.body.appendChild(downloadLink);
downloadLink.click();
// Clean up
document.body.removeChild(downloadLink);
URL.revokeObjectURL(downloadLink.href);
}
if (type === 'svg') {
// Download as SVG
const svgBlob = new Blob([svgString], { type: "image/svg+xml;charset=utf-8" });
triggerDownload(svgBlob, 'svg');
} else if (type === 'png') {
// Convert SVG to PNG and download
const canvas = document.createElement('canvas');
canvas.width = luxLogo.size;
canvas.height = luxLogo.size;
const ctx = canvas.getContext('2d');
const img = new Image();
img.onload = () => {
ctx.drawImage(img, 0, 0);
canvas.toBlob((blob) => {
triggerDownload(blob, 'png');
});
};
img.src = 'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(svgString)));
}
// Clean up
luxLogoSvg.removeAttribute("height");
luxLogoSvg.removeAttribute("width");
}
function toggleDebug() {
const debugOutput = document.getElementById("debugOutput");
if (debugOutput.style.display === "none") {
debugOutput.style.display = "block";
} else {
debugOutput.style.display = "none";
}
}
// Initialization, new LuxLogo instance with the ID of the container
const luxLogo = new LuxLogo("luxlogo");
luxLogoUpdate();
</script>
</body>
</html>