-
Notifications
You must be signed in to change notification settings - Fork 0
/
canusee.html
227 lines (212 loc) · 6.88 KB
/
canusee.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
<!DOCTYPE HTML>
<html lang = "th-TH">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>เห็น ก ข</title>
<style>
button {
height: 40px;
width: 40px;
font-size: 34px;
margin: 2px 2px;
cursor: pointer;
border-radius: 25%;
}
/* simulate lighting */
@keyframes bgc {
0% {background-color: #ffffff;}
25% {background-color: #f2f2f2;}
50% {background-color: #e6e6e6;}
100% {background-color: #d9d9d9;}
}
#board{
width: 360px;
height: 360px;
padding: 10px;
position: relative;
/* background: white;
animation-name: bgc;
animation-duration: 20s;
*/
}
/* choose z-index by the width|height of board in px */
@keyframes grow {
from { transform: scale(1); opacity: 1.0; z-index: 0;}
to { transform: scale(100); opacity: 0.1; z-index: 360;}
}
#opt {
width: 1%;
height: 1%;
border: none;
display: none;
top: 50%;
left: 50%;
position: absolute;
background-color: transparent;
-webkit-animation-name: grow;
-moz-animation-name: grow;
-ms-animation-name: grow;
animation-name: grow;
animation-delay: 0.1s;
-webkit-animation-duration: 10s;
-moz-animation-duration: 10s;
-ms-animation-duration: 10s;
animation-duration: 10s;
animation-timing-function: cubic-bezier(0.95,0.2,0.95,0.4);
animation-iteration-count: 1;
}
/* set answer patterns */
#b0 img {transform: rotate(0deg);}
#b1 img {transform: rotate(90deg);}
#b2 img {transform: rotate(180deg);}
#b3 img {transform: rotate(270deg);}
input {
font-size: 32px;
background-color: lightblue;
}
</style>
</head>
<body>
<h2>เหมือนตัวไหนเอ่ย?</h2>
<div>
   เลือก :
<input type="checkbox" id="eyeL"/>
<label for="eyeL">👁️🤚️</label>  
<input type="checkbox" id="eyeR"/>
<label for="eyeR">🤚️👁️</label>  
<input type="checkbox" id="eyeB"/>
<label for="eyeB">👁️👁️</label>
 
<button id="btn" onclick="start()">▶️</button>
</div>
<div id="board">
<div>
<img id='opt' src='image/Landolt-96.jpg'>
</div>
</div>
<p>   
<button id="b0" class="ans">
<img src="image/Landolt-96.jpg" width=32 height=32></button>
<button id="b1" class="ans">
<img src="image/Landolt-96.jpg" width=32 height=32></button>
<button id="b2" class="ans">
<img src="image/Landolt-96.jpg" width=32 height=32></button>
<button id="b3" class="ans"">
<img src="image/Landolt-96.jpg" width=32 height=32></button>
   
<button id="b4" onclick="help()" width=32 height=32>❓️</button>
</p>
<p id="msg">กดปุ่มที่เหมือนกับรูปที่เห็นข้างบน</p>
<script src="script/beeper.js" type="text/javascript"></script>
<script>
//pause opticon to prepare varibles, etc
var opt = document.getElementById("opt");
opt.style.animationPlayState = 'paused';
var eyeL = document.getElementById("eyeL");
var eyeR = document.getElementById("eyeR");
var eyeB = document.getElementById("eyeB");
var counter = 0;
var state = 0;
var OKbtn=""; //Correct answer/pattern
var rnd = [0,1,2,3].sort(() => Math.random() - 0.5); //shuffle
var optn = 0; //save the selected number for matching with ans
var eye = 0; //0=eyeL, 1=eyeR, 2=eyeB
var optsize; //opticon size at 'freeze' > actual by f(reaction time)
var ndegs = ['0deg','90deg','180deg','270deg'];
var eyecon = ['🤚️👁️:',' 👁️🤚️:','👁️👁️:'];
var results=[]; //array of result = "eye opt optsize"
function freeze() {
//using z-index/360 as approx opticon size; small is good, 0.3+ needs 'real' tests
optsize = parseInt(window.getComputedStyle(opt).getPropertyValue('z-index'))/360;
if (opt.style.animationPlayState == 'paused') {
//console.log("test running "+ optsize);
opt.style.animationPlayState = 'running';
} else {
//console.log("test paused "+ optsize);
opt.style.animationPlayState = 'paused';
}
}
function start(){
//check eye to test; if not selected assume eyeB
if (!(eyeL.checked||eyeR.checked||eyeR.checked)) eyeB.checked = true;
if (eyeL.checked) { eye=0;board.style.borderLeft = "solid #0000FF";}
if (eyeR.checked) { eye=1;board.style.borderRight = "solid #000FFF";}
if (eyeB.checked) { eye=2;board.style.borderTop = "solid #00000F";}
newTest();
var optx = rnd[optn]; //randomly select nth pattern
//console.log("rotate="+ optx + " ="+ndegs[optx]);
opt.style.rotate = ndegs[optx];
OKbtn="b"+optx; //correct button expected **Global**
optn++;
if (optn>3) optn=0;
opt.style.animationPlayState = 'running';
opt.style.display="block"; //turn the display
}
function ping(x){
counter++;
//beep to acknowledge reading
//f=135,dur=250 for No; f=485,dur=125 for Yes
if (x==0) { freq=128; dur=250; }
else { freq=513; dur=125; }
beep(freq, 0, 0.1, dur);
}
//add a click listener to board to freeze animation
var board = document.getElementById("board");
board.addEventListener("click", freeze); //click anywhere in board
// add a click listener to answer buttons
var ans = document.getElementsByClassName("ans");
var whichbtn = e => {
var answer;
const isButton = e.target.nodeName === 'BUTTON';
if (!isButton) {
//console.log(e.target.parentNode.id);
answer=e.target.parentNode.id; //id of img's parent ie. button
} else {
//console.log(e.target.id +" button clicked"); //ID of the button
answer=e.target.id; //id of button
}
if (answer==OKbtn) {
ping(1);
var result = eyecon[eye]+" "+OKbtn+" "+optsize.toFixed(3);
results.push(result);
//console.log(results);
opt.style.display="none"; //
}else {
ping(0);
//continue on
}
}
for (let an of ans) {
an.addEventListener("click", whichbtn);
}
function newTest(){
//trigger a DOM reflow while it is in 'paused'
opt.classList.remove("grow");
opt.style.width="1%";
opt.style.height="1%";
void opt.offsetWidth;
opt.classList.add("grow");
}
function help(){
var msg = document.getElementById("msg");
if (!counter) {
msg.innerText='เลือก และปิดตา ตาขวา หรือ ตาซ้าย หรือ ไม่ปิด แล้ว กด ▶️ \n'+
'ทันทีที่เห็นว่าเป็น รูปอะไร แตะ หรือ กด จอ ให้รูปหยุดโต \n'+
'เลือกกด ปุ่มรูปเหมือนกัน ข้างบน \n'+
'* ควรลอง ตาขวา ตาซ้าย และ ทั้งสองตา *'
} else {
if (results.length==0){
msg.innerText='กดปุ่มที่เหมือนกับรูปที่เห็นข้างบน';
} else {
msg.innerText="ทดลองแล้ว: ตา รูป ขนาด";
for (let i=0;i<results.length;i++) {
//console.log("help "+i+" "+results[i]);
msg.innerText += '\n '+results[i];
}
}
}
}
</script>
</body>
</html>