forked from curvenote/article
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
372 lines (347 loc) · 18.4 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
<!DOCTYPE html>
<html>
<head>
<title><%= htmlWebpackPlugin.options.title %></title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,700&display=swap">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Noto+Sans|Noto+Serif:400,400i,700,700i&display=swap" type="text/css" />
<link rel="stylesheet" href="curvenote.css" type="text/css">
<link rel="stylesheet" href="theme.css" type="text/css">
<body>
<nav class="popout centered">
<div>Documentation</div>
<ul>
<li><a href="/">curvenote.dev</a></li>
<li><a href="/introduction">Introduction</a></li>
<li><a href="/article">Article</a></li>
<li class="section">
<div>Components</div>
<ul>
<li><a href="/components">Introduction</a></li>
<li><a href="/components/variable">Variable</a></li>
<li><a href="/components/display">Display</a></li>
</ul>
</li>
<li><a href="/svg">Diagrams</a></li>
<li><a href="/runtime">Runtime</a></li>
</ul>
</nav>
<article id="myArticle" class="centered">
<h1 id="welcome">Welcome to @curvenote/article</h1>
<r-outline class="popout" for="myArticle"></r-outline>
<p>This is a paragraph, kinda simple. <code>code</code></p>
<aside class="callout">Hello world</aside>
<r-scope name="display">
<h2>Display Variables</h2>
<r-var name="x" value="1"></r-var>
<r-var name="y" value="5"></r-var>
<r-var name="xSquared" :value="x * x" description="The square of x."></r-var>
<p>To display an element create an <code>r-display</code>, which will just render the named variable as text.</p>
<r-code language="html" compact><r-display name="x"></r-display></r-code>
<p>
This is a number that is dynamic: <r-display bind="x"></r-display>.<br>
Try setting the value of $x$ with the range input: <r-range bind="x" max="5"></r-range>
</p>
<p>
You can also <code>transform</code> the value of a variable before you format it.
For example, you might want to say that the admission to a park is <code>'free'</code> when the <r-action
:click="{x:0}">value == 0</r-action>.
</p>
<aside><p>The <code>:transform</code> uses a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator">Conditional Operator</a> from javascript.</p></aside>
<r-demo>
<p>
The park admission is
<r-display :value="x" :transform="(value > 0)? value : 'free'" format="$.2f"></r-display>.
</p>
</r-demo>
<p>
You can also use this <code>transform</code> to say that the park admission is
<r-dynamic bind="x"
:transform="['free','real cheap','cheap','costly','expensive','real expensive'][Math.min(Math.max(value,0),5)]"
max="5"></r-dynamic>.<br>
This is also quite useful if you want to use the transform to index into an array <r-dynamic bind="x"
:transform="['😍','😄','😊','😐','😒','😔'][Math.min(Math.max(value,0),5)]"
max="5"></r-dynamic>, in this case emoji array - but it could be numeric too!
</p>
<aside class="callout">
<p>
Properties of <code>r-display</code>:
<dl>
<dt><code>name</code></dt>
<dd>The variable to name to in the state.</dd>
<dt><code>format</code></dt>
<dd>A d3-format string. See the <a href="https://github.com/d3/d3-format" target="_blank">documentation</a>.</dd>
<dt><code>transform</code></dt>
<dd>Allows you to change or transform the value before formating: <code>format(transform(value))</code>. If the
value is a string after transformation, it will not be formatted.</dd>
</dl>
</p>
</aside>
</r-scope>
<div class="card-container">
<r-card class="flex-item" title="Variables" description="Reactive and variables and displays" img-src="/images/r-var.png" url="var"></r-card>
<r-card class="flex-item" title="Equations" description="Equations using KaTeX" img-src="/images/r-equation.gif" url="equation"></r-card>
<r-card class="flex-item" title="Charts" description="Reactive charts using d3" img-src="/images/r-chart.gif" url="chart"></r-card>
<r-card class="flex-item" title="Charts" description="Reactive charts using d3" img-src="/images/r-chart.gif" url="chart"></r-card>
<r-card class="flex-item" title="Charts" description="Reactive charts using d3" img-src="/images/r-chart.gif" url="chart"></r-card>
<r-card class="flex-item" title="Charts" description="Reactive charts using d3" img-src="/images/r-chart.gif" url="chart"></r-card>
</div>
<h2>There is code</h2>
<aside>The default aside happens, on the side!</aside>
<r-code language="python">
>>> import numpy as np
>>> a = np.arange(15).reshape(3, 5)
>>> a
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]])
</r-code>
<blockquote>
<p>I would have written a shorter letter, but I did not have the time.</p>
<footer>
<cite>Blaise Pascal</cite>
<time datetime="1656-12-04">December 4, 1656</time>
</footer>
</blockquote>
<h2>And Equations</h2>
<r-demo>
<script>
function prod(x, y) {
const prod = x * y;
return prod;
}
</script>
<r-var name="x" value="5"></r-var>
<r-var name="y" value="2"></r-var>
<r-var name="prod" :value="prod(x, y)"></r-var>
<p>
The product of
<r-dynamic bind="x"></r-dynamic>
and
<r-dynamic bind="y"></r-dynamic>
is
<r-display bind="prod"></r-display>
</p>
</r-demo>
<r-code language="javascript" copy>
</r-code>
<r-demo>
<r-var name="cookies" value="3" format=".4"></r-var>
<p>
When you eat
<r-dynamic bind="cookies" min="2" max="100"> cookies</r-dynamic>,
you consume
<r-display :value="cookies * 50" format=".0f" /></r-display>
calories.
</p>
</r-demo>
<r-demo>
<r-var name="index" value="1"></r-var>
<r-var name="MrTaylor"
:value="['f(x) \\approx f(a)', '\\frac {f^{\\prime}(a)}{1!} (x-a)', '\\frac{f^{\\prime\\prime}(a)}{2!} (x-a)^2', '\\frac{f^{(3)}(a)}{3!}(x-a)^3']">
</r-var>
Drag me to expand the Taylor Series:
<r-range bind="index" min="1" max="4"></r-range>
<r-equation :math="MrTaylor.slice(0, index).join(' + ') + ' + \\cdots'"></r-equation>
</r-demo>
<r-demo>
<r-equation>
x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}
</r-equation>
</r-demo>
<h2>And Demos</h2>
<r-svg-chart style="float: right" width="250" height="250" x-axis-location="origin" y-axis-location="origin" xlim="[-10,10]" ylim="[-10,10]">
<r-svg-eqn eqn="m*x + b" :listen="[m, b]"></r-svg-eqn>
<r-svg-node x="0" :y="b" :drag="{b: y}"></r-svg-node>
<r-svg-node x="5" :y="m*5 + b" :drag="{m: (y - b) / 5}"></r-svg-node>
</r-svg-chart>
<r-demo style="width: calc(100% - 250px)">
<r-var name="m" value="1"></r-var>
<r-var name="b" value="1"></r-var>
<p>$m$ = <r-range bind="m" step="0.1" min="-10" max="10"></r-range><r-display bind="m"></r-display></p>
<p>$b$ = <r-range bind="b" step="0.1" min="-10" max="10"></r-range><r-display bind="b"></r-display></p>
<r-equation aligned>
y &= m \times x + b \\
y &=
<r-display :value="m==-1 || m == 0 || m == 1? '' : m" format=".0f"></r-display>
<r-visible :visible="m == -1">-</r-visible>
<r-visible :visible="m !== 0">x</r-visible>
<r-display :value="b==0? '' : b" :format="m==0 ? '.0f' : '+.0f'">+1</r-display>
<r-visible :visible="m == 0 && b ==0">0</r-visible>
</r-equation>
</r-demo>
<r-scope name="radial">
<r-var name="a" value="1"></r-var>
<r-var name="b" value="1"></r-var>
<r-var name="cartesian" value="true" type="Boolean"></r-var>
<r-var name="showX" value="true" type="Boolean"></r-var>
<r-var name="radius" value="true" type="Boolean"></r-var>
<r-var name="r" :value="Math.sqrt(a*a + b*b)"></r-var>
<r-var name="theta" :value="Math.atan2(b, a) * 180 / Math.PI"></r-var>
<h3>Coordinate Transformation</h3>
<p>
A good example of this is <r-action :click="{cartesian: !cartesian}">changing</r-action> from a <r-action :click="{cartesian: false}">radial</r-action> coordinate system to <r-action :click="{cartesian: true}">Cartesian</r-action>.
</p>
<r-svg-chart style="float:right" xlim="[-5, 5]" ylim="[-5, 5]" height="300" width="300" x-axis-location="origin"
y-axis-location="origin">
<r-svg-path :visible="cartesian" :data="[[a,0], [a, b]]" :hover="{showX: true}" :stroke="showX ? 'red' : '#333'" strokeWidth="1.5"></r-svg-path>
<r-svg-path :visible="cartesian" :data="[[a, b], [0,b]]" :hover="{showX: false}" :stroke="!showX ? 'red' : '#333'" strokeWidth="1.5"></r-svg-path>
<r-svg-path :visible="!cartesian" :data="[[0,0], [a, b]]" :hover="{radius: true}" :stroke="radius ? 'red' : '#333'" strokeWidth="1.5"></r-svg-path>
<r-svg-eqn :visible="!cartesian && theta != 0" eqn="[Math.cos(t)*r, Math.sin(t)*r]" :domain="[0, theta * Math.PI / 180]" parameterize="t" :hover="{radius: false}" :stroke="!radius ? 'red' : '#333'" stroke="#333" strokeWidth="1.5"></r-svg-eqn>
<r-svg-node :x="a" :y="b" :drag="{a: x, b: y, cartesian: x > 0}"></r-svg-node>
</r-svg-chart>
<strong>Cartesian Coordinate System</strong>
<dl>
<dt>$x$</dt>
<dd>
<r-dynamic :value="a" :change="{a: value, cartesian: true, showX: true}" min="-5" :max="5" step="0.05"></r-dynamic>
</dd>
<dt>$y$</dt>
<dd>
<r-dynamic :value="b" :change="{b: value, cartesian: true, showX: false}" min="-5" :max="5" step="0.05"></r-dynamic>
</dd>
</dl>
<strong>Radial Coordinate System</strong>
<dl>
<dt>$r$</dt>
<dd>
<r-dynamic :value="Math.sqrt(a*a + b*b)" :change="{
a: value * Math.cos(Math.atan2(b, a)),
b: value * Math.sin(Math.atan2(b, a)),
cartesian: false, radius: true,
}" min="0.1" :max="5" step="0.05"></r-dynamic>
</dd>
<dt>$\theta$</dt>
<dd>
<r-dynamic :value="Math.atan2(b, a) * 180 / Math.PI" :change="{
a: Math.sqrt(a*a + b*b) * Math.cos(value * Math.PI / 180),
b: Math.sqrt(a*a + b*b) * Math.sin(value * Math.PI / 180),
cartesian: false, radius: false,
}" min="-180" :max="180" step="1" periodic="true">°</r-dynamic>
</dd>
</dl>
<r-visible :visible="cartesian && showX">
<strong style="text-decoration: underline;">Cartesian Update- $x$</strong>
<r-equation>
x = <r-display bind="a"></r-display>
</r-equation>
<r-code language="html">
<r-dynamic :value="x" :change="{x: value}"></r-dynamic>
</r-code>
</r-visible>
<r-visible :visible="cartesian && !showX">
<strong style="text-decoration: underline;">Cartesian Update - $y$</strong>
<r-equation>
y = <r-display bind="b"></r-display>
</r-equation>
<r-code language="html">
<r-dynamic :value="y" :change="{y: value}"></r-dynamic>
</r-code>
</r-visible>
<r-visible :visible="!cartesian && radius">
<strong>Radius Update</strong>
<r-equation aligned>
r &= \sqrt{x^2 + y^2} = <r-display bind="r"></r-display> \\
x &= r \cos(\operatorname{atan2}(y, x)) = <r-display bind="a"></r-display> \\
y &= r \sin(\operatorname{atan2}(y, x)) = <r-display bind="b"></r-display>
</r-equation>
<r-code language="html">
<r-dynamic :value="Math.sqrt(x*x + y*y)" :change="{
x: value * Math.cos(Math.atan2(y, x)),
y: value * Math.sin(Math.atan2(y, x))
}"></r-dynamic>
</r-code>
</r-visible>
<r-visible :visible="!cartesian && !radius">
<strong>Theta Update</strong>
<r-equation aligned>
\theta &= \operatorname{atan2}(y, x) = <r-display bind="theta"></r-display> \\
x &= \sqrt{x^2 + y^2} \cos( \theta ) = <r-display bind="a"></r-display> \\
y &= \sqrt{x^2 + y^2} \sin( \theta ) = <r-display bind="b"></r-display>
</r-equation>
<r-code language="html">
<r-dynamic :value="Math.atan2(y, x)" :change="{
x: Math.sqrt(x*x + y*y) * Math.cos(value),
y: Math.sqrt(x*x + y*y) * Math.sin(value)
}"></r-dynamic>
</r-code>
</r-visible>
</r-scope>
<r-scope name="sincos">
<r-var name="r" value="0.35"></r-var>
<r-var name="theta" value="0" format=".1f"></r-var>
<r-var name="xC" :value="Math.cos(theta)*r-0.5"></r-var>
<r-var name="yC" :value="Math.sin(theta)*r+0.5"></r-var>
<r-var name="sOrigin" value="false" type="Boolean"></r-var>
<r-var name="sRadius" value="false" type="Boolean"></r-var>
<r-var name="sAngle" value="false" type="Boolean"></r-var>
<r-var name="wR" value="1"></r-var>
<r-var name="wG" value="3"></r-var>
<r-var name="wB" value="1"></r-var>
<r-var name="wSin" value="3"></r-var>
<r-var name="wCos" value="3"></r-var>
<h3>Sin and Cos</h3>
<p>
In trigonometry, a
<r-action :hover="{wG:enter?8:3}"><strong style="color:green">unit circle</strong></r-action>
is the circle of
<r-action :hover="{sRadius:enter}"><strong style="color:#333">radius</strong></r-action>
one centered at the <r-action :hover="{sOrigin:enter}"><strong style="color:#333">origin</strong></r-action>
$(0, 0)$ in the Cartesian coordinate system. Let a
<r-action :hover="{sRadius:enter}"><strong style="color:#333">line</strong></r-action>
through the
<r-action :hover="{sOrigin:enter}"><strong style="color:#333">origin</strong></r-action>,
making an
<r-action :hover="{sAngle:enter}"><strong style="color:#333">angle</strong></r-action>,
of $\theta$=
<r-dynamic bind="theta" min="0" step="0.01" :max="Math.PI*2" periodic="true" :transform="value*180/Math.PI" after="º"></r-dynamic>
with the positive half of the x-axis, intersect the
<r-action :hover="{wG:enter?8:3}"><strong style="color:green">unit circle</strong></r-action>.
The
<r-action :hover="{wB:enter?3:1}"><strong style="color:blue">x-coordinates</strong></r-action>
and
<r-action :hover="{wR:enter?3:1}"><strong style="color:red">y-coordinates</strong></r-action>
of this point of intersection are equal to
<r-action :hover="{wCos:enter?8:3}"><strong style="color:blue">$\cos(\theta)$</strong></r-action>
and
<r-action :hover="{wSin:enter?8:3}"><strong style="color:red">$\sin(\theta)$</strong></r-action>,
respectively.
<a href="https://en.wikipedia.org/wiki/Sine#Unit_circle_definition" target="_blank">See Wikipedia</a>.
</p>
<r-demo>
<r-svg-chart xlim="[-1, 2]" ylim="[-1, 1]" height="400" width="600" x-axis-location="hidden" y-axis-location="hidden">
<!-- Create Axis -->
<r-svg-path :data="[[-1,0],[2, 0],[],[0, -1], [0, 1]]" stroke="#ddd" stroke-width="2"></r-svg-path>
<r-svg-path :data="[[-1, 0.5-r],[2, 0.5-r],[],[-1, 0.5], [2, 0.5],[],[-1, 0.5+r],[2, 0.5+r]]" stroke="#ddd" stroke-width="0.5"></r-svg-path>
<r-svg-path :data="[[ 0,-0.5-r],[2,-0.5-r],[],[ 0,-0.5], [2,-0.5],[],[ 0,-0.5+r],[2,-0.5+r]]" stroke="#ddd" stroke-width="0.5"></r-svg-path>
<r-svg-path :data="[[-0.5-r,1],[-0.5-r,0],[],[-0.5,1], [-0.5,0],[],[-0.5+r,1],[-0.5+r,0]]" stroke="#ddd" stroke-width="0.5"></r-svg-path>
<!-- Three equations for the bottom-left curve -->
<r-svg-eqn eqn="[-Math.cos(t)*(-0.5-r), -Math.sin(t)*(-0.5-r)]" parameterize="t" :domain="[Math.PI, Math.PI*1.5]" stroke="#ddd" stroke-width="0.5"></r-svg-eqn>
<r-svg-eqn eqn="[-Math.cos(t)/-2, -Math.sin(t)/-2]" parameterize="t" :domain="[Math.PI, Math.PI*1.5]" stroke="#ddd" stroke-width="0.5"></r-svg-eqn>
<r-svg-eqn eqn="[-Math.cos(t)*(-0.5+r), -Math.sin(t)*(-0.5+r)]" parameterize="t" :domain="[Math.PI, Math.PI*1.5]" stroke="#ddd" stroke-width="0.5"></r-svg-eqn>
<!-- Guidelines from the current point (xC,yC) -->
<r-svg-path :data="[[xC, yC], [0, yC]]" stroke="red" :stroke-width="wR"></r-svg-path>
<r-svg-path :data="[[xC, yC], [xC, 0]]" stroke="blue" :stroke-width="wB"></r-svg-path>
<r-svg-eqn eqn="[-Math.cos(t)*xC, -Math.sin(t)*xC]" parameterize="t" :domain="[Math.PI, Math.PI*1.5]" stroke="blue" :stroke-width="wB"></r-svg-eqn>
<!-- Text labels -->
<r-svg-text text="sin(θ)" x="1.75" :y=" 0.43-r" fill="red"></r-svg-text>
<r-svg-text text="cos(θ)" x="1.75" :y="-0.57-r" fill="blue"></r-svg-text>
<!-- Origin, radius and angle: default is hidden -->
<r-svg-circle x="-0.5" y="0.5" :visible="sOrigin" fill="#333"></r-svg-circle>
<r-svg-path :data="[[-0.5, 0.5], [xC,yC]]" :visible="sRadius" stroke="#333" stroke-width="3"></r-svg-path>
<r-svg-eqn eqn="[Math.cos(t)*0.1 - 0.5, Math.sin(t)*0.1 + 0.5]" parameterize="t" :domain="[0, theta]" :visible="sAngle" stroke="#333" stroke-width="3"></r-svg-eqn>
<r-svg-path :data="[[xC,yC], [-0.5, 0.5], [-0.5 + r,0.5]]" :visible="sAngle" stroke="#333" stroke-width="2"></r-svg-path>
<!-- A circle! -->
<r-svg-eqn eqn="[Math.cos(t)*r-0.5, Math.sin(t)*r+0.5]" parameterize="t" :domain="[0, Math.PI*2]" stroke="green" :stroke-width="wG"></r-svg-eqn>
<!-- Offset sin and cos waves -->
<r-svg-eqn eqn="Math.sin(x* Math.PI+theta)*r + 0.5" domain="[0, 2]" stroke="red" :stroke-width="wSin"></r-svg-eqn>
<r-svg-eqn eqn="Math.cos(x* Math.PI+theta)*r - 0.5" domain="[0, 2]" stroke="blue" :stroke-width="wCos"></r-svg-eqn>
<!-- A drag node to change the offset -->
<r-svg-node :x="xC" :y="yC" fill="#333" :drag="{theta: (Math.PI * 2 + Math.atan2(y-0.5, x+0.5)) % (Math.PI * 2)}"></r-svg-node>
</r-svg-chart>
</r-demo>
</r-scope>
</article>
</body>
</html>