/
index.html
380 lines (331 loc) · 15.1 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
373
374
375
376
377
378
379
380
<!doctype html>
<html lang="en">
<head>
<meta property="og:image" content="favicon.ico"/>
<meta charset="utf-8">
<title>lsys</title>
<link href="css/normalize.css" rel="stylesheet" type="text/css"/>
<link href="css/forkme.css" rel="stylesheet" type="text/css"/>
<link href="css/fontello.css" rel="stylesheet" type="text/css"/>
<link href="css/animation.css" rel="stylesheet" type="text/css"/>
<link href="css/introjs.min.css" rel=" stylesheet" type="text/css"/>
<link href="sass/test.css" rel="stylesheet" type="text/css"/>
<!-- google analytics -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-35201182-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body class="bg-slategray">
<ol id="tour" style="display:none">
<li data-element="#helpTrigger">loading<!-- hidden step, to allow me to hook into callbacks - there aren't any useful ones on the first step... --></li>
<li data-element="#helpTrigger">
<p>Welcome to lsys - the brainchild of a <a href="http://benvan.co.uk">curious programmer</a> with questionable taste in design.</p>
<p>The pattern on the right is an <a href="https://en.wikipedia.org/wiki/L-system">l-system</a>, and it's interactive.</p>
<a onclick="window.goToStep(3);" href="javascript:void(0);" data-trigger="tour" class="introjs-button wide">
Er.. Ok. What the hell?
</a>
<a onclick="window.goToStep(13);" href="javascript:void(0);" data-trigger="syntax" class="introjs-button wide">
Yeah, yeah, yeah.<br/>Just show me the syntax.
</a>
</li>
<!-- tour bit -->
<li data-element=".drawing-pad" data-position="bottom" data-overlay="off">
<p>Click and drag!</p>
</li>
<li data-element=".drawing-pad" data-position="bottom">
<p>As you drag your mouse, you change the parameters of the system, which then gets redrawn.</p>
</li>
<li data-element="#control-set">
<p>This set of controls describes (entirely) what you will see on the right</p>
</li>
<li data-element="#rules-row">
<p>This is the most important part: The set of rules that defines the shape of the system</p>
<p>The rules are used to generate a sequence of drawing instructions. For example, 'F' means 'draw forwards', and '+' means rotate right.</p>
<p>By generating long strings of instructions, we can make some pretty crazy patterns</p>
</li>
<li data-element="#rules-row">
<p>Let's try something super simple: a square</p>
</li>
<li data-element="#rules-row" data-example="square">
<p>We've defined a rule, called S, for "square". It really doesn't matter what we call it, but it must be precisely one character</p>
<p>After the colon, we've defined what 'S' means - it means draw forwards, then rotate right, four times in a row</p>
<p>But we could describe this another way:</p>
</li>
<li data-element="#rules-container" data-example="square-recursive">
<p>Instead, let's make the S rule recursive. Now, we draw forwards, rotate right, then do 'S' again.</p>
<p>We do this 4 times, since that's the value of the 'levels' input field</p>
</li>
<li data-element="#rules-container" data-example="spirograph">
<p>Let's get more interesting:</p>
<p>We define a new rule A, which does a S(quare), then rotates right, and does an A again. The [brackets] surrounding the S mean "remember where you are, do an S, return to where you were".</p>
<p>We've also bumped up the levels to 50. Try dragging around and see what happens! Notice that you're changing the value of 'angle' up above, which is what we rotate by when we see a '+' instruction.</p>
</li>
<li data-element="#rules-container">
<p>The system's parameters are also sync'd automatically with the url - meaning you can share systems by pasting the url somewhere.</p>
<p>Also - since systems are just urls, your browsers back button works the way you would expect it to :)</p>
</li>
<li data-element=".elem" data-position="left">
<p>Take a look at some of the examples here (you can scroll down!)</p>
</li>
<!-- syntax bit -->
<li data-element=".icon-help-circled" data-overlay='off'>
<p>Here's the list of available symbols (so far)</p>
<table class="table" >
<thead>
<tr>
<th style="width:70px;">symbol</th>
<th>meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td>F</td>
<td>draw forwards by [size]</td>
</tr>
<tr>
<td>+ / -</td>
<td>rotate by +/-[angle]</td>
</tr>
<tr>
<td>> / <</td>
<td>increase/decrease [size] by [size-growth]</td>
</tr>
<tr>
<td>) / (</td>
<td>increase / decrease [angle] by [angle-growth]</td>
</tr>
<tr>
<td>[ , ]</td>
<td>push / pop state
</td>
</tr>
<tr>
<td>!</td>
<td>negate [angle]</td>
</tr>
<tr>
<td>|</td>
<td>increment [angle] by 180°</td>
</tr>
</tbody>
</table>
<p>Other than that, it's worth mentioning the mouse controls:</p>
</li>
<li data-element="#offsets-container">
<p>Ctrl-click (or cmd-click) will translate (move) the system around</p>
<p>Rotation is done manually, using the input field on the right</p>
</li>
<li data-element="#controls-container ul.control-row:nth-child(3)">
<p>Dragging left-right affects angle values, up-down affects angle growth</p>
</li>
<li data-element="#controls-container ul.control-row:nth-child(2)">
<p>Hold alt and drag to adjust size parameters</p>
<p>Here, up-down adjusts scale, and left-right adjusts size growth</p>
</li>
<li data-element="#helpTrigger">
That's it! Whew!
</li>
</ol>
<div class="container-left">
<div class="header">
<a class="site" href="http://benvan.co.uk/lsys"><img src="img/logo3.png"><span>lsys</span></a>
<div class="actions">
<a id="helpTrigger" href="#">
<i class="icon-help"></i>
</a>
</div>
</div>
<div class="controls">
<ul id="control-set">
<li class="section">offsets</li>
<li class="group" id="offsets-container">
<ul class="labels">
<li>x</li><li>y</li><li>rotation</li>
</ul>
<!-- offsets be here! -->
</li>
<li class="section">variables</li>
<li class="group" id="controls-container">
<ul class="labels pair">
<li>value</li><!--
--><li>growth</li>
</ul>
<!-- controls be here! -->
</li>
<li class="section">mouse sensitivities</li>
<li class="group" id="sensitivities-container">
<ul class="labels pair">
<li>value</li><!--
--><li>growth</li>
</ul>
<!-- sensitivities be here! -->
</li>
<li class="section">
system
<i id="syntaxTrigger" class="icon-help-circled"></i>
</li>
<li class="group" id="rules-container">
<ul class="control-row half">
<li class="label">levels</li><!--
--><li><input id="iterations" type="text" required ></li>
</ul>
<ul class="control-row" id="rules-row">
<li class="label">rules</li><!--
--><li><textarea id="rules" rows="12"></textarea></li>
</ul>
<div class="recalculate">
<button class='recalculating'>
<span class="layer progress"></span>
<span class="text-recalculate">recalculate</span>
<span class="text-cancel">cancel <i class="icon-spin4"></i></span>
<span class="layer sheen"></span>
</button>
</div>
</li>
</ul>
</div>
</div>
<div class="container-bottom bg-slategray">
<footer class="ticker">
<ul class="elems"></ul>
</footer>
<div class="fade"></div>
</div>
<div class="container-right">
<div class="drawing-pad">
<div id="drawingContainer">
<canvas id="c1"></canvas>
<canvas id="c2"></canvas>
<canvas id="c3"></canvas>
<canvas id="c0"></canvas>
</div>
<div id="systemInfo" class="system-info blue">
<div class="system-name" >
<input type="text" id="system-name" value="click-and-drag!"/>
</div>
<div class="actions">
<a class="export tooltip" href="#" title="download png"><i class="icon-download"></i></a><!--
--><a href="#" class="tooltip" id="link" title="link" onclick="return false;"><i class="icon icon-link"></i><input readonly /></a><!--
--><a href="#" class="facebook" title="share on facebook" data-params="width=626,height=436" data-base="https://www.facebook.com/sharer/sharer.php?u="><i class="icon icon-facebook"></i></a><!--
--><a href="#" class="twitter" title="share on twitter" data-base="http://twitter.com/share?url="><i class="icon icon-twitter"></i></a><!--
--><a href="#" class="gplus" title="share on google+" data-base="https://plus.google.com/share?url="><i class="icon icon-gplus"></i></a>
</div>
</div>
</div>
<div class="github-fork-ribbon-wrapper fm-left">
<div class="github-fork-ribbon">
<a href="https://github.com/benvan/lsys">Fork me on GitHub</a>
</div>
</div>
</div>
<script type="text/javascript" src="js/underscore.js"></script>
<script type="text/javascript" src="js/jquery-1.8.1.js"></script>
<script type="text/javascript" src="js/system-ticker.js"></script>
<script type="text/javascript" src="js/generated/util.js"></script>
<script type="text/javascript" src="js/generated/controls.js"></script>
<script type="text/javascript" src="js/generated/lsystem.js"></script>
<script type="text/javascript" src="js/generated/compilation.js"></script>
<script type="text/javascript" src="js/generated/rendering.js"></script>
<script type="text/javascript" src="js/generated/manager.js"></script>
<script type="text/javascript">
var manager; // Don't judge. I want to get ahold of it in the console!
$(document).ready(function () {
$(".elems").ticker("ticker.json");
manager = new AppManager(
Util.control("drawingContainer"),
Util.map({
params: 'controls-container',
offsets: 'offsets-container',
sensitivities: 'sensitivities-container',
iterations: 'iterations',
rules: 'rules',
name: 'system-name'
}, Util.control)
);
var syncLocationQuiet = _.debounce( _.bind(manager.syncLocationQuiet, manager) ,300);
var sync = function(){
return manager.recalculate().pipe(syncLocationQuiet);
};
var $recalculateButton = $('.recalculate button');
$recalculateButton.click(function(){
if (manager.isRecalculating()) manager.systemManager.compiler.halt(); else sync();
});
// perhaps I should just make the promise available at this point.. gah.
manager.beforeRecalculate = function(){
$recalculateButton.addClass("recalculating");
setTimeout(function(){
if(manager.isRecalculating()) $recalculateButton.fadeIn(100);
},200)
};
manager.afterRecalculate = function(){
$recalculateButton.fadeOut(100, function(){
$recalculateButton.removeClass("recalculating");
});
};
manager.onRecalculateFail = function(){
$recalculateButton.removeClass("recalculating");
};
manager.onRecalculateProgress = function(progress){
$recalculateButton.find(".progress").width(progress*100+"%")
};
Util.enhanceAndStretchCanviiInContainer(Util.control("drawingContainer"));
$(window).resize(function(){
clearTimeout(window.resizeTimer);
window.resizeTimer = setTimeout(function(){
manager.prepareContainer();
manager.draw();
},50);
});
$('#rules,#iterations').on('input', function(){
$recalculateButton.fadeIn(100);
}).on('keydown', function(evt){
// enter key + any modifier -> update system
if (evt.keyCode == 13 && (evt.shiftKey || evt.metaKey || evt.ctrlKey || evt.altKey)){
$recalculateButton.click();
return false;
}
});
// open/close link button
$('#link').click(function(){
$(this).toggleClass('open');
$(this).find('input').val(location.href).select();
return false;
}).mouseleave(function(){
$(this).removeClass('open');
});
//bind sharing icons
$('[data-base]').click(function(){
window.open($(this).data('base') + encodeURIComponent(location.href), 'share on ' + $(this).attr('title'), $(this).data('params') || 'height=300,width=550,resizable=1');
return false;
});
$('a.export').click(function(){
manager.exportToPng();
return false;
});
setTimeout(function(){
manager.start().always(function(){
//this is kinda naughty... but I'd rather refactor Controls first than fudge this in otherwise
var syncIfNotEmpty = function(ev){
if (ev.target.value) sync()
};
$("#controls-container,#offsets-container").find("[data-param]").on("input", syncIfNotEmpty );
$("#sensitivities-container").find("[data-param]").on("input", syncIfNotEmpty );
$("#system-name").on("input", sync );
$("#rules").on("input", sync);
$("#iterations").on("input", syncIfNotEmpty);
$(".controls").addClass('validation-enabled');
});
},0);
});
</script>
<script src="js/intro.min.js"></script>
<script src="js/lsys-intro.js"></script>
</body>
</html>