-
Notifications
You must be signed in to change notification settings - Fork 5
/
test-resistor.html
174 lines (158 loc) · 4.82 KB
/
test-resistor.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
<!DOCTYPE HTML>
<html>
<head>
<title>VISIR Resistor test</title>
<style>
body {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
.resistor {
display: table-cell;
border: 1px solid black;
width: 400px;
padding: 0; margin: 0;
text-align: center;
height: 120px;
background-color: rgb(68, 194, 231);
vertical-align: middle;
letter-spacing: 0px;
word-spacing: 0px;
border-radius: 55px;
}
.colorband {
border: 0;
display: inline-block;
padding: 0;
width: 6%;
height: 100%;
margin: 0 5% 0 5%;
background-color: black;
vertical-align: top;
}
.colorband .name {
position: relative;
top: 50%;
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
-ms-transform: rotate(-90deg);
-o-transform: rotate(-90deg);
transform: rotate(-90deg);
}
.outer {
position: relative;
display: table;
border: 0; padding: 0; margin: 0;
vertical-align: middle;
}
.wireend {
display: table-cell;
border: 0; padding: 0; margin: 0;
width: 50px;
height: 100%;
vertical-align: middle;
}
.wire {
vertical-align: middle;
background: black;
height: 12px;
}
.value {
width: 200px;
}
</style>
<script type="text/javascript" src="jquery-2.1.3.min.js"></script>
<script type="text/javascript" src="jquery-draggable.js"></script>
<script type="text/javascript" src="utils.js"></script>
<script type="text/javascript" src="visir.js"></script>
<script>
var colorIdx = [1,0,0,0,0];
var Limit = [9,9,9,11,8];
var colors = [ "#000000", "#B8860B", "#FF0000", "#FFA500", "#FFFF00", "#9ACD32", "#6495ED", "#EE82EE", "#A0A0A0", "#FFFFFF", "#FFD700", "#C0C0C0" ];
var colorNames = [ "Black", "Brown", "Red", "Orange", "Yellow", "Green", "Blue", "Violet", "Gray", "White", "Gold", "Silver", "None"];
var Multipliers = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -2];
var Tolerances = [ 1, 2, 0.5, 0.25, 0.1, 0.05, 5, 10, 20];
var ToleranceColors = [ "#B8860B", "#FF0000", "#9ACD32", "#6495ED", "#EE82EE", "#FFFFFF", "#FFD700", "#C0C0C0", "rgb(68, 194, 231)" ];
var ToleranceColorNames = [ "Brown", "Red", "Green", "Blue", "Violet", "Gray", "Gold", "Silver", "None"];
function UpdateColors()
{
$(".color1").css("background-color", colors[colorIdx[0]]);
$(".color2").css("background-color", colors[colorIdx[1]]);
$(".color3").css("background-color", colors[colorIdx[2]]);
$(".color4").css("background-color", colors[colorIdx[3]]);
$(".color5").css("background-color", ToleranceColors[colorIdx[4]]);
$(".color1 .name").text(colorNames[colorIdx[0]]);
$(".color2 .name").text(colorNames[colorIdx[1]]);
$(".color3 .name").text(colorNames[colorIdx[2]]);
$(".color4 .name").text(colorNames[colorIdx[3]]);
$(".color5 .name").text(ToleranceColorNames[colorIdx[4]]);
}
function CalculateValue()
{
var value = (colorIdx[0] * 100 + colorIdx[1] * 10 + colorIdx[2]) * Math.pow(10, Multipliers[colorIdx[3]]);
$(".value").val((value < 20.0) ? value.toFixed(3) : value);
//trace("value: " + value + " " + colorIdx[3]);
var tolerance = Tolerances[colorIdx[4]];
$(".tolerance").val(tolerance + "%");
//trace("tolerance: " + tolerance);
}
function ChangeColor(num, dir)
{
colorIdx[num] += dir;
//if (num == 0 && colorIdx[num] < 1) colorIdx[num] = Limit[num];
if (colorIdx[num] < 0) colorIdx[num] = Limit[num];
if (colorIdx[num] > Limit[num]) colorIdx[num] = 0;
UpdateColors();
CalculateValue();
}
function init()
{
UpdateColors();
CalculateValue();
function genDragFunc(idx)
{
var prev = 0;
var step = 10;
return { move: function(elem, x, y, newtouch) {
if (newtouch) prev = y;
var diff = y - prev;
if (diff > step) {
ChangeColor(idx, -1);
prev = y;
}
if (diff < -step) {
ChangeColor(idx, 1);
prev = y;
}
return {x: undefined, y:undefined };
}}
}
$(".color1").draggable( genDragFunc(0) );
$(".color2").draggable( genDragFunc(1) );
$(".color3").draggable( genDragFunc(2) );
$(".color4").draggable( genDragFunc(3) );
$(".color5").draggable( genDragFunc(4) );
$(".resistor").on("mousedown touchstart", function(e) { e.preventDefault(); });
}
$(init);
</script>
</head>
<body>
<div class="outer">
<div class="wireend"><div class="wire"></div></div>
<div class="resistor">
<div class="colorband color1"><div class="name"></div></div>
<div class="colorband color2"><div class="name"></div></div>
<div class="colorband color3"><div class="name"></div></div>
<div class="colorband color4"><div class="name"></div></div>
<div class="colorband color5"><div class="name"></div></div>
</div>
<div class="wireend"><div class="wire"></div></div>
</div>
<input class="value" type="number" value="1000" />
<input class="tolerance" type="text" value="1%" />
</body>
</html>