-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
707 lines (625 loc) · 26.5 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
<!DOCTYPE html>
<html>
<head>
<title>Resistance Calculator</title>
<script type="text/javascript"></script>
<style type="text/css">
#appFooter {
padding: 2px;
background-color: #15a;
border-radius: 2px;
outline: none;
background-image: -webkit-linear-gradient(top, #ee432e 0%, #c63929 50%, #b51700 50%, #891100 100%);
background-image: -moz-linear-gradient(top, #ee432e 0%, #c63929 50%, #b51700 50%, #891100 100%);
background-image: -o-linear-gradient(top, #ee432e 0%, #c63929 50%, #b51700 50%, #891100 100%);
background-image: linear-gradient(top, #ee432e 0%, #c63929 50%, #b51700 50%, #891100 100%);
border: 1px solid #ffefbb;
box-shadow: inset 0px 0px 0px 1px rgba(255, 115, 100, 0.4), 0 0px 1px #333333;
color: #fff;
font: bold 12px garamond;
text-align: center;
text-shadow: 0px -1px 1px rgba(0, 0, 0, 0.8);
}
#appTitle {
background-color: #15a;
border-radius: 2px;
outline: none;
padding: 2px;
background-image: -webkit-linear-gradient(top, #ee432e 0%, #c63929 50%, #b51700 50%, #891100 100%);
background-image: -moz-linear-gradient(top, #ee432e 0%, #c63929 50%, #b51700 50%, #891100 100%);
background-image: -o-linear-gradient(top, #ee432e 0%, #c63929 50%, #b51700 50%, #891100 100%);
background-image: linear-gradient(top, #ee432e 0%, #c63929 50%, #b51700 50%, #891100 100%);
border: 1px solid #ffefbb;
box-shadow: inset 0px 0px 0px 1px rgba(255, 115, 100, 0.4), 0 0px 1px #333333;
color: #fff;
font: bold 16px garamond;
text-align: center;
text-shadow: 0px -1px 1px rgba(0, 0, 0, 0.8);
}
.calculate {
background-color: #15a;
border-radius: 2px;
outline: none;
padding: 2px 5px;
cursor: pointer;
background-image: -webkit-linear-gradient(top, #ee432e 0%, #c63929 50%, #b51700 50%, #891100 100%);
background-image: -moz-linear-gradient(top, #ee432e 0%, #c63929 50%, #b51700 50%, #891100 100%);
background-image: -o-linear-gradient(top, #ee432e 0%, #c63929 50%, #b51700 50%, #891100 100%);
background-image: linear-gradient(top, #ee432e 0%, #c63929 50%, #b51700 50%, #891100 100%);
border: 1px solid #ffefbb;
box-shadow: inset 0px 0px 0px 1px rgba(255, 115, 100, 0.4), 0 0px 1px #333333;
text-decoration: none;
color: #fff;
font: bold 0.9em garamond;
text-align: center;
text-shadow: 0px -1px 1px rgba(0, 0, 0, 0.8);
}
.calculate:hover {
color: #000;
background-image: linear-gradient(#fa4 50%, #f60 50%);
}
#digit {
width: 80px;
}
#imageDiv {
border: 1px solid #ececec;
padding: 10px;
height: 110px;
background-color: #fff;
border-radius: 2px;
border-radius: 2px ;
box-shadow: 0px 0px 2px #333333;
text-align: center;
}
#imageHolder {
background-color: #eeeeee;
/*background-color: rgba(255, 239, 187, 0.7);*/
border-top: 6px solid #e5e5e5;
line-height: 3em;
border-radius: 54px;
height: 72px;
width: 40%;
box-shadow: 1px 1px 2px #333333;
}
.imageLines {
font-size: 85px;
font-weight: bold;
cursor: default;
}
.imageLines:hover {
text-shadow: 0px -1px 4px rgba(0, 0, 0, 0.8);
}
#inputDiv {
box-shadow: 0px 0px 3px #333333;
padding: 10px;
height: 76px;
border-radius: 2px;
background-color: #fff;
}
#range {
width: 30px;
}
#result {
font-weight: bold;
color: red;
font-size: 16px;
}
#result2 {
font-weight: bold;
font-size: 16px;
}
#selectDiv {
height: 110px;
box-shadow: 0px 0px 3px #333333;
padding: 10px;
border-radius: 2px;
background-color: #fff;
}
.selects {
width: 19%;
}
#separator4:hover, #separator5:hover {
text-shadow: 0px -1px 1px transparent;
}
#styleDiv {
font-family: cursive;
font-weight: bold;
font-size: 13px;
}
#wrapper {
padding: 0 1%;
width: 98%;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="styleDiv">
<div id="appTitle">RESISTANCE VALUE CALCULATOR</div><br>
<div id="selectDiv">
<span class="sectionTitle">CONVERT COLOR CODE TO DIGIT</span><br>
<select id="bandNumber" title="Select either 4Band or 5Band. Select '4Band' for 3color" onchange="bandType(this.value)">
<option value="#">Select Band Type</option>
<option value="4">4Band</option>
<option value="5">5Band</option>
</select><br><br>
<div id="bandDiv" style="display: none;">
<select id="band1" title="Select the first band of the resistor" class="selects" onchange="bandColor('color1',this.value)">
<option value="#">Select Color 1</option>
<option value="brown" style="background-color: brown; font-weight: bold">Brown</option>
<option value="red" style="background-color: red; font-weight: bold">Red</option>
<option value="orange" style="background-color: orange; font-weight: bold">Orange</option>
<option value="yellow" style="background-color: yellow; font-weight: bold">Yellow</option>
<option value="green" style="background-color: green; font-weight: bold">Green</option>
<option value="blue" style="background-color: blue; font-weight: bold">Blue</option>
<option value="violet" style="background-color: violet; font-weight: bold">Violet</option>
<option value="grey" style="background-color: grey; font-weight: bold">Grey</option>
<option value="white" style="background-color: white; font-weight: bold">White</option>
</select>
<select id="band2" title="Select the second band of the resistor" class="selects" onchange="bandColor('color2',this.value)">
<option value="#">Select Color 2</option>
<option value="black" style="background-color: black; color: white; font-weight: bold">Black</option>
<option value="brown" style="background-color: brown; font-weight: bold">Brown</option>
<option value="red" style="background-color: red; font-weight: bold">Red</option>
<option value="orange" style="background-color: orange; font-weight: bold">Orange</option>
<option value="yellow" style="background-color: yellow; font-weight: bold">Yellow</option>
<option value="green" style="background-color: green; font-weight: bold">Green</option>
<option value="blue" style="background-color: blue; font-weight: bold">Blue</option>
<option value="violet" style="background-color: violet; font-weight: bold">Violet</option>
<option value="grey" style="background-color: grey; font-weight: bold">Grey</option>
<option value="white" style="background-color: white; font-weight: bold">White</option>
</select>
<select id="band3" title="Select the third band of the resistor" class="selects" onchange="bandColor('color3',this.value)">
<option value="#">Select Color 3</option>
<option value="black" style="background-color: black; color: white; font-weight: bold">Black</option>
<option value="brown" style="background-color: brown; font-weight: bold">Brown</option>
<option value="red" style="background-color: red; font-weight: bold">Red</option>
<option value="orange" style="background-color: orange; font-weight: bold">Orange</option>
<option value="yellow" style="background-color: yellow; font-weight: bold">Yellow</option>
<option value="green" style="background-color: green; font-weight: bold">Green</option>
<option value="blue" style="background-color: blue; font-weight: bold">Blue</option>
<option value="violet" style="background-color: violet; font-weight: bold">Violet</option>
<option value="grey" style="background-color: grey; font-weight: bold">Grey</option>
<option value="white" style="background-color: white; font-weight: bold">White</option>
<option disabled id="value1" value="gold" style="background-color: gold; font-weight: bold">Gold</option><!-- this would not show in 5band -->
<option disabled id="value2" value="silver" style="background-color: silver; font-weight: bold">Silver</option><!-- this would not show in 5band -->
<!-- <option value="transparent">None</option> -->
</select>
<select id="band4" title="" class="selects" onchange="bandColor('color4',this.value)">
<option value="#">Select Color 4</option>
<option value="black" style="background-color: black; color: white; font-weight: bold" title="Select this band to show the absolute value">Black</option>
<option value="brown" style="background-color: brown; font-weight: bold">Brown</option>
<option value="red" style="background-color: red; font-weight: bold">Red</option>
<option disabled id="tolerance1" value="orange" style="background-color: orange; font-weight: bold">Orange</option><!-- this would be invisible in a 4band -->
<option disabled id="tolerance2" value="yellow" style="background-color: yellow; font-weight: bold">Yellow</option><!-- this would be invisible in a 4band -->
<option value="green" style="background-color: green; font-weight: bold">Green</option><!-- this would be invisible in a 4band -->
<option value="blue" style="background-color: blue; font-weight: bold">Blue</option><!-- this would be invisible in a 4band -->
<option value="violet" style="background-color: violet; font-weight: bold">Violet</option><!-- this would be invisible in a 4band -->
<option value="grey" style="background-color: grey; font-weight: bold">Grey</option><!-- this would be invisible in a 4band -->
<option disabled id="tolerance3" value="white" style="background-color: white; font-weight: bold">White</option><!-- this would be invisible in a 4band -->
<option value="gold" style="background-color: gold; font-weight: bold">Gold</option>
<option value="silver" style="background-color: silver; font-weight: bold">Silver</option>
<option disabled id="value3" value="transparent">None</option><!-- this would not show in 5band -->
</select>
<select id="band5" title="" class="selects" onchange="bandColor('color5',this.value)" style="display: none;">
<option value="#">Select Color 5</option>
<option value="black" style="background-color: black; color: white; font-weight: bold">Black</option>
<option value="brown" style="background-color: brown; font-weight: bold">Brown</option>
<option value="red" style="background-color: red; font-weight: bold">Red</option>
<option value="green" style="background-color: green; font-weight: bold">Green</option>
<option value="blue" style="background-color: blue; font-weight: bold">Blue</option>
<option value="violet" style="background-color: violet; font-weight: bold">Violet</option>
<option value="grey" style="background-color: grey; font-weight: bold">Grey</option>
<option value="gold" style="background-color: gold; font-weight: bold">Gold</option>
<option value="silver" style="background-color: silver; font-weight: bold">Silver</option>
<!-- <option value="transparent">None</option> -->
</select>
<br>
<br>
<span class="calculate" onclick="calculate()">CALCULATE</span>
<br><br>
</div><!-- end band div -->
</div><!-- end selectDiv -->
<br>
<div id="inputDiv">
<span class="sectionTitle">CONVERT DIGIT TO COLOR CODE</span><br>
<select id="bandValue" title="Select either 4 or 5 for 4Band or 5Band respectively" onchange="bandValue(this.value)">
<option value="#">Select Band Value</option>
<option value="4">4</option>
<option value="5">5</option>
</select><br><br>
<div id="inputs" style="display: none;">
RESISTANCE VALUE: <input id="digit" onkeyup="showDigit(this.value)">
TOLERANCE: <input id="range" onkeyup="showTolerance(this.value)">
<span class="calculate" onclick="calculateColor()">CONVERT</span>
</div>
</div><!-- end inputDiv -->
</div><!-- end styleDiv -->
<br>
<div id="imageDiv" title="Hover on each color to view its properties"><center>
<div id="imageHolder" title="Your virtual resistor">
<span id="color1" title="" class="imageLines"></span>
<span id="color2" title="" class="imageLines"></span>
<span id="color3" title="" class="imageLines"></span>
<span id="separator4" style="display: none;" class="imageLines"></span>
<span id="color4" title="" class="imageLines"></span>
<span id="separator5" style="display: none;" class="imageLines"></span>
<span id="color5" title="" class="imageLines"></span>
</div></center>
<span id="result">0Ohms</span>
<span id="result2">(0%)</span>
</div><!-- end imageDiv -->
<br>
<div id="appFooter">ResistanceValueCalculator© Developed by KingSam™ for BANDS TECHNOLOGIES<br>
For enquiries & contributions: 2347037270037</div>
</div><!-- end wrapper -->
<script>
// alert(1500000000%1000000000);
var band1 = document.getElementById("band1");
var band2 = document.getElementById("band2");
var band3 = document.getElementById("band3");
var band4 = document.getElementById("band4");
var band5 = document.getElementById("band5");
var digit = document.getElementById("digit");
var range = document.getElementById("range");
var sep4 = document.getElementById("separator4");
var sep5 = document.getElementById("separator5");
var bandNumber = document.getElementById("bandNumber");
function bandColor(band,value) {//filling and coloring the bands
document.getElementById(band).style.display = "";//colorX
document.getElementById(band).innerHTML = "|";
document.getElementById(band).title = value;
document.getElementById(band).style.color = value;
var bg;
switch (band){
case 'color1' : bg = 'band1'; break;
case 'color2' : bg = 'band2'; break;
case 'color3' : bg = 'band3'; break;
case 'color4' : bg = 'band4'; break;
case 'color5' : bg = 'band5'; break;
}
document.getElementById(bg).style.backgroundColor = value;
}
//
function bandType(value) {//selecting 4band or 4band
document.getElementById("result").innerHTML = "0Ohms";
document.getElementById("result2").innerHTML = "(0%)";
document.getElementById("bandDiv").style.display = "block";
document.getElementById("inputs").style.display = "none";
document.getElementById("bandValue").value = "#";
removeLines();
for (var i = 1; i <= 5; i++) {
document.getElementById("band"+i).value = "#";
document.getElementById("band"+i).style.backgroundColor = "";
}
if (value == "5") {//a five band color code
for (var i = 1; i <= 3; i++) {//show the hidden colors in band 4
document.getElementById("tolerance"+i).disabled = false;
}
for (var i = 1; i <= 3; i++) {//show the hidden colors in band 4
document.getElementById("value"+i).disabled = true;
}
sep4.style.display = "none";//hide 4band separator
band5.style.display = "";//make band5 <select> visible
var color5 = document.getElementById("color5");
document.getElementById("band4").title = "Select the fourth band of the resistor";
document.getElementById("band5").title = "Select the last/farthest band";
color5.style.display = "";//show the 5th color
color5.innerHTML = "";//clear the content of the band
sep5.style.display = "";//show 5band separator
sep5.innerHTML = "||";//fill 5band's separator
sep5.style.color = "transparent";//make the separator invisible
}else{//a four band color code
for (var i = 1; i <= 3; i++) {//hide the colors in band 4
document.getElementById("tolerance"+i).disabled = true;
}
for (var i = 1; i <= 3; i++) {//show the hidden colors in band 4
document.getElementById("value"+i).disabled = false;
}
band5.style.display = "none";//hide band5 <select>
band5.value = "#";
sep5.style.display = "none";//hide 5band separator
document.getElementById("color5").style.display = "none";//hide the 5th color
document.getElementById("band4").title = "Select the last/farthest band. Select 'None' for 3color";//hide the 5th color
sep4.style.display = "";//4band separator
sep4.innerHTML = "||";//fill 4band's separator
sep4.style.color = "transparent";//make the separator invisible
}
}
function bandValue(value) {
removeLines();
document.getElementById("result").innerHTML = "0Ohms";
document.getElementById("result2").innerHTML = "(0%)";
document.getElementById("inputs").style.display = "block";
document.getElementById("bandNumber").value = "#";
document.getElementById("bandDiv").style.display = "none";
if (value == "5") {//a five band color code
sep4.style.display = "none";//hide 4band separator
sep5.style.display = "";//show 5band separator
sep5.innerHTML = "||";//fill 5band's separator
sep5.style.color = "transparent";//make the separator invisible
}else{//a four band color code
document.getElementById("color5").style.display = "none";
sep5.style.display = "none";//hide 5band separator
sep4.style.display = "";//show 4band separator
sep4.innerHTML = "||";//fill 4band's separator
sep4.style.color = "transparent";//make the separator invisible
}
}
function calculate() {//converting to digit
var values = {"black":0,"brown":1,"red":2,"orange":3,"yellow":4,"green":5,"blue":6,"violet":7,"grey":8,"white":9,}
var tolerance = {"transparent":20,"silver":10,"gold":5,"red":2,"brown":1,"green":0.5,"violet":0.1,"blue":0.25,"grey":0.05,"black":0,}
if (bandNumber.value == "4") {
if (band1.value == "#" || band2.value == "#" || band3.value == "#" || band4.value == "#") {
alert("Select all colors before proceeding");
}else{
var multiplier = 1;
for (var i = 0; i < values[band3.value]; i++) {
multiplier *= 10;
}
if (band3.value == "gold") {multiplier = 0.1;}
if (band3.value == "silver") {multiplier = 0.01;}
var abs = (((values[band1.value]*10) + values[band2.value]) * multiplier);
var min = abs - ((tolerance[band4.value] / 100) * abs);
abs += ((tolerance[band4.value] / 100) * abs);
var max = abs;
document.getElementById("result").innerHTML = ohms(min.toFixed(3))+" ~~ "+ohms(max.toFixed(3));
document.getElementById("result2").innerHTML = "(+/- "+tolerance[band4.value]+"% Tolerance)";
}
}
else if (bandNumber.value == "5") {
if (band1.value == "#" || band2.value == "#" || band3.value == "#" || band4.value == "#" || band5.value == "#") {
alert("Select all colors before proceeding");
}else{
var multiplier = 1;
for (var i = 0; i < values[band4.value]; i++) {
multiplier *= 10;
}
if (band4.value == "gold") {multiplier = 0.1;}
if (band4.value == "silver") {multiplier = 0.01;}
var abs = (((values[band1.value]*100) + (values[band2.value]*10) + values[band3.value]) * multiplier);
var min = abs - ((tolerance[band5.value] / 100) * abs);
abs += (tolerance[band5.value] / 100) * abs;
var max = abs;
document.getElementById("result").innerHTML = ohms(min.toFixed(3))+" ~~ "+ohms(max.toFixed(3));
document.getElementById("result2").innerHTML = "(+/- "+tolerance[band5.value]+"% Tolerance)";
}
}
}
var val = {"0":"black","1":"brown","2":"red","3":"orange","4":"yellow","5":"green","6":"blue","7":"violet","8":"grey","9":"white",}
var tol = {"20":"transparent","10":"silver","5":"gold","2":"red","1":"brown","0.5":"green","0.25":"blue","0.1":"violet","0.05":"grey",}
var col1, col2, col3, cols, xply4, xply5;
function calculateColorGiga(dig,bv) {
if (dig>9000000000) {//can only calculate within the range of 9GigaOhms
alert("What were you thinking dude?\nDon't you realize that current might not flow---?\nMeet King Sam at the Walkway for explanations");
}
if (dig>=1000000000) {//within the calculable range (1G - 9G)
col1 = Math.floor(dig/1000000000);
col2 = Math.floor((dig/100000000) - (col1*10));
col3 = ((dig/10000000) - (Math.floor(dig/100000000)*10));
bandColor("color1",val[col1]);//color1 takes the first digit
bandColor("color2",val[col2]);
if(bv=="5"){
bandColor("color3",val[col3]);
bandColor("color4",val[7]);
}else{
bandColor("color3",val[8]);
}
}else{
calculateColorMega(dig,bv);
}
}
function calculateColorMega(dig,bv) {
if (dig>=1000000) {//1M - 999M
cols = Math.floor(dig/1000000);//used for further calculations
col1 = Math.floor(dig/1000000);
col2 = Math.floor((dig/100000) - (col1*10));
xply5 = 4;
xply4 = 5;
col3 = ((dig/10000) - (Math.floor(dig/100000)*10));
if (col1>99) {//100 - 999
colors100(cols);
xply5 = 6;
xply4 = 7;
}
if (col1>9) {//10 - 99
colors10(cols);
xply5 = 5;
xply4 = 6;
}
bandColor("color1",val[col1]);//color1 takes the first digit
bandColor("color2",val[col2]);
if(bv=="5"){
bandColor("color3",val[col3]);
bandColor("color4",val[xply5]);
}else{
bandColor("color3",val[xply4]);
}
}else{
calculateColorKilo(dig,bv);
}
}
function calculateColorKilo(dig,bv) {
if (dig>=1000) {//1000 - 999999
cols = Math.floor(dig/1000);//used for further calculations
col1 = Math.floor(dig/1000);
col2 = Math.floor((dig/100) - (col1*10));
xply5 = 1;
xply4 = 2;
col3 = ((dig/10) - (Math.floor(dig/100)*10));
if (col1>99) {//100 - 999
colors100(cols);
xply5 = 3;
xply4 = 4;
}
if (col1>9) {//10 - 99
colors10(cols);
xply5 = 2;
xply4 = 3;
}
bandColor("color1",val[col1]);//color1 takes the first digit
bandColor("color2",val[col2]);
if(bv=="5"){
bandColor("color3",val[col3]);
bandColor("color4",val[xply5]);
}else{
bandColor("color3",val[xply4]);
}
}else{
calculateColorHun(dig,bv);
}
}
function calculateColorHun(dig,bv) {
if (dig>=100) {//100 - 999
cols = Math.round(dig);
document.getElementById("result").innerHTML = ohms(cols);//display the input value
col1 = Math.floor(cols/100);
col2 = Math.floor((cols/10) - (col1*10));
col3 = Math.floor((cols) - (Math.floor(cols/10)*10));
bandColor("color1",val[col1]);//color1 takes the first digit
bandColor("color2",val[col2]);
if(bv=="5"){
bandColor("color3",val[col3]);
bandColor("color4",val[0]);
}else{
bandColor("color3",val[1]);
}
}
else{
calculateColorTen(dig,bv);
}
}
function calculateColorTen(dig,bv) {
if (dig>=10) {//10 - 99
cols = Math.round(dig*10);
document.getElementById("result").innerHTML = ohms(cols/10);//display the input value
col1 = Math.floor(cols/100);
col2 = Math.floor((cols/10) - (col1*10));
col3 = Math.floor(cols) - (Math.floor(cols/10)*10);
if(bv=="5"){
bandColor("color1",val[col1]);
bandColor("color2",val[col2]);
bandColor("color3",val[col3]);
bandColor("color4","gold");
}else{
coln = Math.round(dig);
col1 = Math.floor(coln/10);
col2 = coln - (col1*10);
document.getElementById("result").innerHTML = ohms(coln);//display the input value
bandColor("color1",val[col1]);
bandColor("color2",val[col2]);
bandColor("color3",val[0]);
}
}else{
calculateColorUnit(dig,bv);
}
}
function calculateColorUnit(dig,bv) {
if (dig>=1) {//1 - 9
cols = dig*100;
col1 = Math.floor(cols/100);
col2 = Math.floor((cols/10) - (col1*10));
col3 = Math.floor((cols - Math.floor(cols/10)*10));
bandColor("color1",val[col1]);//color1 takes the first digit
bandColor("color2",val[col2]);
if(bv=="5"){
bandColor("color3",val[col3]);
bandColor("color4","silver");
}else{
bandColor("color3","gold");
}
}
}
function calculateColor() {
for (var i = 1; i <= 5; i++) {
document.getElementById("band"+i).value = "#";
document.getElementById("band"+i).style.backgroundColor = "";
}
var rawDig = digit.value, dig; dig = parseFloat(rawDig).toFixed(2);
var rng = range.value;
if (isNaN(rng)) {rng = 0;}
var bv = document.getElementById("bandValue").value;//for tolerance color
if (bv=="5") {
document.getElementById("separator5").style.display = "";
}else{
document.getElementById("separator4").style.display = "";
}
if (tol[rng] === undefined) {alert("I don't think there's a tolerance value of "+rng+" :("); tol[rng] = "transparent";}
if (isNaN(parseInt(dig))) {
alert("Hey! you just forgot to enter a value");
}else{
document.getElementById("result").innerHTML = ohms(dig);//display the input value
if (dig<1) {//0.1 - 0.9
if (dig<0.1) {
alert("Sorry! But I can only calculate values between\n0.1Ohms - 99000000000Ohms(99GigaOhms)\nMeet King Sam at Block 10 for the code ;)");
}else{//value >= 0.1, continue
cols = dig*100;
col1 = Math.floor(cols/10);
col2 = Math.floor(cols - (col1*10));
col3 = Math.floor((cols - Math.floor(cols))*10.1);
if(bv=="5"){
alert("5band not possible for values less than 1");
}else{
// alert("color"+tol[rng]);
bandColor("color"+bv,tol[rng]);
bandColor("color1",val[col1]);//color1 takes the first digit
bandColor("color2",val[col2]);
bandColor("color3","silver");
}
}
}else{
// alert(tol[rng]);
bandColor("color"+bv,tol[rng]);
calculateColorGiga(dig,bv);
}
}
}
function colors100(cols) {
col1 = Math.floor(cols/100);
col2 = (Math.floor(cols/10) - (col1*10));
col3 = cols - (Math.floor(cols/10)*10);
}
function colors10(cols) {
col1 = Math.floor(cols/10);
col2 = cols - (col1*10);
col3 = 0;
}
function ohms(val) {
if (val>=1000000000) {
return (val/1000000000).toFixed(3)+"GOhms";
}
if (val>=1000000) {
return (val/1000000).toFixed(3)+"MOhms";
}
if (val>=1000) {
return (val/1000).toFixed(3)+"kOhms";
}
else{
return parseFloat(val).toFixed(3)+"Ohms";
}
}
function removeLines() {
var lines = document.getElementsByClassName("imageLines"), i;
i = lines.length;
while(i--){
lines[i].style.display = "none";
}
}
function showDigit(value) {
if (isNaN(value) || value == "") {
digit.value = "";
document.getElementById("result").innerHTML = 0;
}else{
document.getElementById("result").innerHTML = ohms(value);
removeLines();
}
}
function showTolerance(value) {
if (isNaN(value) || value <0.05) {value = 0;}
document.getElementById("result2").innerHTML = "(+/- "+parseFloat(value).toFixed(2)+"% Tolerance)";
document.getElementById("color4").style.color = "transparent";
document.getElementById("color5").style.color = "transparent";
}
</script>
</body>
</html>