-
Notifications
You must be signed in to change notification settings - Fork 0
/
grey-code.html
93 lines (90 loc) · 3.81 KB
/
grey-code.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="graycounter.css">
<title>Gray Counter</title>
</head>
<body>
<div class="container">
<div class="title">
<h1 class="headd">COUNTER</h1>
</div>
<div class="box">
<div class="btn press cont">
<button class="submit" onclick="increment()">INCREMENT</button>
</div>
<div class="show cont">
<div class="answer"><span id="answerr"></span></div>
</div>
<div class="btn decrement cont">
<button class="submit" onclick="decrement()">DECREMENT</button>
</div>
<div class="current cont">
<div class="state">
<div class="text">CURRENT STATE</div>
</div>
<div class="fig"><span class="cs" id="currentState"></span></div>
</div>
<div class="gif cont">
<div class="btn reset cont">
<button class="submit2" onclick="reset()">RESET</button>
</div>
<div class="imgg">
<img class="image"src="giphy.gif" alt="arrow">
</div>
</div>
<div class="next cont">
<div class="state">
<div class="text">NEXT STATE</div>
</div>
<div class="fig"><span class="ns" id="nextState"></span></div>
</div>
<div class="light cont">
<p><span class="aab"><span class="aa">On </span><span class="b">1</span></span><span class="cd"><span class="c">Off </span><span class="d">0</span></span></p>
</div>
</div>
</div>
<script>
var currentState = "0 0 0 0";
var currentvalue = "0";
// var currentindex = 0;
var grayCode = ["0 0 0 0", "0 0 0 1", "0 0 1 1", "0 0 1 0", "0 1 1 0", "0 1 1 1", "0 1 0 1", "0 1 0 0", "1 0 0 1", "1 0 0 0"];
var finalvalue = ["0", "1", "3", "2", "6", "7", "5", "4", "9", "8"];
function increment() {
var index = grayCode.indexOf(currentState);
var nextIndex = (index + 1) % 10;
var nextState = grayCode[nextIndex];
var currentindex = finalvalue.indexOf(currentvalue);
var nexttindex = (currentindex + 1) % 10;
var nextanswer = finalvalue[nexttindex];
document.getElementById("currentState").innerHTML = currentState;
document.getElementById("nextState").innerHTML = nextState;
document.getElementById("answerr").innerHTML = currentvalue;
currentState = nextState;
currentvalue = nextanswer;
}
function decrement() {
var index = grayCode.indexOf(currentState);
var nextIndex = (index - 1 + 10) % 10;
var nextState = grayCode[nextIndex];
var currentindex = finalvalue.indexOf(currentvalue);
var nexttindex = (currentindex - 1 + 10) % 10;
var nextanswer = finalvalue[nexttindex];
document.getElementById("currentState").innerHTML = currentState;
document.getElementById("nextState").innerHTML = nextState;
document.getElementById("answerr").innerHTML = currentvalue;
currentState = nextState;
currentvalue = nextanswer;
}
function reset() {
document.getElementById("currentState").innerHTML = "0 0 0 0";
document.getElementById("nextState").innerHTML = "0 0 0 1 ";
document.getElementById("answerr").innerHTML = "0";
}
</script>
<!-- <script type="text/javascript" src="graycounter.js"></script> -->
</body>
</html>