|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+<!DOCTYPE html>
|
|
|
2
|
+<html>
|
|
|
3
|
+<head>
|
|
|
4
|
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/12.1.0/math.js"></script>
|
|
|
5
|
+ <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
|
|
|
6
|
+ <style>
|
|
|
7
|
+ input[type=text]{
|
|
|
8
|
+ --O_ROLOC_O_COLOR_O:#F2F2F2;
|
|
|
9
|
+ --O_SUIDAR_RULB_O_BLUR_RADIUS_O:0PX;
|
|
|
10
|
+ --O_SUIDAR_DAERPS_O_SPREAD_RADIUS_O:1.0PX;
|
|
|
11
|
+ BOX-SHADOW:INSET 0 0 VAR(--O_SUIDAR_RULB_O_BLUR_RADIUS_O) VAR(--O_SUIDAR_DAERPS_O_SPREAD_RADIUS_O) VAR(--O_ROLOC_O_COLOR_O),0 0 VAR(--O_SUIDAR_RULB_O_BLUR_RADIUS_O) VAR(--O_SUIDAR_DAERPS_O_SPREAD_RADIUS_O) VAR(--O_ROLOC_O_COLOR_O)!IMPORTANT;
|
|
|
12
|
+ BORDER-WIDTH:0;BORDER-RADIUS:65536PX;OVERFLOW:VISIBLE
|
|
|
13
|
+ }
|
|
|
14
|
+ input[type=text]:focus{
|
|
|
15
|
+ border-color: #CECECE;BORDER-WIDTH:0PX;border-style: solid;outline: 1PX SOLID #E7E7E7;
|
|
|
16
|
+ }
|
|
|
17
|
+ input[type=range]::-moz-range-track {
|
|
|
18
|
+ HEIGHT:0PX;
|
|
|
19
|
+ --O_ROLOC_O_COLOR_O:#F2F2F2;
|
|
|
20
|
+ --O_SUIDAR_RULB_O_BLUR_RADIUS_O:0PX;
|
|
|
21
|
+ --O_SUIDAR_DAERPS_O_SPREAD_RADIUS_O:1.0PX;
|
|
|
22
|
+ BOX-SHADOW:INSET 0 0 VAR(--O_SUIDAR_RULB_O_BLUR_RADIUS_O) VAR(--O_SUIDAR_DAERPS_O_SPREAD_RADIUS_O) VAR(--O_ROLOC_O_COLOR_O),0 0 VAR(--O_SUIDAR_RULB_O_BLUR_RADIUS_O) VAR(--O_SUIDAR_DAERPS_O_SPREAD_RADIUS_O) VAR(--O_ROLOC_O_COLOR_O)!IMPORTANT;
|
|
|
23
|
+ BORDER-WIDTH:0;BORDER-RADIUS:65536PX;OVERFLOW:HIDDEN
|
|
|
24
|
+ }
|
|
|
25
|
+
|
|
|
26
|
+ input[type=range]::-moz-range-thumb {
|
|
|
27
|
+ HEIGHT:16PX;WIDTH:16PX;
|
|
|
28
|
+ --O_ROLOC_O_COLOR_O:#F2F2F2;
|
|
|
29
|
+ --O_SUIDAR_RULB_O_BLUR_RADIUS_O:0PX;
|
|
|
30
|
+ --O_SUIDAR_DAERPS_O_SPREAD_RADIUS_O:1.0PX;
|
|
|
31
|
+ BOX-SHADOW:INSET 0 0 VAR(--O_SUIDAR_RULB_O_BLUR_RADIUS_O) VAR(--O_SUIDAR_DAERPS_O_SPREAD_RADIUS_O) VAR(--O_ROLOC_O_COLOR_O),0 0 VAR(--O_SUIDAR_RULB_O_BLUR_RADIUS_O) VAR(--O_SUIDAR_DAERPS_O_SPREAD_RADIUS_O) VAR(--O_ROLOC_O_COLOR_O)!IMPORTANT;
|
|
|
32
|
+ BORDER-WIDTH:0;BORDER-RADIUS:65536PX;OVERFLOW:HIDDEN
|
|
|
33
|
+ }
|
|
|
34
|
+ </style>
|
|
|
35
|
+</head>
|
|
|
36
|
+<body style="background:#FFFFFF;font-size:16px;MARGIN:0;COLOR:#CECECE">
|
|
|
37
|
+<div align="center">
|
|
|
38
|
+ 𓊗<br><span id="nVal"></span><br><input type="range" id="n" min="1" max="16" value="8" style="width:100%"><br>
|
|
|
39
|
+ ✤<br><span id="toVal"></span><br><input type="range" id="to" min="-12.566370614359172953850573533118" max="12.566370614359172953850573533118" value="6.283185307179586476925286766559" step="0.785398163397448" style="width:100%;color:#CECECE"><br>
|
|
|
40
|
+ ꗳ<br><span id="fromVal"></span><br><input type="range" id="from" min="-12.566370614359172953850573533118" max="12.566370614359172953850573533118" value="-6.283185307179586476925286766559" step="0.785398163397448" style="width:100%;color:#CECECE"><br>
|
|
|
41
|
+ <input type="text" id="formula" value="(1-cos(x*(4)/2))/2 ; acos(cos(x*(4)/2))/pi" style="width:100%; text-align:CENTER;COLOR:#CECECE;FONT-SIZE:16PX"><br>
|
|
|
42
|
+ <div id="k-graph"></div>
|
|
|
43
|
+ <div id="function-graph"></div>
|
|
|
44
|
+ <script>
|
|
|
45
|
+ function clamp(x) {return math.max(math.min(x,1),0)}
|
|
|
46
|
+
|
|
|
47
|
+ // JS equivalent for the map function
|
|
|
48
|
+ function arrayMax(arr) {
|
|
|
49
|
+ return Math.max(...arr.map(e => Math.max(...e)));
|
|
|
50
|
+ }
|
|
|
51
|
+ function arrayMin(arr) {
|
|
|
52
|
+ return Math.min(...arr.map(e => Math.min(...e)));
|
|
|
53
|
+ }
|
|
|
54
|
+
|
|
|
55
|
+ function plot() {
|
|
|
56
|
+ var formulas = document.getElementById('formula').value.split(";");
|
|
|
57
|
+ var fromPIO2 = Number(document.getElementById('from').value);
|
|
|
58
|
+ var toPIO2 = Number(document.getElementById('to').value);
|
|
|
59
|
+ var N = Number(document.getElementById('n').value);
|
|
|
60
|
+
|
|
|
61
|
+ var num_points = 0 + 2 ** N;
|
|
|
62
|
+ document.getElementById('fromVal').innerText = +fromPIO2;
|
|
|
63
|
+ document.getElementById('toVal').innerText = +toPIO2;
|
|
|
64
|
+ document.getElementById('nVal').innerText = +N;
|
|
|
65
|
+
|
|
|
66
|
+ var from = fromPIO2;
|
|
|
67
|
+ var to = toPIO2;
|
|
|
68
|
+
|
|
|
69
|
+ var step = (to - from) / num_points;
|
|
|
70
|
+ var x_vals = math.range(from, to, step, true).toArray();
|
|
|
71
|
+
|
|
|
72
|
+ var k_trace = [];
|
|
|
73
|
+ var function_trace = [];
|
|
|
74
|
+
|
|
|
75
|
+ var all_x = [];
|
|
|
76
|
+ var all_y = [];
|
|
|
77
|
+
|
|
|
78
|
+ formulas.map((formula, i) => {
|
|
|
79
|
+ var scope = {
|
|
|
80
|
+ clamp: function(x) { return math.max(math.min(x, 1), 0); }
|
|
|
81
|
+ };
|
|
|
82
|
+ var kappa_vals = x_vals.map(x => math.evaluate(formula.trim(), { x: x, ...scope}));
|
|
|
83
|
+ var theta_vals = math.map(math.cumsum(kappa_vals), x => x * step);
|
|
|
84
|
+ var x_coords = math.map(math.cumsum(math.map(theta_vals, math.cos)), x => x * step);
|
|
|
85
|
+ var y_coords = math.map(math.cumsum(math.map(theta_vals, math.sin)), x => x * step);
|
|
|
86
|
+
|
|
|
87
|
+ if (x_coords[0] != 0 || y_coords[0] != 0) {
|
|
|
88
|
+ x_coords.unshift(0);
|
|
|
89
|
+ y_coords.unshift(0);
|
|
|
90
|
+ }
|
|
|
91
|
+
|
|
|
92
|
+ k_trace.push({
|
|
|
93
|
+ x: x_coords,
|
|
|
94
|
+ y: y_coords,
|
|
|
95
|
+ mode: 'lines',
|
|
|
96
|
+ // line: { color: '#CECECE' }
|
|
|
97
|
+ line: {width: 1},
|
|
|
98
|
+ hovertemplate: 'X:%{x:.256f}' + '<br>Y:%{y:.256f}',
|
|
|
99
|
+ name: ''
|
|
|
100
|
+ });
|
|
|
101
|
+
|
|
|
102
|
+ all_x.push(x_coords);
|
|
|
103
|
+ all_y.push(y_coords);
|
|
|
104
|
+
|
|
|
105
|
+ // Now creating the trace for y=f(x)
|
|
|
106
|
+ var y_vals = x_vals.map(x => math.evaluate(formula.trim(), { x: x, ...scope}));
|
|
|
107
|
+
|
|
|
108
|
+ function_trace.push({
|
|
|
109
|
+ x: x_vals,
|
|
|
110
|
+ y: y_vals,
|
|
|
111
|
+ mode: 'lines',
|
|
|
112
|
+ // optional features
|
|
|
113
|
+ // line: { color: '#CECECE' }
|
|
|
114
|
+ line: {width: 1},
|
|
|
115
|
+ hovertemplate: 'X:%{x:.256f}' + '<br>Y:%{y:.256f}',
|
|
|
116
|
+ name: ''
|
|
|
117
|
+ });
|
|
|
118
|
+
|
|
|
119
|
+ all_x.push(x_vals);
|
|
|
120
|
+ all_y.push(y_vals);
|
|
|
121
|
+ });
|
|
|
122
|
+
|
|
|
123
|
+ var layout = {
|
|
|
124
|
+ margin: { l: 0, r: 0, b: 0, t: 0, pad: 0 },
|
|
|
125
|
+ autosize: true,
|
|
|
126
|
+ height: 312,
|
|
|
127
|
+ xaxis: {scaleanchor:'y',scaleratio: 1, showgrid:true,zeroline:true,zerolinecolor:'#CECECE',zerolinewidth:2,tick0:0,dtick:1,showticklabels:true ,automargin:true,gridcolor:'#CECECE',tickfont:{color:'#CECECE',size:16}},
|
|
|
128
|
+ yaxis: {range: [arrayMin(all_y), arrayMax(all_y)],showgrid:true,zeroline:true,zerolinecolor:'#CECECE',zerolinewidth:2,tick0:0,dtick:1,showticklabels:true ,automargin:true,gridcolor:'#CECECE',tickfont:{color:'#CECECE',size:16}},
|
|
|
129
|
+ hovermode: 'closest',
|
|
|
130
|
+ showlegend: false,
|
|
|
131
|
+ hoverlabel: { bgcolor: "#FFFFFF", font_color: '#9C9C9C', bordercolor: "#CECECE", font_size: 16 }
|
|
|
132
|
+ }
|
|
|
133
|
+
|
|
|
134
|
+ Plotly.newPlot('k-graph', k_trace, layout);
|
|
|
135
|
+ Plotly.newPlot('function-graph', function_trace, layout);
|
|
|
136
|
+ }
|
|
|
137
|
+
|
|
|
138
|
+ plot();
|
|
|
139
|
+
|
|
|
140
|
+ document.getElementById('formula').addEventListener('input', plot);
|
|
|
141
|
+ document.getElementById('from').addEventListener('input', plot);
|
|
|
142
|
+ document.getElementById('to').addEventListener('input', plot);
|
|
|
143
|
+ document.getElementById('n').addEventListener('input', plot);
|
|
|
144
|
+ </script>
|
|
|
145
|
+</div>
|
|
|
146
|
+</body>
|
|
|
147
|
+</html>
|