-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
734 lines (720 loc) · 46.2 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
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
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
<!DOCTYPE html> <!-- February 2021 - RoccoLox Programs -->
<!--
Thank you Privacy_Dragon for your help.
Thank you mr womp womp and KMisthebomb for your code suggestions.
Thank you Zeroko for your rgb888 to rgb1555 (and vice versa) conversion code.
Thank you epsilon5 for your suggestions.
Thank you to anyone else who suggested features and has used this program.
-->
<html lang="en">
<head>
<meta charset="utf-8">
<title>Xlibc Color Picker</title>
<style type="text/css">
body {
background-color: rgb(243,243,243);
}
tr {
display: flex;
}
div {
cursor: pointer; /* thank you KMisthebomb */
width: 35px;
height: 35px;
border-style: none;
display: flex;
padding: 1px;
}
div.osColors {
display: flex;
padding: 1px;
width: 100%;
justify-content: center;
align-items: center;
color: #ffffff;
font-family: sans-serif;
font-weight: bold;
cursor: pointer;
height: 35px;
border-style: none;
}
div.table {
display: flex;
margin: 10px auto;
width: auto;
background-color: #000000;
border: solid black 1px;
height: fit-content;
justify-content: center;
border-radius: 5px;
}
table {
display: flex;
margin: auto;
justify-content: center;
border-style: hidden;
}
p {
text-align: center;
font-weight: bold;
font-size: 300%;
padding: 2%;
font-family: sans-serif;
margin: 20px auto 25px auto;
}
p#text {
border-radius: 5px;
}
p.rgb {
text-align: center;
font-family: sans-serif;
font-size: 45%;
margin: 0px;
padding: 10px 0px 0px 0px;
}
p.osRGB {
text-align: center;
font-family: sans-serif;
font-size: 125%;
border-radius: 0px 0px 5px 5px;
}
p#loadCustomPalette {
font-size: 150%;
padding: 0px;
margin: 0px;
}
h1 {
margin: 5px 0px 0px 0px;
text-align: center;
font-size: 250%;
font-family: sans-serif;
font-weight: normal;
text-decoration: underline;
}
h3 {
color: #000000;
margin: 0px;
cursor: pointer;
}
footer {
background-color: rgb(243,243,243);
bottom: 0px;
left: 0px;
position: fixed;
width: 100%;
}
a {
text-decoration: none;
color: #0179f9;
font-family: sans-serif;
font-size: 110%;
padding: 0px 5px 5px 5px;
}
h3#mode {
float: left;
padding-left: 5px;
cursor: text;
}
/* switch styling */
.switch {
position: relative;
display: inline-block;
width: 48px;
height: 22px;
}
.switch input {
opacity: 0%;
width: 0px;
height: 0px;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: #bebebe;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 16px;
width: 16px;
left: 4px;
bottom: 3px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider:before {
-webkit-transform: translateX(24px);
-ms-transform: translateX(24px);
transform: translateX(24px);
}
.slider.round {
border-radius: 22px;
}
.slider.round:before {
border-radius: 50%;
}
/* hover box styling */
.hoverBox:before {
content: attr(data-hover);
font-family: sans-serif;
visibility: hidden;
opacity: 0%;
width: max-content;
height: max-content;
background-color: #000000;
color: #ffffff;
text-align: center;
border-radius: 5px;
border: solid white 1px;
padding: 5px;
transition: opacity 0.8s ease-in-out;
position: relative;
z-index: 1;
left: 50%;
transform: translateX(-50%);
top: 110%;
}
.hoverBox:hover:before {
opacity: 100%;
visibility: visible;
}
/* button styling */
.customPalette {
margin-top: 5px;
background-color: #bebebe;
color: #000000;
padding: 8px;
font-family: sans-serif;
border-radius: 5px;
cursor: pointer;
font-size: 55%;
border: hidden;
font-weight: bold;
}
#uploadButton {
margin-right: 50px;
}
#paletteReset {
cursor: default;
color: #e9e9e9;
}
.copyButtons {
padding: 5px 15px;
margin: 0px;
font-size: 75%;
}
/* dropdown box styling */
.dropdown {
position: relative;
display: inline-block;
}
.dropdownButtons {
display: none;
position: absolute;
border-radius: 5px;
box-shadow: 3px 3px 5px 2px #666666;
width: fit-content;
padding: 8px;
top: 110%;
z-index: 1;
left: 50%;
transform: translateX(-50%);
}
.dropdownButtons input {
display: block;
width: 100%;
margin-bottom: 5px;
}
.show {
display: block;
}
@media screen and (max-width: 1152px) {
div {
cursor: pointer;
width: 20px;
height: 20px;
border-style: none;
display: flex;
padding: 1px;
}
.hoverBox:before {
content: attr(data-hover);
font-family: sans-serif;
font-size: 70%;
visibility: hidden;
opacity: 0%;
width: max-content;
height: max-content;
background-color: #000000;
color: #ffffff;
text-align: center;
border-radius: 2px;
border: solid white 1px;
padding: 3px;
transition: opacity 0.8s ease-in-out;
position: relative;
z-index: 1;
left: 0px;
top: 110%;
}
.hoverBox:hover:before {
opacity: 100%;
visibility: visible;
}
}
</style>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-JGXGWXXPLL"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-JGXGWXXPLL');
</script>
<script type="text/javascript">
// display xlibc colors
function color(n, r, g, b, hex, c1555) {
// remove TI-OS color box
document.getElementById('osRGB').setAttribute("style","padding: 0px; margin: 0px;");
document.getElementById('osRGB').innerHTML = '';
if (colorBrightness(r, g, b) > 164) {
if (localStorage.getItem("RLP_XlibcColorPicker_mode_090419") == 'light') { // for light mode
document.getElementById('text').setAttribute('style',`background-color: rgb(${r}, ${g}, ${b}); color: #000000; border: solid black thin;`); // display xlibc color
} else { // for dark mode
document.getElementById('text').setAttribute('style',`background-color: rgb(${r}, ${g}, ${b}); color: #000000; border: solid white thin;`);
}
} else {
if (localStorage.getItem("RLP_XlibcColorPicker_mode_090419") == 'light') { // for light mode
document.getElementById('text').setAttribute('style',`background-color: rgb(${r}, ${g}, ${b}); color: #ffffff; border: solid black thin;`); // display xlibc color
} else { // for dark mode
document.getElementById('text').setAttribute('style',`background-color: rgb(${r}, ${g}, ${b}); color: #ffffff; border: solid white thin;`);
}
}
c1555 = c1555.toString(16).toUpperCase(); // convert the 1555 value
// add additional 0's
if (c1555.length == 1) c1555 = '0x000' + c1555;
else if (c1555.length == 2) c1555 = '0x00' + c1555;
else if (c1555.length == 3) c1555 = '0x0' + c1555;
else if (c1555.length == 4) c1555 = '0x' + c1555;
document.getElementById('text').innerHTML = `${n}<br>${hex}<p class="rgb">R: ${r} G: ${g} B: ${b}<br>1555: ${c1555}</p>`; // display xlibc values
if (oldn > 265 && oldn < 270) document.getElementsByTagName('div')[oldn].setAttribute("style",`background-color: rgb(${oldr},${oldg},${oldb}); color: #000000;`); // remove selection box
else document.getElementsByTagName('div')[oldn].setAttribute("style",`background-color: rgb(${oldr}, ${oldg}, ${oldb});`);
if (colorBrightness(r, g, b) > 164) document.getElementsByTagName('div')[n].setAttribute("style",`background-color: rgb(${r}, ${g}, ${b}); border: solid black 1px; padding: 0px;`); // add selection box
else document.getElementsByTagName('div')[n].setAttribute("style",`background-color: rgb(${r}, ${g}, ${b}); border: solid white 1px; padding: 0px;`);
// copy variable values
copyDec = n;
copyHex = hex;
copyRGB = "r: " + r + ", g: " + g + ", b: " + b;
copy1555 = c1555;
copy565 = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
oldn = n;
oldr = r;
oldg = g;
oldb = b;
}
// display TI-OS colors
function OScolor(n, r, g, b, hex, or, og, ob, tagNum, c1555, OSc1555) {
// remove selection box
document.getElementsByTagName('div')[oldn].setAttribute("style",`background-color: rgb(${oldr}, ${oldg}, ${oldb});`);
if (tagNum > 265 && tagNum < 270) {
if (localStorage.getItem("RLP_XlibcColorPicker_mode_090419") == 'light') { // for light mode
document.getElementById('text').setAttribute('style',`background-color: rgb(${r}, ${g}, ${b}); color: #000000; border: solid black thin; padding: 0.5% 2%; margin: 20px 0px 0px 0px; border-bottom: hidden; border-radius: 5px 5px 0px 0px;`); // display xlibc equivalent
document.getElementById('osRGB').setAttribute('style',`background-color: rgb(${or}, ${og}, ${ob}); color: #000000; border: solid black thin; padding: 0.5% 2%; margin: 0px 0px 25px 0px; border-top: hidden;`); // display actual color
} else { // for dark mode
document.getElementById('text').setAttribute('style',`background-color: rgb(${r}, ${g}, ${b}); color: #000000; border: solid white thin; padding: 0.5% 2%; margin: 20px 0px 0px 0px; border-bottom: hidden; border-radius: 5px 5px 0px 0px;`);
document.getElementById('osRGB').setAttribute('style',`background-color: rgb(${or}, ${og}, ${ob}); color: #000000; border: solid white thin; padding: 0.5% 2%; margin: 0px 0px 25px 0px; border-top: hidden;`);
}
} else {
if (localStorage.getItem("RLP_XlibcColorPicker_mode_090419") == 'light') { // for light mode
document.getElementById('text').setAttribute('style',`background-color: rgb(${r}, ${g}, ${b}); color: #ffffff; border: solid black thin; padding: 0.5% 2%; margin: 20px 0px 0px 0px; border-bottom: hidden; border-radius: 5px 5px 0px 0px;`); // display xlibc equivalent
document.getElementById('osRGB').setAttribute('style',`background-color: rgb(${or}, ${og}, ${ob}); color: #ffffff; border: solid black thin; padding: 0.5% 2%; margin: 0px 0px 25px 0px; border-top: hidden;`); // display actual color1
} else { // for dark mode
document.getElementById('text').setAttribute('style',`background-color: rgb(${r}, ${g}, ${b}); color: #ffffff; border: solid white thin; padding: 0.5% 2%; margin: 20px 0px 0px 0px; border-bottom: hidden; border-radius: 5px 5px 0px 0px;`);
document.getElementById('osRGB').setAttribute('style',`background-color: rgb(${or}, ${og}, ${ob}); color: #ffffff; border: solid white thin; padding: 0.5% 2%; margin: 0px 0px 25px 0px; border-top: hidden;`);
}
}
document.getElementById('text').innerHTML = `${n}<br>${hex}<p class="rgb">R: ${r} G: ${g} B: ${b}<br>1555: ${c1555}</p>`; // xlibc equivalent color value
document.getElementById('osRGB').innerHTML = `R: ${or} G: ${og} B: ${ob}<br>1555: ${OSc1555}`; // display actual rgb value
if (oldn > 265 && oldn < 270) document.getElementsByTagName('div')[oldn].setAttribute("style",`background-color: rgb(${oldr}, ${oldg}, ${oldb}); color: #000000;`); // remove selection box
else document.getElementsByTagName('div')[oldn].setAttribute("style",`background-color: rgb(${oldr}, ${oldg}, ${oldb});`);
if (tagNum > 265 && tagNum < 270) document.getElementsByTagName('div')[tagNum].setAttribute("style",`background-color: rgb(${or}, ${og}, ${ob}); color: #000000; border: solid black 1px; padding: 0px;`); // add selection box
else document.getElementsByTagName('div')[tagNum].setAttribute("style",`background-color: rgb(${or}, ${og}, ${ob}); border: solid white 1px; padding: 0px;`);
// copy variable values
copyDec = n;
if (n != 0 && n != 255) {
copyDec = n.substr(1, n.length - 1);
}
copyHex = hex;
copyRGB = "r: " + or + ", g: " + og + ", b: " + ob;
copy1555 = OSc1555;
copy565 = ((or & 0xF8) << 8) | ((og & 0xFC) << 3) | (ob >> 3);
oldn = tagNum;
oldr = or;
oldg = og;
oldb = ob;
red = r;
green = g;
blue = b;
}
// mode changes
function changeMode() {
if (localStorage.getItem("RLP_XlibcColorPicker_mode_090419") == 'light') { // change mode
localStorage.setItem("RLP_XlibcColorPicker_mode_090419","dark");
darkMode();
} else {
localStorage.setItem("RLP_XlibcColorPicker_mode_090419","light");
lightMode();
}
}
function lightMode() {
document.getElementById('fileUpload').setAttribute("style","color: #000000;");
document.getElementById("body").setAttribute("style","background-color: rgb(243,243,243);"); // chanhe background
document.getElementsByTagName("footer")[0].setAttribute("style","background-color: rgb(243,243,243);"); // change footer background
document.getElementById("title").setAttribute("style","color: #000000;"); // change text color
document.getElementById('changeColorPicker').setAttribute('style','font-size: 100%; margin: 0px 0px 15px 0px; padding: 0px; font-weight: normal; color: #000000;');
document.getElementById("mode").setAttribute("style","color: #000000;");
document.getElementById("copyright").setAttribute("style","color: #808080; float: right; padding-left: 5px;");
document.getElementById("mode").innerHTML = 'Light Mode '; // change option
document.getElementById("OSColors").setAttribute("style","margin: 10px auto; border: solid black thin; background-color: #000000;"); // change border color
if (oldn > 255) { // if an OS color is being display
if (colorBrightness(oldr, oldg, oldb) > 164) {
document.getElementById('text').setAttribute('style',`background-color: rgb(${red}, ${green}, ${blue}); color: #000000; border: solid black thin; border-style: solid; padding: 0.5% 2%; margin: 20px 0px 0px 0px; border-bottom: hidden; border-radius: 5px 5px 0px 0px;`);
document.getElementById('osRGB').setAttribute('style',`background-color: rgb(${oldr}, ${oldg}, ${oldb}); color: #000000; border: solid black thin; padding: 0.5% 2%; margin: 0px 0px 25px 0px; border-top: hidden;`);
} else {
document.getElementById('text').setAttribute('style',`background-color: rgb(${red}, ${green}, ${blue}); color: #ffffff; border: solid black thin; solid; padding: 0.5% 2%; margin: 20px 0px 0px 0px; border-bottom: hidden; border-radius: 5px 5px 0px 0px;`);
document.getElementById('osRGB').setAttribute('style',`background-color: rgb(${oldr}, ${oldg}, ${oldb}); color: #ffffff; border: solid black thin; padding: 0.5% 2%; margin: 0px 0px 25px 0px; border-top: hidden;`);
}
} else { // else, just change the text foreground color
if (colorBrightness(oldr, oldg, oldb) > 164) document.getElementById("text").setAttribute("style",`background-color: rgb(${oldr}, ${oldg}, ${oldb}); color: #000000; border: solid black thin;`);
else document.getElementById("text").setAttribute("style",`background-color: rgb(${oldr}, ${oldg}, ${oldb}); color: #ffffff; border: solid black thin;`);
}
document.getElementById("TI").setAttribute("style","font-size: 170%; font-family: sans-serif; font-weight: bold; text-align: center; margin: 5px 0px 15px 0px; padding: 0px;"); // change text color
document.getElementById("loadCustomPalette").setAttribute("style","color: #000000;");
document.getElementById("dropdownBox").setAttribute("style","background-color: rgb(243,243,243); border: solid black 1px;");
document.getElementById("breakLine").setAttribute("style","color: #000000; float: right; cursor: default;");
}
function darkMode() {
document.getElementById('fileUpload').setAttribute("style","color: #ffffff;");
document.getElementById("body").setAttribute("style","background-color: rgb(40,40,40);"); // change background
document.getElementsByTagName("footer")[0].setAttribute("style","background-color: rgb(40,40,40);"); // change footer background
document.getElementById("title").setAttribute("style","color: #ffffff;"); // change text color
document.getElementById('changeColorPicker').setAttribute('style','font-size: 100%; margin: 0px 0px 15px 0px; padding: 0px; font-weight: normal; color: #ffffff;');
document.getElementById("mode").setAttribute("style","color: #ffffff;");
document.getElementById("copyright").setAttribute("style","color: #b3b3b3; float: right; padding-left: 5px;");
document.getElementById("mode").innerHTML = 'Dark Mode '; // change option
document.getElementById("OSColors").setAttribute("style","margin: 10px auto; border: solid white thin; background-color: #ffffff;"); // change border color
if (oldn > 255) { // if an OS color is being display
if (colorBrightness(oldr, oldg, oldb) > 164) {
document.getElementById('text').setAttribute('style',`background-color: rgb(${red}, ${green}, ${blue}); color: #000000; border: solid white thin; solid; padding: 0.5% 2%; margin: 20px 0px 0px 0px; border-bottom: hidden; border-radius: 5px 5px 0px 0px;`);
document.getElementById('osRGB').setAttribute('style',`background-color: rgb(${oldr}, ${oldg}, ${oldb}); color: #000000; border: solid white thin; padding: 0.5% 2%; margin: 0px 0px 25px 0px; border-top: hidden;`);
} else {
document.getElementById('text').setAttribute('style',`background-color: rgb(${red}, ${green}, ${blue}); color: #ffffff; border: solid white thin; border-style: solid; padding: 0.5% 2%; margin: 20px 0px 0px 0px; border-bottom: hidden; border-radius: 5px 5px 0px 0px;`);
document.getElementById('osRGB').setAttribute('style',`background-color: rgb(${oldr}, ${oldg}, ${oldb}); color: #ffffff; border: solid white thin; padding: 0.5% 2%; margin: 0px 0px 25px 0px; border-top: hidden;`);
}
} else { // else, just change the text foreground color
if (colorBrightness(oldr, oldg, oldb) > 164) document.getElementById("text").setAttribute("style",`background-color: rgb(${oldr}, ${oldg}, ${oldb}); color: #000000; border: solid white thin;`);
else document.getElementById("text").setAttribute("style",`background-color: rgb(${oldr}, ${oldg}, ${oldb}); color: #ffffff; border: solid white thin;`);
}
document.getElementById("TI").setAttribute("style","font-size: 170%; font-family: sans-serif; font-weight: bold; text-align: center; margin: 5px 0px 15px 0px; padding: 0px; color: #ffffff;"); // change text color
document.getElementById("loadCustomPalette").setAttribute("style","color: #ffffff;");
document.getElementById("dropdownBox").setAttribute("style","background-color: rgb(40,40,40); border: solid white 1px;");
document.getElementById("breakLine").setAttribute("style","color: #ffffff; float: right; cursor: default;");
}
// draw hover box
function hover(r, g, b, tagNum) {
onMouseOut(); // remove hover box
// deisplay new hover box
if (colorBrightness(r, g, b) > 164) {
document.getElementsByTagName('div')[tagNum].setAttribute('style',`background-color: rgb(${r}, ${g}, ${b}); border: solid black 1px; padding: 0px; color: #000000;`);
} else {
document.getElementsByTagName('div')[tagNum].setAttribute('style',`background-color: rgb(${r}, ${g}, ${b}); border: solid white 1px; padding: 0px;`);
}
// copy variable values
oldHover = tagNum;
oldHoverR = r;
oldHoverG = g;
oldHoverB = b;
}
function onMouseOut() { // when not over a table, remove the hover box
if ((oldHover != oldn) && oldHover < 256) document.getElementsByTagName('div')[oldHover].setAttribute('style',`background-color: rgb(${oldHoverR}, ${oldHoverG}, ${oldHoverB});`);
if ((oldHover != oldn) && oldHover > 255) {
if (oldHover > 265 && oldHover < 270) document.getElementsByTagName('div')[oldHover].setAttribute('style',`background-color: rgb(${oldHoverR}, ${oldHoverG}, ${oldHoverB}); color: #000000;`);
else document.getElementsByTagName('div')[oldHover].setAttribute('style',`background-color: rgb(${oldHoverR}, ${oldHoverG}, ${oldHoverB}); color: #ffffff;`);
}
}
function setDefaultPalette() {
colorLightness = 0;
red = 0, green = 0, blue = 0, oldn = 0, oldr = 0, oldg = 0, oldb = 0, oldHover = 0, oldHoverR = 0, oldHoverG = 0, oldHoverB = 0;
for (let colorNum = 0; colorNum < 256; colorNum++) {
let hex = '0x' + colorNum.toString(16).toUpperCase(); // find hex value of number
if (colorNum < 16) hex = '0x0' + colorNum.toString(16).toUpperCase();
let rgb565 = colorNum.toString(16);
if (rgb565.length == 1) rgb565 = '0' + rgb565;
rgb565 = rgb565 + rgb565;
rgb565 = parseInt(rgb565, 16);
// convert 565 to rgb
red = ((((rgb565 >> 11) & 0x1F) * 527) + 23) >> 6;
green = ((((rgb565 >> 5) & 0x3F) * 259) + 33) >> 6;
blue = (((rgb565 & 0x1F) * 527) + 23) >> 6;
// add attributes to the table columns
document.getElementsByTagName('div')[colorNum].setAttribute('style',`background-color: rgb(${red}, ${green}, ${blue});`);
document.getElementsByTagName('div')[colorNum].setAttribute('onmouseover',`hover(${red}, ${green}, ${blue}, ${colorNum})`);
var scaledGreen = Math.round(green * 63 / 255);
var c1555 = (Math.round(red * 31 / 255) << 10) | (scaledGreen << 15 & 0x8000) | (scaledGreen << 4 & 0x03E0) | Math.round(blue * 31 / 255);
document.getElementsByTagName('div')[colorNum].setAttribute('onclick',`color(${colorNum}, ${red}, ${green}, ${blue}, '${hex}', ${c1555})`);
}
document.getElementsByTagName('div')[0].setAttribute('style','background-color: rgb(0,0,0); border: solid white 1px; padding: 0px;');
copyDec = 0;
copyHex = "0x00";
}
// finds the perceived brightness of a color
function colorBrightness(red, green, blue) {
colorLightness = 0.299 * red + 0.587 * green + 0.114 * blue;
return colorLightness;
}
function resetTable(clear) {
if (!paletteLoaded) return;
if (clear) {
document.getElementById("fileUpload").value = null;
document.getElementById("paletteReset").setAttribute("style","");
} else {
document.getElementById("paletteReset").setAttribute("style","color: #000000; cursor: pointer;");
}
document.getElementById('osRGB').setAttribute("style","padding: 0px; margin: 0px;");
document.getElementById('osRGB').innerHTML = '';
if (localStorage.getItem("RLP_XlibcColorPicker_mode_090419") == 'light') document.getElementById("text").setAttribute("style",'background-color: #000000; color: #ffffff; border: solid black thin;');
else document.getElementById("text").setAttribute("style",'background-color: #000000; color: #ffffff; border: solid white thin;');
document.getElementById('text').innerHTML = '0<br>0x00<p class="rgb">R: 0 G: 0 B: 0<br>1555: 0x0000</p>';
if (oldn > 256) {
if (oldn > 265 && oldn < 270) document.getElementsByTagName('div')[oldn].setAttribute("style",`background-color: rgb(${oldr}, ${oldg}, ${oldb}); color: #000000;`);
else document.getElementsByTagName('div')[oldn].setAttribute("style",`background-color: rgb(${oldr}, ${oldg}, ${oldb});`);
}
setDefaultPalette();
copyRGB = "r: 0, g: 0, b: 0";
copy1555 = "0x0000";
copy565 = 0;
if (paletteLoaded && clear) paletteLoaded = false;
}
function dropdownButtons(buttonNumber) {
document.getElementById("dropdownBox").classList.toggle("show");
if (buttonNumber == 0) return;
if (buttonNumber == 1) {
navigator.clipboard.writeText(copyDec);
} else if (buttonNumber == 2) {
navigator.clipboard.writeText(copyHex);
} else if (buttonNumber == 3) {
navigator.clipboard.writeText(copyRGB);
} else if (buttonNumber == 4) {
navigator.clipboard.writeText(copy1555);
} else if (buttonNumber == 5) {
let c565 = copy565.toString(16).toUpperCase();
if (c565.length == 1) c565 = '0x000' + c565;
else if (c565.length == 2) c565 = '0x00' + c565;
else if (c565.length == 3) c565 = '0x0' + c565;
else if (c565.length == 4) c565 = '0x' + c565;
navigator.clipboard.writeText(c565);
} else if (buttonNumber == 6) {
let redHex = parseInt(oldr).toString(16).toUpperCase();
let greenHex = parseInt(oldg).toString(16).toUpperCase();
let blueHex = parseInt(oldb).toString(16).toUpperCase();
if (redHex.length == 1) redHex = '0' + redHex;
if (greenHex.length == 1) greenHex = '0' + greenHex;
if (blueHex.length == 1) blueHex = '0' + blueHex;
copy24Hex = redHex + greenHex + blueHex;
navigator.clipboard.writeText(copy24Hex);
}
}
window.onclick = function(event) {
if (!event.target.matches('.copyButtons')) {
let dropdowns = document.getElementsByClassName("dropdownButtons");
for (let i = 0; i < dropdowns.length; i++) {
let openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
function info() { // short description
alert("Xlibc Color Picker\nBy RoccoLox Programs\nVersion: 1.12\nDate: 2023-04-24\nLicense: BSD 3-Clause License\nDescription: Xlibc color picker for C and Assembly programmers on the TI-84 Plus CE.");
}
</script>
</head>
<body id="body">
<label class="switch" style="float: left;">
<input type="checkbox" id="switch" onclick="changeMode()">
<span class="slider round"></span>
</label>
<h3 id="mode">Light Mode </h3> <!-- mode indicator -->
<section class="dropdown">
<input type="button" value="Copy Values" class="customPalette copyButtons" onclick="dropdownButtons(0)">
<section id="dropdownBox" class="dropdownButtons" style="background-color: rgb(243,243,243); border: solid black 1px;">
<input type="button" value="Copy Decimal" class="customPalette copyButtons" onclick="dropdownButtons(1)">
<input type="button" value="Copy 8b Hex" class="customPalette copyButtons" onclick="dropdownButtons(2)">
<input type="button" value="Copy RGB" class="customPalette copyButtons" onclick="dropdownButtons(3)">
<input type="button" value="Copy 1555" class="customPalette copyButtons" onclick="dropdownButtons(4)">
<input type="button" value="Copy 565" class="customPalette copyButtons" onclick="dropdownButtons(5)">
<input type="button" value="Copy 24b Hex" class="customPalette copyButtons" onclick="dropdownButtons(6)" style="margin: 0px;">
</section>
</section>
<h3 id="copyright" style="color: #808080; float: right; padding-left: 5px;" onclick="info()"></h3>
<h3 style="color: #000000; float: right; cursor: default;" id="breakLine">|</h3>
<a href="https://github.com/RoccoLoxPrograms/XlibcColorPicker/blob/main/README.md" target="_blank" style="float: right;" title="See a list of features.">View ReadMe</a>
<br>
<h1 id="title">Xlibc Color Picker</h1>
<p id="changeColorPicker" style="font-size: 100%; margin: 0px 0px 15px 0px; padding: 0px; font-weight: normal;">
(<a href="https://roccoloxprograms.github.io/1555ColorPicker" style="padding: 0px;">1555 Color Picker</a>)
</p>
<table onmouseout="onMouseOut()" style="width: auto;">
<tbody>
<tr id="row0"></tr>
<tr id="row1"></tr>
<tr id="row2"></tr>
<tr id="row3"></tr>
<tr id="row4"></tr>
<tr id="row5"></tr>
<tr id="row6"></tr>
<tr id="row7"></tr>
</tbody>
</table>
<p id="text" style="background-color: #000000; color: #ffffff; border: solid black thin;"></p>
<p class="osRGB" id="osRGB" style="padding: 0px; margin: 0px;"></p> <!-- for displaying TI-OS color values -->
<div id="OSColors" class="table" onmouseout="onMouseOut()"> <!-- TI-OS color table -->
<div class="osColors" style="background-color: rgb(0,0,255);" onclick="OScolor('~25',25,32,206,'0x19',0,0,225,257,'0x0C99','0x001F')" onmouseover="hover(0,0,255,257)">BLUE</div>
<div class="osColors" style="background-color: rgb(255,0,0);" onclick="OScolor('~224',230,28,0,'0xE0',255,0,0,258,'0xF060','0x7C00')" onmouseover="hover(255,0,0,258)">RED</div>
<div class="osColors" style="background-color: rgb(0,0,0);" onclick="OScolor('0',0,0,0,'0x00',0,0,0,259,'0x0000','0x0000')" onmouseover="hover(0,0,0,259)">BLACK</div>
<div class="osColors" style="background-color: rgb(255,0,255);" onclick="OScolor('~249',255,61,206,'0xF9',255,0,255,260,'0xFCF9','0x7C1F')" onmouseover="hover(255,0,255,260)">MAGENTA</div>
<div class="osColors" style="background-color: rgb(0,158,0);" onclick="OScolor('~5',0,162,41,'0x05',0,158,0,261,'0x0285','0x8260')" onmouseover="hover(0,158,0,261)">GREEN</div>
<div class="osColors" style="background-color: rgb(255,142,33);" onclick="OScolor('~227',230,125,25,'0xE3',255,142,33,262,'0xF1E3','0xFE24')" onmouseover="hover(255,142,33,262)">ORANGE</div>
<div class="osColors" style="background-color: rgb(181,32,0);" onclick="OScolor('~160',165,20,0,'0xA0',181,32,0,263,'0xD010','0x5880')" onmouseover="hover(181,32,0,263)">BROWN</div>
<div class="osColors" style="background-color: rgb(0,0,132);" onclick="OScolor('~16',16,0,132,'0x10',0,0,132,264,'0x0810','0x0010')" onmouseover="hover(0,0,132,264)">NAVY</div>
<div class="osColors" style="background-color: rgb(0,146,255);" onclick="OScolor('~28',25,130,230,'0x1C',0,146,255,265,'0x0E1C','0x025F')" onmouseover="hover(0,146,255,265)">LTBLUE</div>
<div class="osColors" style="background-color: rgb(255,255,0); color: #000000;" onclick="OScolor('~231',230,255,58,'0xE7',255,255,0,266,'0xF3E7','0xFFE0')" onmouseover="hover(255,255,0,266)">YELLOW</div>
<div class="osColors" style="background-color: rgb(255,255,255); color: #000000;" onclick="OScolor('255',255,255,255,'0xFF',255,255,255,267,'0xFFFF','0xFFFF')" onmouseover="hover(255,255,255,267)">WHITE</div>
<div class="osColors" style="background-color: rgb(230,227,230); color: #000000;" onclick="OScolor('~222',222,219,247,'0xDE',230,227,230,268,'0x6F7E','0x739C')" onmouseover="hover(230,227,230,268)">LTGRAY</div>
<div class="osColors" style="background-color: rgb(197,194,197); color: #000000;" onclick="OScolor('~181',181,182,173,'0xB5',197,194,197,269,'0xDAD5','0x6318')" onmouseover="hover(197,194,197,269)">MEDGRAY</div>
<div class="osColors" style="background-color: rgb(140,138,140);" onclick="OScolor('~148',148,146,165,'0x94',140,138,140,270,'0x4A54','0x4631')" onmouseover="hover(140,138,140,270)">GRAY</div>
<div class="osColors" style="background-color: rgb(82,85,82);" onclick="OScolor('~74',74,73,82,'0x4A',82,85,82,271,'0x252A','0xA94A')" onmouseover="hover(82,85,82,271)">DARKGRAY</div>
</div>
<p id ="TI" style="font-size: 170%; font-family: sans-serif; font-weight: bold; text-align: center; margin: 5px 0px 15px 0px; padding: 0px;">TI-OS Colors</p>
<p id="loadCustomPalette">
Load Custom Palette
<br>
<input type="file" name="palette" accept=".c" id="fileUpload" value="Custom Palette" class="customPalette" hidden>
<label for="fileUpload" class="customPalette" id="uploadButton">Upload Palette</label>
<input type="button" onclick="resetTable(true)" value="Reset Palette" class="customPalette" id="paletteReset">
</p>
<br> <!-- for smaller screen sizes -->
<br>
<footer> <!-- advertising! -->
<hr style="margin: 0px; margin-bottom: 5px;">
<a href="https://www.cemetech.net/forum/viewtopic.php?t=17446&highlight=" target="_blank">Ask a question or suggest a feature</a>
<a href="https://github.com/RoccoLoxPrograms/XlibcColorPicker/releases/latest" target="_blank" style="float: right;">Download the newest version</a>
</footer>
<script type="text/javascript">
// load palette from C file
document.getElementById('fileUpload').onchange = function() {
var r, g, b, paletteHex;
var palette = this.files[0];
var fileReader = new FileReader();
fileReader.onload = function(progressEvent) {
var paletteFile = this.result.split('\n');
var lineNum = 1;
var tableOffset = 0;
var startValue, pal1, pal2, hex1555color;
paletteLoaded = true;
resetTable(false);
while (paletteFile[lineNum].indexOf('}') == -1) {
if (paletteFile[lineNum].indexOf('0x') != -1) {
pal2 = paletteFile[lineNum].substr(paletteFile[lineNum].indexOf('0x') + 2, 2);
startValue = paletteFile[lineNum].indexOf('0x') + 1;
pal1 = paletteFile[lineNum].substr(paletteFile[lineNum].indexOf('0x', startValue) + 2, 2);
hex1555color = parseInt(pal1 + pal2, 16);
red = Math.round((hex1555color >> 10 & 31) * 255 / 31);
green = Math.round((hex1555color >> 15 & 1 | hex1555color >> 4 & 62) * 255 / 63);
blue = Math.round((hex1555color & 31) * 255 / 31);
if (tableOffset == 0) { // save the rgb values of the first color (for drawing the border box later)
r = red;
g = green;
b = blue;
paletteHex = pal1.toUpperCase() + pal2.toUpperCase();
}
hex = '0x' + tableOffset.toString(16).toUpperCase(); // find hex value of number
if (tableOffset < 16) hex = '0x0' + tableOffset.toString(16).toUpperCase();
document.getElementsByTagName('div')[tableOffset].setAttribute('style',`background-color: rgb(${red}, ${green}, ${blue});`);
document.getElementsByTagName('div')[tableOffset].setAttribute('onmouseover',`hover(${red}, ${green}, ${blue}, ${tableOffset})`);
document.getElementsByTagName('div')[tableOffset].setAttribute('onclick',`color(${tableOffset}, ${red}, ${green}, ${blue}, '${hex}', ${hex1555color})`);
tableOffset++;
}
lineNum++;
}
if (colorBrightness(r, g, b) > 164) {
document.getElementsByTagName('div')[0].setAttribute('style',`background-color: rgb(${r}, ${g}, ${b}); border: solid black 1px; padding: 0px; color: #000000;`);
if (localStorage.getItem("RLP_XlibcColorPicker_mode_090419") == 'light') document.getElementById("text").setAttribute("style",`background-color: rgb(${r}, ${g}, ${b}); color: #000000; border: solid black thin;`);
else document.getElementById("text").setAttribute("style",`background-color: rgb(${r}, ${g}, ${b}); color: #000000; border: solid white thin;`);
} else {
document.getElementsByTagName('div')[0].setAttribute('style',`background-color: rgb(${r}, ${g}, ${b}); border: solid white 1px; padding: 0px; color: #ffffff;`);
if (localStorage.getItem("RLP_XlibcColorPicker_mode_090419") == 'light') document.getElementById("text").setAttribute("style",`background-color: rgb(${r}, ${g}, ${b}); color: #ffffff; border: solid black thin;`);
else document.getElementById("text").setAttribute("style",`background-color: rgb(${r}, ${g}, ${b}); color: #ffffff; border: solid white thin;`);
}
document.getElementById('text').innerHTML = `0<br>0x00<p class="rgb">R: ${r} G: ${g} B: ${b}<br>1555: 0x${paletteHex}</p>`;
copyRGB = "r: " + r + ", g: " + g + ", b: " + b;
copy1555 = "0x" + paletteHex;
copy565 = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
oldr = r;
oldg = g;
oldb = b;
oldHoverR = r;
oldHoverG = g;
oldHoverB = b;
};
fileReader.readAsText(palette);
}
document.getElementById("text").innerHTML = '0<br>0x00<p class="rgb">R: 0 G: 0 B: 0<br>1555: 0x0000</p>';
var colorLightness = 0, paletteLoaded = false;
var red = 0, green = 0, blue = 0, oldn = 0, oldr = 0, oldg = 0, oldb = 0, oldHover = 0, oldHoverR = 0, oldHoverG = 0, oldHoverB = 0;
var copyDec = 0, copyHex = "0x00", copyRGB = "r: 0, g: 0, b: 0", copy1555 = "0x0000", copy565 = "0x0000", copy24Hex = "000000";
for (let colorNum = 0; colorNum < 256; colorNum++) {
let hex = '0x' + colorNum.toString(16).toUpperCase(); // find hex value of number
if (colorNum < 16) hex = '0x0' + colorNum.toString(16).toUpperCase();
let rgb565 = colorNum.toString(16);
if (rgb565.length == 1) rgb565 = '0' + rgb565;
rgb565 = rgb565 + rgb565;
rgb565 = parseInt(rgb565, 16);
// convert 565 to rgb
red = ((((rgb565 >> 11) & 0x1F) * 527) + 23) >> 6;
green = ((((rgb565 >> 5) & 0x3F) * 259) + 33) >> 6;
blue = (((rgb565 & 0x1F) * 527) + 23) >> 6;
// create the table cells
let div = document.createElement('DIV');
let ID = 'row' + Math.floor((colorNum / 32)).toString();
document.getElementById(ID).appendChild(div);
// add attributes to the table columns
document.getElementsByTagName('div')[colorNum].setAttribute('style',`background-color: rgb(${red}, ${green}, ${blue});`);
document.getElementsByTagName('div')[colorNum].setAttribute('onmouseover',`hover(${red}, ${green}, ${blue}, ${colorNum})`);
let scaledGreen = Math.round(green * 63 / 255);
let c1555 = (Math.round(red * 31 / 255) << 10) | (scaledGreen << 15 & 0x8000) | (scaledGreen << 4 & 0x03E0) | Math.round(blue * 31 / 255);
document.getElementsByTagName('div')[colorNum].setAttribute('onclick',`color(${colorNum}, ${red}, ${green}, ${blue}, '${hex}', ${c1555})`);
document.getElementsByTagName('div')[colorNum].setAttribute('data-hover',`${colorNum}\n${hex}`);
document.getElementsByTagName('div')[colorNum].setAttribute('class','hoverBox');
}
document.getElementsByTagName('div')[0].setAttribute('style','background-color: rgb(0,0,0); border: solid white 1px; padding: 0px;');
// change copyright year
const date = new Date();
document.getElementById("copyright").innerHTML = `© 2021-${date.getFullYear()} RoccoLox Programs`;
// set mode
if (localStorage.getItem("RLP_XlibcColorPicker_mode_090419") == 'dark') {
document.getElementById("switch").checked = true;
darkMode(); // switch to dark mode
}
else localStorage.setItem("RLP_XlibcColorPicker_mode_090419","light"); // default mode is light
</script>
</body>
</html>