-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
95 lines (74 loc) · 4.15 KB
/
Copy pathindex.html
File metadata and controls
95 lines (74 loc) · 4.15 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Golden Spiral</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="css/styles.css" type="text/css" />
</head>
<body>
<div class="container">
<header>
<h1>Golden Spiral</h1>
</header>
<div class="row">
<div id="spiral" class="col-12 col-md-8">
<canvas id="spiral-canvas" width="1000px" height="1000px"></canvas>
</div>
<div id="fraction" class="col-12 col-md-4">
<input id="number" type="number" onchange="updateNumber()" value="" step="0.01" min="0" />
<hr/>
<h2>Presets</h2>
<button id="preset-phi" class="btn" onclick="document.getElementById('number').value = (1+Math.sqrt(5))/2; updateNumber();">$\varphi$</button>
<button id="preset-pi" class="btn" onclick="document.getElementById('number').value = Math.PI; updateNumber();">$\pi$</button>
<button id="preset-sqrt2" class="btn" onclick="document.getElementById('number').value = Math.sqrt(2); updateNumber();">$\sqrt{2}$</button>
<button id="preset-sqrt3" class="btn" onclick="document.getElementById('number').value = Math.sqrt(3); updateNumber();">$\sqrt{3}$</button>
<hr/>
<h2>Continued fraction</h2>
<div id="latex"></div>
</div>
</div>
<hr/>
<div class="row justify-content-center">
<a class="github-button" href="https://github.com/KinoxKlark/golden-spiral" data-icon="octicon-star" data-size="large" aria-label="Star KinoxKlark/golden-spiral on GitHub">Star</a>
<a class="github-button" href="https://github.com/KinoxKlark/golden-spiral/fork" data-icon="octicon-repo-forked" data-size="large" aria-label="Fork KinoxKlark/golden-spiral on GitHub">Fork</a>
<a class="github-button" href="https://github.com/KinoxKlark/golden-spiral/issues" data-icon="octicon-issue-opened" data-size="large" aria-label="Issue KinoxKlark/golden-spiral on GitHub">Issue</a>
<a class="github-button" href="https://github.com/KinoxKlark/golden-spiral/archive/master.zip" data-icon="octicon-cloud-download" data-size="large" aria-label="Download KinoxKlark/golden-spiral on GitHub">Download</a>
</div>
</div>
<script async defer src="https://buttons.github.io/buttons.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/MathJax.js?config=TeX-MML-AM_CHTML' async></script>
<script src="javascript/script.js"></script>
<script>
var canvas = document.getElementById('spiral-canvas');
var phi = (1+Math.sqrt(5))/2;
document.getElementById("number").value = phi;
updateNumber();
function updateNumber()
{
var number = document.getElementById("number").value;
drawSpiral(number, canvas);
var seq = getContinuedFractionSequence(number, 5);
var fraction = writeFraction(seq);
function writeFraction(seq) {
var fraction = "";
var integer = seq.shift();
if(integer == -1) return "\\ddots";
if(integer != 0) fraction += integer;
if(integer != 0 && seq.length > 0) fraction += " + ";
if(seq.length > 0) fraction += "\\frac{1}{"+writeFraction(seq)+"}";
return fraction;
}
document.getElementById('latex').innerHTML = "$$"+fraction+"$$";
if(typeof MathJax !== 'undefined') MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
}
</script>
</body>
</html>