forked from worrydream/Tangle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
274 lines (206 loc) · 12.6 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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<base target="_top">
<title>Tangle: a JavaScript library for reactive documents</title>
<!-- stylesheets -->
<link href='http://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="Fonts/Insolent/stylesheet.css" type="text/css">
<link rel="stylesheet" href="Fonts/BorisBlackBloxx/stylesheet.css" type="text/css">
<link rel="stylesheet" href="style.css" type="text/css">
<!-- Tangle -->
<script type="text/javascript" src="Tangle.js"></script>
<!-- TangleKit -->
<link rel="stylesheet" href="TangleKit/TangleKit.css" type="text/css">
<script type="text/javascript" src="TangleKit/mootools.js"></script>
<script type="text/javascript" src="TangleKit/sprintf.js"></script>
<script type="text/javascript" src="TangleKit/BVTouchable.js"></script>
<script type="text/javascript" src="TangleKit/TangleKit.js"></script>
<!-- examples -->
<script type="text/javascript" src="Examples/CookieExample.js"></script>
<script type="text/javascript" src="Examples/ParkExample.js"></script>
<script type="text/javascript" src="Examples/FilterExample.js"></script>
<script type="text/javascript" src="Examples/FilterExampleDSP.js"></script>
</head>
<body>
<div id="everything">
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- header -->
<div id="header">
<h1><a href="./">tangle</a></h1>
<h3>explorable explanations made easy</h3>
<div class="menu">
<a href="guide.html">Getting Started</a>
<a href="reference.html">API Reference</a>
<a href="download.html">Download</a>
<a href="https://groups.google.com/group/tangle-talk/topics">Discuss</a>
</div>
</div> <!-- header -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- body -->
<div id="body">
<p>Tangle is a JavaScript library for creating <b>reactive documents</b>. Your readers can interactively explore
possibilities, play with parameters, and see the document update immediately. Tangle is super-simple and easy to learn.</p>
<p>This is a simple reactive document.</p>
<div id="cookieExample" class="example">
<div class="exampleTop"></div>
<div class="exampleCenter">
<p>When you eat <span data-var="cookies" class="TKAdjustableNumber" data-min="2" data-max="100"> cookies</span>, you consume <span data-var="calories"></span> calories.</p>
</div>
<div class="exampleBottom"></div>
</div>
<p>This is the HTML for that example.</p>
<div class="example">
<div class="exampleTop"></div>
<div class="exampleCenter">
<code>When you eat <b><span data-var="cookies" class="TKAdjustableNumber"></b> cookies<b></span></b>,<br>
you consume <b><span data-var="calories"></b> calories<b></span></b>.</code>
</div>
<div class="exampleBottom"></div>
</div>
<p>And this is the JavaScript.</p>
<div class="example">
<div class="exampleTop"></div>
<div class="exampleCenter">
<code>var tangle = new Tangle(document, {<br>
<b>initialize:</b> function () { <b>this.cookies = 3;</b> },<br>
<b>update:</b> function () { <b>this.calories = this.cookies * 50;</b> }<br>
});</code>
</div>
<div class="exampleBottom"></div>
</div>
<p>Write your document with HTML and CSS, as you normally would. Use special HTML attributes to indicate <b>variables</b>. Write a little JavaScript to specify how your variables are calculated. Tangle ties it all together.</p>
<p style="text-align:center; margin-top:30px;">* * *</p>
<p style="">Try out some examples.</p>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- park example -->
<div class="example">
<div class="exampleTop"></div>
<div class="exampleCenter">
<div id="parkExample">
<h5>Proposition 21: Vehicle License Fee for State Parks</h5>
<h6>The way it is now:</h6>
<p>California has <span data-var="parkCount"></span> state parks, including state beaches and historic parks.
The current $<span data-var="oldBudget" data-format="e6"></span> million budget is insufficient to maintain these parks,
and <span data-var="oldClosedParkCount"></span> parks will be shut down at least part-time.
Most parks charge <span data-var="oldAdmission" data-format="dollars"></span> per vehicle for admission.</p>
<h6>What Prop 21 would do:</h6>
<p>Proposes to charge car owners an extra $18 on their annual registration bill, to go into the state park fund. Cars that pay the charge would have free park admission.</p>
<h6>Analysis:</h6>
<p>Suppose that an extra
<span data-var="tax" data-format="$%d" class="TKAdjustableNumber" data-min="0" data-max="50"></span> was charged to
<span data-var="percentCompliance" class="TKAdjustableNumber" data-min="0" data-max="100" data-step="5">%</span> of
<span data-var="isTaxPerVehicle" class="TKToggle TKSwitch"><span>California taxpayers</span><span>vehicle registrations</span></span>.
Park admission would be <span data-var="newAdmission" data-format="free" class="TKAdjustableNumber" data-min="0" data-max="25"></span> for
<span data-var="newAdmissionAppliesToEveryone" class="TKToggle TKSwitch"><span>those who paid the charge</span><span>everyone</span></span>.
</p>
<p>This would <span data-var="deltaBudget" class="TKSwitchPositiveNegative"><span>collect an extra</span><span>lose</span></span>
$<span data-var="deltaBudget" data-format="abs_e6"></span> million
($<span data-var="taxCollected" data-format="e6"></span> million from the tax,
<span data-var="deltaRevenue" class="TKSwitchPositiveNegative"><span>plus</span><span>minus</span></span>
$<span data-var="deltaRevenue" data-format="abs_e6"></span> million
<span data-var="deltaRevenue" class="TKSwitchPositiveNegative"><span>additional</span><span>lost</span></span> revenue from admission)
for a total state park budget of $<span data-var="budget" data-format="e6"></span> million.
<span data-var="scenarioIndex" class="TKSwitch">
<span>This is not sufficient to maintain the parks, and
<span data-var="closedParkCount"></span> parks would be shut down at least part-time.</span>
<span>This is sufficient to maintain the parks in their current state, but not fund
a program to bring safety and cleanliness up to acceptable standards.</span>
<span>This is sufficient to maintain the parks in their current state, plus fund a program to
bring safety and cleanliness up to acceptable standards over the next
<span data-var="restorationTime"></span> years.</span>
<span>This is sufficient to maintain the parks and bring safety and cleanliness up to acceptable standards,
leaving a $<span data-var="surplus" data-format="e6"></span> million per year surplus.</span>
</span>
</p>
<p>Park attendance would
<span data-var="deltaVisitorCount" class="TKSwitchPositiveNegative"><span>rise</span><span>fall</span></span> by
<span data-var="relativeVisitorCount" data-format="percent"></span>, to
<span data-var="newVisitorCount" data-format="e6"></span> million visits each year.</p>
</div>
</div>
<div class="exampleBottom"></div>
</div>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- filter example -->
<div class="example">
<div class="exampleTop"></div>
<div class="exampleCenter">
<div id="filterExample">
<p>Below is a simplified digital adaptation of the analog state variable filter.</p>
<p class="filterSidebar">This topology is particularly useful for embedded audio processing, because <i>F<sub>c</sub></i> (cutoff frequency) and <i>Q</i> (resonance) are controlled by independent coefficients, <i>k<sub>f</sub></i> and <i>k<sub>q</sub></i>. (With most filters, the coefficients are functions of both parameters, which precludes pre-calculated lookup tables.)</p>
<div class="filterIndent">
<canvas class="FilterStepPlot showOnDrag" data-var="kf kq" style="left:-50px;top:-10px;" width="48" height="64"></canvas>
<canvas class="FilterTimePlot showOnDrag" data-var="kf kq" style="left:324px;top:-10px;" width="128" height="64"></canvas>
<div class="filterDynamicLabel showOnDrag" data-var="kf" data-format="p3" style="left:70px; top:4px;"></div>
<div class="filterDynamicLabel showOnDrag" data-var="kf" data-format="p3" style="left:180px; top:4px;"></div>
<div class="filterDynamicLabel showOnDrag" data-var="kq" data-format="neg_p3" style="left:71px; top:48px;"></div>
<img src="Images/FilterSchematic.png" width="325" height="110">
</div>
<p>The coefficients and transfer function are:</p>
<div class="filterIndent">
<div class="filterDynamicCoef showOnDrag" style="left:34px;top:0px;width:70px;height:35px;">
<div style="position:relative;top:9px;left:2px;"><span data-var="kf" data-format="p3"></span></div>
</div>
<div class="filterDynamicCoef showOnDrag" style="left:141px;top:0px;width:40px;height:35px;">
<div style="position:relative;top:9px;left:2px;"><span data-var="kq" data-format="p3"></span></div>
</div>
<div class="filterDynamicCoef showOnDrag" style="left:141px;top:46px;width:40px;height:16px;">
<div style="position:relative;top:0px;left:2px;"><span data-var="b0" data-format="p3"></span></div>
</div>
<div class="filterDynamicCoef showOnDrag" style="left:72px;top:67px;width:91px;height:16px;">
<div style="position:relative;top:0px;left:58px;"><span data-var="a1neg" data-format="p3"></span></div>
</div>
<div class="filterDynamicCoef showOnDrag" style="left:196px;top:67px;width:56px;height:16px;">
<div style="position:relative;top:0px;left:22px;"><span data-var="a2" data-format="p3"></span></div>
</div>
<canvas class="FilterPolePlot showOnDrag" data-var="pole1Real pole1Imag pole2Real pole2Imag"
width="160" height="160" style="left:276px;top:-36px;"></canvas>
<img src="Images/FilterEquations.png" width="281" height="92">
</div>
<p>Some example frequency responses:</p>
<div class="filterIndent" style="position:relative;">
<div class="filterFreqPlot">
<canvas class="FilterFreqPlot" data-var="kf1 kq1" width="256" height="128"></canvas>
<div class="FilterKnob" data-var="fc1 q1"></div>
<div class="filterParams" style="left:5px;top:0px;">
<i>F<sub>c</sub></i> = <span data-var="fc1" data-format="freq"></span><br>
<i>Q</i> = <span data-var="q1" data-format="p2"></span>
</div>
<div class="filterUnstable TKIf" data-var="unstable1">Unstable</div>
</div>
<div class="filterFreqPlot" style="position:absolute; top:0px; left:274px;">
<canvas class="FilterFreqPlot" data-var="kf2 kq2" width="256" height="128"></canvas>
<div class="FilterKnob" data-var="fc2 q2"></div>
<div class="filterParams" style="left:5px;top:0px;">
<i>F<sub>c</sub></i> = <span data-var="fc2" data-format="freq"></span><br>
<i>Q</i> = <span data-var="q2" data-format="p2"></span>
</div>
<div class="filterUnstable TKIf" data-var="unstable2">Unstable</div>
</div>
</div>
</div>
</div>
<div class="exampleBottom"></div>
</div>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- bottom -->
<p>For a more extensive example, see <a href="http://worrydream.com/TenBrighterIdeas/">Ten Brighter Ideas</a>.</p>
<p>For the motivation and philosophy behind reactive documents, see <a href="http://worrydream.com/ExplorableExplanations/">Explorable Explanations</a>.</p>
<p>Or learn how to <a href="guide.html">get started with Tangle</a>.</p>
</div> <!-- body -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- footer -->
<div id="footer">
<div id="footerShadow"></div>
<div class="author"><a href="http://worrydream.com/">Bret Victor</a></div>
<div class="menu">
<a href="guide.html">Getting Started</a>
<a href="reference.html">API Reference</a>
<a href="download.html">Download</a>
<a href="https://groups.google.com/group/tangle-talk/topics">Discuss</a>
</div>
</div> <!-- footer -->
</div> <!-- everything -->
</body></html>