-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
67 lines (55 loc) · 2.22 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
<!DOCTYPE HTML>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>逆数の期待値シミュレーター</title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.bundle.js"></script>
<link rel="stylesheet" href="css/style.css">
<script src="./DrawGraph.js"></script>
</head>
<body>
<style>
#ex_chart {
max-width: 80%;
max-height: 80%;
}
</style>
<canvas id="ex_chart"></canvas>
P =
<span style="display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center;">
<span style="padding: 0 10px; border-bottom: 1px solid #000000;">1</span>
<span style="padding: 0 10px;"><input type="number" id='probInput' class="input" min="1" max="1000" step="1"
value="4"></span>
</span>
<button type="submit" id="restartButton" onclick="OnButtonClick();">再シミュレーション</button>
<br>
<br>
期待値(理論値) = <span id="expectation"> 4</span>,
N回の試行回数の平均値 = <span id="averageTryCount"></span>
<script>
// グラフの初期設定
var graphDrawer = new GraphDrawer;
window.onload = graphDrawer.InitializeGraph(4, "ex_chart");
graphDrawer.Plot(10);
// 確率を変えて再シミュレーション
function OnButtonClick() {
graphDrawer.Stop();
var probInput = Number(document.getElementById('probInput').value);
graphDrawer = new GraphDrawer;
graphDrawer.InitializeGraph(probInput, "ex_chart");
graphDrawer.Plot(10);
document.getElementById('expectation').innerText = probInput;
}
// 入力変更時に数値制限をチェック
const inputElem = document.getElementById("probInput");
inputElem.addEventListener("change", update);
function update() {
var probInput = Number(document.getElementById('probInput').value);
if (probInput < 1)
document.getElementById('probInput').value = 1;
if (probInput > 1000)
document.getElementById('probInput').value = 1000;
}
</script>
</body>
</html>