-
Notifications
You must be signed in to change notification settings - Fork 0
/
to-past.html
177 lines (152 loc) · 7.03 KB
/
to-past.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
<!DOCTYPE html>
<html>
<head>
<script>
var canvas;
var ctx;
var radius;
var wrong = 0;
var correct = 0;
var current = "";
var digitalAnalogMode = "both";
var pauseAfterWrong = true;
function start(){
canvas = document.getElementById("canvas");
ctx = canvas.getContext("2d");
radius = canvas.height / 2;
ctx.translate(radius, radius);
radius = radius * 0.90
drawClock();
}
function setMode(mode){
digitalAnalogMode = mode;
}
function answerClicked(correctanswer){
if(current !== correctanswer){
if(pauseAfterWrong){
alert("You said:\n\n " + correctanswer + " \n\nThats incorrect, look at the clock and learn from your mistake.");
}
wrong++;
document.body.style.backgroundColor = 'red';
}else{
correct++;
document.body.style.backgroundColor = 'green';
}
drawClock();
drawCorrectness();
}
function drawCorrectness(){
document.getElementById("correct").value = correct;
document.getElementById("wrong").value = wrong;
}
function drawClock() {
var digitalOrAnalog = digitalAnalogMode == "digital" ? 1 : digitalAnalogMode == "analog" ? 0 : Math.floor(Math.random() * 2);
if(digitalOrAnalog === 1){
document.getElementById("canvas").style.display = 'none';
document.getElementById("digitalclock").style.display = 'block';
}else{
document.getElementById("canvas").style.display = 'block';
document.getElementById("digitalclock").style.display = 'none';
}
var hour = Math.floor(Math.random() * 12) + 1;
var minute = Math.floor(Math.random() * 60);
drawFace(ctx, radius);
drawNumbers(ctx, radius);
drawTime(ctx, radius, hour,minute);
document.getElementById("digitalclockhour").value = hour < 10 ? "0" + hour : hour;
document.getElementById("digitalclockminute").value = minute < 10 ? "0" + minute : minute;
if(minute === 0){
current = "oclock";
}else if(minute == 30){
current = "halfpast";
}else{
current = minute > 30 ? "to" : "past";
}
}
function drawFace(ctx, radius) {
var grad;
ctx.beginPath();
ctx.arc(0, 0, radius, 0, 2*Math.PI);
ctx.fillStyle = 'white';
ctx.fill();
grad = ctx.createRadialGradient(0,0,radius*0.95, 0,0,radius*1.05);
grad.addColorStop(0, '#333');
grad.addColorStop(0.5, 'white');
grad.addColorStop(1, '#333');
ctx.strokeStyle = grad;
ctx.lineWidth = radius*0.1;
ctx.stroke();
ctx.beginPath();
ctx.arc(0, 0, radius*0.1, 0, 2*Math.PI);
ctx.fillStyle = '#333';
ctx.fill();
}
function drawNumbers(ctx, radius) {
var ang;
var num;
ctx.font = radius*0.15 + "px arial";
ctx.textBaseline="middle";
ctx.textAlign="center";
for(num = 1; num < 13; num++){
ang = num * Math.PI / 6;
ctx.rotate(ang);
ctx.translate(0, -radius*0.85);
ctx.rotate(-ang);
ctx.fillText(num.toString(), 0, 0);
ctx.rotate(ang);
ctx.translate(0, radius*0.85);
ctx.rotate(-ang);
}
}
function drawTime(ctx, radius, hour, minute){
var second = 0
//hour
hour=hour%12;
hour=(hour*Math.PI/6)+
(minute*Math.PI/(6*60))+
(second*Math.PI/(360*60));
drawHand(ctx, hour, radius*0.5, radius*0.07);
//minute
minute=(minute*Math.PI/30)+(second*Math.PI/(30*60));
drawHand(ctx, minute, radius*0.8, radius*0.07);
}
function drawHand(ctx, pos, length, width) {
ctx.beginPath();
ctx.lineWidth = width;
ctx.lineCap = "round";
ctx.moveTo(0,0);
ctx.rotate(pos);
ctx.lineTo(0, -length);
ctx.stroke();
ctx.rotate(-pos);
}
function pauseAfterWrongToggle(input){
pauseAfterWrong = input;
}
</script>
</head>
<body onload="start()">
<div style="float:left;display:block;width:50%">
<canvas style="display:none" id="canvas" width="400" height="400" style="background-color:#333">
</canvas>
<div id="digitalclock" style="font-size:150px">
<input type="text" id="digitalclockhour" style="font-size:150px;width:180px;height:400px;" value="11"/>:<input type="text" id="digitalclockminute" style="font-size:150px;width:180px;height:400px;" value="12"/>
</div>
<input type="Button" id="to" value="To" onclick="answerClicked('to')" style="width:200px;height:200px;font-size:30px;" />
<input type="Button" id="past" value="Past" onclick="answerClicked('past')" style="width:200px;height:200px;font-size:30px;"/><br />
<input type="Button" id="halfpast" value="Half past" onclick="answerClicked('halfpast')" style="width:200px;height:200px;font-size:30px;" />
<input type="Button" id="oclock" value="OClock" onclick="answerClicked('oclock')" style="width:200px;height:200px;font-size:30px;"/><br />
<br /><br /><br /><br />
</div>
<div>
<h3>Correct</h3> <input id="correct" style="background-color:green;font-size:30px;color:white;text-align:center;" value="0" readonly />
<h3>Incorrect</h3> <input id="wrong" style="background-color:red;font-size:30px;color:white;text-align:center" value="0" readonly />
</div>
<br />
<h3>Settings</h3>
<input type="radio" name="clockmode" value="digital" onclick="setMode(this.value)">Only digital clock<br />
<input type="radio" name="clockmode" value="analog" onclick="setMode(this.value)">Only analog clock<br />
<input type="radio" name="clockmode" value="both" checked onclick="setMode(this.value)">Both<br />
<input type="checkbox" name="pauseAfterWrong" onclick="pauseAfterWrongToggle(this.checked)" checked />Pause after wrong answer
</body>
</html>