-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
145 lines (132 loc) · 6.13 KB
/
index.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
<!DOCTYPE html>
<html lang="zh-Hant-TW">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
<meta name="description" content="建構式數學計算步驟產生器">
<meta name="author" content="Tsai-Fu-Hsuan">
<title>建構式數學計算步驟產生器</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.1/katex.min.css">
<style>
#normal {
font-size: 5em !important;
}
#step {
font-size: 3em !important;
}
.row {
padding: 15px 0px 15px 0px;
}
.result {
font-size: 2em;
}
.box {
padding: 15px 0px 30px 0px;
}
</style>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-12 text-center">
<form class="form-inline" id="calmath" autocomplete="off">
<div class="form-group">
<input type="text" class="form-control" id="number1" name="number1">
</div>
<div class="form-group">
<label class="radio-inline">
<input type="radio" name="calmethod" id="times" value="times"> ×
</label>
<label class="radio-inline">
<input type="radio" name="calmethod" id="divide" value="divide"> ÷
</label>
</div>
<div class="form-group">
<input type="text" class="form-control" id="number2" name="number2">
</div>
<button type="submit" class="btn btn-primary">產生步驟</button>
</form>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-md-4 text-center box"> <p class="result">直式</p> <span id="normal"></span> </div>
<div class="col-xs-12 col-md-8 text-center box"> <p class="result">橫式</p> <span id="step"></span ></div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.1/katex.min.js"></script>
<script>
$('#calmath').bind('submit', function(e) {
e.preventDefault();
switch ( this.calmethod.value ) {
case 'times':
var colorgenerator = getRandomColor();
//console.log(colorgenerator.next().value);
var ans = this.number1.value * this.number2.value
var tmp = 0;
var result = 0;
var render = '';
var color1 = colorgenerator.next().value;
var color2 = colorgenerator.next().value;
katex.render('\\frac{ \\begin{array}{rr} &' + this.number1.value + '\\\\ \\times &' + this.number2.value + '\\end{array} }{ \\begin{array}{} \\phantom{X} &' + ans + '\\end{array} }', normal);
if (this.number2.value > 5) {
var count = 0;
for (i = 0; i < this.number2.value; i++) {
result = Number(tmp) + Number(this.number1.value);
render += '\\color{' + color1 + '}{' + tmp + '} +' + this.number1.value + '= \\color{' + color2 + '}{' + result + '} \\\\ ';
color1 = color2;
color2 = colorgenerator.next().value;
katex.render('\\begin{array}{rr}' + render + '\\end{array}', step);
tmp = result;
}
} else {
for (i = 0; i < this.number2.value; i++) {
result = Number(tmp) + Number(this.number1.value);
render += '\\color{' + color1 + '}{' + tmp + '} +' + this.number1.value + '= \\color{' + color2 + '}{' + result + '} \\\\ ';
color1 = color2;
color2 = colorgenerator.next().value;
katex.render('\\begin{array}{rr}' + render + '\\end{array}', step);
tmp = result;
}
}
break;
case 'divide':
var colorgenerator = getRandomColor();
//console.log(colorgenerator.next().value);
var ans = 0;
var result = 0;
var count = 0;
var render = '';
var color1 = colorgenerator.next().value;
var color2 = colorgenerator.next().value;
var tmp = this.number1.value;
while (Number(tmp) >= Number(this.number2.value)) {
result = Number(tmp) - Number(this.number2.value);
render += '\\color{' + color1 + '}{' + tmp + '} -' + this.number2.value + '= \\color{' + color2 + '}{' + result + '} \\\\ ';
color1 = color2;
color2 = colorgenerator.next().value;
katex.render('\\begin{array}{rr}' + render + '\\end{array}', step);
tmp = result;
count++;
}
katex.render('', normal);
katex.render('\\begin{array}{rr}' + render + '\\\\ \\text{商: }' + count + ' \\\\ \\text{餘數: }' + result + ' \\end{array}', step);
break;
}
});
function * getRandomColor() {
var letters = '0123456789ABCDEF';
while(true) {
var color = '#';
for (var i = 0; i < 6; i++ ) {
color += letters[Math.floor(Math.random() * 16)];
}
yield color;
}
}
</script>
</body>
</html>