-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
150 lines (138 loc) · 3.49 KB
/
test.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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.slidecontainer {
width: 100%;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 25px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider:hover {
opacity: 1;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
background: #04AA6D;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 25px;
height: 25px;
background: #04AA6D;
cursor: pointer;
}
.slider2 {
position: absolute;
bottom: 15em;
-webkit-transform: rotate(270deg);
-moz-transform: rotate(270deg);
-ms-transform: rotate(270deg);
-o-transform: rotate(270deg);
transform: rotate(270deg);
-webkit-appearance: none;
width: 30%;
height: 25px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider2:hover {
opacity: 1;
}
.slider2::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
background: #04AA6D;
cursor: pointer;
}
.slider2::-moz-range-thumb {
width: 25px;
height: 25px;
background: #04AA6D;
cursor: pointer;
}
.robot{
text-align: center;
font-size: 50px;
}
</style>
</head>
<body>
<h1>Heading Corrector</h1>
<p>Drag the slider to change the heading of the bot.</p>
<div class="slidecontainer">
<input type="range" min="-360" max="360" value="0" class="slider" id="myRange">
<input type="range" min="-100" max="100" value="100" class="slider2" id="left" style="left: 10%">
<input type="range" min="-100" max="100" value="100" class="slider2" id="right" style="right: 10%">
<p>Actual Heading: <span id="demo2"></span></p>
<p><pre style="display:inline">head</pre> Variable: <span id="demo"></span></p>
<p>Left Wheel Speed: <span id="leftSpeed">100</span></p>
<p>Right Wheel Speed: <span id="rightSpeed">100</span></p>
<div class="robot" id="robot">⬆️</div>
</div>
<script>
function sin(x){
return Math.sin(x * (Math.PI / 180));
}
var head = document.getElementById("myRange").value;
var output = document.getElementById("demo");
var output2 = document.getElementById("demo2");
var robot = document.getElementById("robot");
var left = document.getElementById("left");
var right = document.getElementById("right");
var leftSpeed = document.getElementById("leftSpeed");
var rightSpeed = document.getElementById("rightSpeed");
var speed = 100;
output.innerHTML = head;
document.getElementById("myRange").oninput = function() {
var head = document.getElementById("myRange").value;
output2.innerHTML = head;
robot.style.webkitTransform = 'rotate(' + head + 'deg)';
if (head%180 == 0){
head = 0;
}
else if (head > 180){
head = head%180 - 180;
}
else if (head < -180){
head = head%-180 + 180;
}
if (head > 90){
head = 90;
}
else if (head < -90){
head = -90;
}
output.innerHTML = head;
if (head >= 0){
rightSpeed.innerHTML = speed;
right.value = speed;
leftSpeed.innerHTML = (1-(sin(head)*2))*speed;
left.value = (1-(sin(head)*2))*speed;
}
else if (head < 0){
leftSpeed.innerHTML = speed;
left.value = speed;
rightSpeed.innerHTML = (1-(sin(head)*-2))*speed;
right.value = (1-(sin(head)*-2))*speed;
}
}
</script>
</body>
</html>