forked from atc1441/atc1441.github.io
-
Notifications
You must be signed in to change notification settings - Fork 1
/
RampTest.html
90 lines (79 loc) · 2.44 KB
/
RampTest.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
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="600" height="600" style="border:1px solid #c3c3c3;"></canvas><br>
Linear/Curve: <input type="checkbox" id="myCheck1"><br>
Enable Slider: <input type="checkbox" id="myCheck">
<input type="range" min="1" max="1000" value="500" id="sliderDiv">
<p>Output: <span id="OutputText"></span></p>
<p>Input: <span id="InputText"></span></p>
<p>Current: <span id="currentText"></span></p>
<script>
var slider = document.getElementById("sliderDiv");
var printdiv = document.getElementById("OutputText");
var printdiv1 = document.getElementById("InputText");
var printdiv2 = document.getElementById("currentText");
var printdiv3 = document.getElementById("acclText");
var canvas = document.getElementById("myCanvas");
var checkBox = document.getElementById("myCheck");
var checkBox1 = document.getElementById("myCheck1");
var ctx = canvas.getContext("2d");
let myarray = [];
var output = 0;
var input = 0;
var currAccl = 0;
function drawPixel(x,y,y1){
ctx.beginPath();
ctx.moveTo(((canvas.width/1000)*x-1), ((canvas.height/1000)*(1000-y1)));
ctx.lineTo(((canvas.width/1000)*x), ((canvas.height/1000)*(1000-y)));
ctx.strokeStyle = 'blue';
ctx.stroke();
}
function drawGraph(newpoint){
var i;
for (i = 1000; i > 0; i--)myarray[i]=myarray[i-1];
myarray[0]=newpoint;
ctx.clearRect(0,0,canvas.width, canvas.height);
ctx.fillText("Fast", 10, 10);
ctx.fillText("Slow", 10, 590);
for (i = 0; i < 1000; i++)drawPixel(i,myarray[i],myarray[i-1]);
}
function calcit(invar,outvar){
var diff = invar-outvar;
diff = Math.max(diff, 1);
diff = Math.min(diff, 2);
currAccl += diff/50;
var currentout =currAccl;
printdiv2.innerHTML = currentout;
if(checkBox1.checked)currentout = 1;
return currentout;
}
function calcit1(invar,outvar){
var diff = invar-outvar;
var currentout = diff/50;
currAccl=0;
printdiv2.innerHTML = currentout;
if(checkBox1.checked)currentout = 1;
return currentout;
}
function timedInterval(){
if(checkBox.checked)input = slider.value;
if (input > output)
output+=calcit(input,output);
if (input < output)
output-=calcit1(output,input);
printdiv.innerHTML = output;
printdiv1.innerHTML = input;
output = Math.max(output, 0);
output = Math.min(output, 1000);
drawGraph(output);
if(output>995)input=0;
if(output<5)input=1000;
}
checkBox.oninput = function() {
if(!checkBox.checked)input=0;;
}
myVar = setInterval(timedInterval, 1);
</script>
</body>
</html>