-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
430 lines (389 loc) · 15.2 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
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
<html>
<head>
<title>Ugly calculator using JQuery and math.js</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css">
body {
margin: 0px 0px 0px 0px;
}
/* h1 {
font-family: "Avant Garde", Avantgarde, "Century Gothic", CenturyGothic, "AppleGothic", sans-serif;
font-size: 20px;
padding: 10px 10px;
text-align: center;
text-transform: uppercase;
text-rendering: optimizeLegibility;
color: #e0dfdc;
background-color: #333;
letter-spacing: .1em;
text-shadow: 0 -1px 0 #fff,
0 1px 0 #2e2e2e,
0 2px 0 #2c2c2c,
0 3px 0 #2a2a2a,
0 4px 0 #282828,
0 5px 0 #262626,
0 6px 0 #242424,
0 7px 0 #222,
0 8px 0 #202020,
0 9px 0 #1e1e1e,
0 10px 0 #1c1c1c,
0 11px 0 #1a1a1a,
0 12px 0 #181818,
0 13px 0 #161616,
0 14px 0 #141414,
0 15px 0 #121212,
0 22px 30px rgba(0, 0, 0, 0.9);
} */
#calculator {
font-size: 0px;
width: 300px;
height: 534px;
background-color: #484848;
padding: 20px;
margin: auto;
}
#result {
width: 290px;
height: 120px;
margin-bottom: 0px;
padding: 0px 5px 0px 5px;
background-color: #cddecc;
border-radius: 5px;
display: inline-flex;
justify-content: flex-end;
align-items: center;
overflow: hidden;
box-shadow: inset 0 0px 3px;
font: 20px digital;
}
.key {
width: 65px;
height: 40px;
background-color: #eeeeee;
display: inline-flex;
margin: 3px 10px 5px 0px;
vertical-align: middle;
justify-content: center;
align-items: center;
padding: 0px 0px 5px 0px;
border: none;
border-radius: 20px;
cursor: pointer;
box-shadow: 0 3px 0 #a1a1a1, 0 2px 5px rgba(0, 0, 0, .75);
font: bold 20px sans-serif;
margin-top: 12px;
}
.mf-key {
font: italic 20px "Times New Roman";
width: 65px;
height: 25px;
padding: 5px 0px 5px 0px;
background-color: hsl(303, 82%, 73%);
color: white;
}
.more-key {
font: italic 20px "Times New Roman";
width: 65px;
height: 25px;
padding: 5px 0px 5px 0px;
background-color: hsl(303, 82%, 73%);
color: white;
display: inline-flex;
}
.more2-key {
display: none;
float: right;
vertical-align: baseline;
text-align: center;
}
.symbol-key {
font: italic 20px "Times New Roman"
}
.function-key {
font: italic 25px "Times New Roman";
display: none;
float: left;
vertical-align: baseline;
text-align: center;
}
.del-key {
font: italic 25px "Times New Roman";
display: none;
float: left;
vertical-align: baseline;
text-align: center;
background-color: #f85562;
color: white;
}
.eval-key {
background-color: #4a9840;
color: white;
}
.backspace-key {
background-color: #fb8c00;
color: white;
}
.clear-key {
background-color: #bb1c09;
color: white;
}
.operator-key {
background-color: hsl(303, 82%, 73%);
color: white;
}
.operator2-key {
background-color: hsl(303, 82%, 73%);
color: white;
}
.graph-key {
background-color: rgb(54, 96, 117);
color: white;
font: italic 20px "Times New Roman";
width: 140px;
height: 25px;
padding: 5px 0px 5px 0px;
}
.gclear-key {
background-color: rgb(54, 96, 117);
color: white;
font: italic 20px "Times New Roman";
width: 140px;
height: 25px;
padding: 5px 0px 5px 0px;
display: none;
float: right;
vertical-align: baseline;
text-align: center;
}
.key:active {
background-color: #a1a1a1;
box-shadow: 0 5px #666;
transform: translateY(4px);
}
</style>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js' type='text/javascript'></script>
<script src='math.js' type='text/javascript'></script>
<script src='https://cdn.plot.ly/plotly-1.35.2.min.js' type='text/javascript'></script>
<script src='https://unpkg.com/[email protected]/dist/math.min.js' type='text/javascript'></script>
<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ "HTML-CSS": { scale: 75} });
</script>
<script type="text/javascript">
$(document).ready(function () {
var parser = math.parser();
var arr = new Array();
var displayValue = '0';
$('#result').text(displayValue);
$('.key').each(function (index, key) {
$(this).click(function (e) {
if (displayValue == '0') displayValue = '';
if ($(this).text() == 'EV') {
try {
displayValue = parser.eval(displayValue.replace(/√/gi, 'sqrt')).toString();
var tokens = displayValue.split(' ');
if (tokens[0] == 'function') {
displayValue = tokens[0];
}
$('#result').text(displayValue);
displayValue = '0';
} catch (e) {
displayValue = '0';
if (displayValue != 'function') {
$('#result').text(e);
}
}
} else {
if ($(this).text() == 'CL') {
displayValue = '0';
$('#result').text(displayValue);
} else if ($(this).text() == '⌫') {
var l = displayValue.length - 1;
displayValue = displayValue.substring(0, l);
$('#result').text(displayValue);
if (displayValue == '') {
displayValue = '0';
$('#result').text(displayValue);
}
} else if ($(this).text() == 'more') {
$('.num-key').toggle("fast");
$('.operator2-key').toggle("fast");
$('.graph-key').toggle("fast");
$('.mf-key').toggle("fast");
$('.more2-key').toggle("fast");
} else if ($(this).text() == 'Func') {
$('.num-key').toggle("fast");
$('.graph-key').toggle("fast");
$('.more-key').toggle("fast");
$('.function-key').toggle("fast");
$('.operator2-key').toggle("fast");
$('.del-key').toggle("fast");
} else if ($(this).text() == 'Graph') {
$('.graph-key').hide();
$('.num-key').toggle("fast");
$('.more-key').toggle("fast");
$('.mf-key').toggle("fast");
$('.operator2-key').toggle("fast");
$('.clear-key').toggle("fast");
$('.eval-key').toggle("fast");
$('.backspace-key').toggle("fast");
$('.operator-key').toggle("fast");
$('.gclear-key').toggle("fast");
draw(arr);
arr = [];
} else if ($(this).text() == 'save') {
arr.push(displayValue);
displayValue = '0';
$('#result').text(displayValue);
} else if ($(this).text() == 'del') {
arr = [];
alert('save 초기화!');
displayValue = '0';
$('#result').text(displayValue);
} else if ($(this).text() == 'G.CL') {
location.reload();
}
else {
displayValue += $(this).text();
$('#result').text(displayValue);
}
}
e.preventDefault()
})
})
})
</script>
</head>
<body>
<!-- <h1>
Project Calculator 3
</h1> -->
<div id="calculator">
<div id="result"></div>
<div id="plot"></div>
<span class="key operator-key">(</span>
<span class="key operator-key">)</span>
<span class="key operator-key">√</span>
<span class="key operator-key">^</span>
<span class="key clear-key">CL</span>
<span class="key eval-key">EV</span>
<span class="key backspace-key">⌫</span>
<span class="key operator-key">+</span>
<span class="key num-key">7</span>
<span class="key num-key">8</span>
<span class="key num-key">9</span>
<span class="key operator2-key">-</span>
<span class="key num-key">4</span>
<span class="key num-key">5</span>
<span class="key num-key">6</span>
<span class="key operator2-key">*</span>
<span class="key num-key">1</span>
<span class="key num-key">2</span>
<span class="key num-key">3</span>
<span class="key function-key">exp</span>
<span class="key function-key">log</span>
<span class="key function-key">sin</span>
<span class="key operator2-key">/</span>
<span class="key num-key">,</span>
<span class="key num-key">0</span>
<span class="key num-key">.</span>
<span class="key function-key">cos</span>
<span class="key function-key">tan</span>
<span class="key function-key">cross</span>
<span class="key operator2-key">%</span>
<span class="key more2-key">>=</span>
<span class="key more2-key">
<=</span>
<span class="key more2-key">]</span>
<span class="key more2-key">[</span>
<span class="key more2-key">></span>
<span class="key more2-key">
<</span>
<span class="key more2-key">:</span>
<span class="key more2-key">==</span>
<span class="key more2-key">!=</span>
<span class="key more2-key">i</span>
<span class="key more2-key">=</span>
<span class="key more2-key">pi</span>
<span class="key more2-key">z</span>
<span class="key more2-key">y</span>
<span class="key more2-key">x</span>
<span class="key more2-key">e</span>
<span class="key more2-key">f</span>
<span class="key more-key">more</span>
<span class="key function-key">det</span>
<span class="key function-key">inv</span>
<span class="key function-key">save</span>
<span class="key mf-key">Func</span>
<span class="key graph-key">Graph</span>
<span class="key gclear-key">G.CL</span>
<span class="key del-key">del</span>
<span class="key more2-key">g</span>
<span class="key more2-key">w</span>
</div>
<script>
function draw(arr) {
try {
if (arr[1]) {
// compile the expression once
var expression1 = arr[0];
var expression2 = arr[1];
var expr1 = math.compile(expression1);
var expr2 = math.compile(expression2);
var xValues1 = math.range(-10, 10, 0.1).toArray();
var yValues1 = xValues1.map(function (x) {
return expr1.eval({ x: x });
});
// evaluate the expression repeatedly for different values of x
var xValues2 = math.range(-10, 10, 0.1).toArray();
var yValues2 = xValues2.map(function (x) {
return expr2.eval({ x: x });
});
// render the plot using plotly
var trace1 = {
x: xValues1,
y: yValues1,
type: 'scatter',
name: arr[0]
};
var trace2 = {
x: xValues2,
y: yValues2,
type: 'scatter',
name: arr[1]
};
var data = [trace1, trace2];
} else {
var expression1 = arr[0];
var expr1 = math.compile(expression1);
// evaluate the expression repeatedly for different values of x
var xValues1 = math.range(-10, 10, 0.1).toArray();
var yValues1 = xValues1.map(function (x) {
return expr1.eval({ x: x });
});
// render the plot using plotly
var trace1 = {
x: xValues1,
y: yValues1,
type: 'scatter',
name: arr[0]
};
var data = [trace1];
}
// var data = [trace1, trace2];
var layout = {
title: 'Graph',
showlegend: true
};
Plotly.newPlot('plot', data, layout, { displayModeBar: false });
}
catch (err) {
console.error(err);
alert(err);
}
}
</script>
</body>
</html>