Skip to content

Commit 6da32ca

Browse files
committed
fix: analytic
1 parent 5004a36 commit 6da32ca

File tree

2 files changed

+41
-24
lines changed

2 files changed

+41
-24
lines changed

demo/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<script type="text/javascript" src="./lib/jquery.pubsub.js"></script>
1414
<script type="text/javascript" src="./lib/fd-slider/fd-slider.js"></script>
1515
<script type="text/javascript" src="../lib/terrain.js"></script>
16-
<script type="text/javascript" src="./main.js"></script>
1716
</head>
1817
<body>
1918
<div id="sidebar">
@@ -60,6 +59,7 @@ <h1 id="title">Fractal Terrain Generator</h1>
6059
<div id="container"></div>
6160

6261
<a href="https://github.com/qiao/fractal-terrain-generator"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://a248.e.akamai.net/assets.github.com/img/71eeaab9d563c2b3c590319b398dd35683265e85/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677261795f3664366436642e706e67" alt="Fork me on GitHub"></img></a>
62+
<script type="text/javascript" src="./main.js"></script>
6363
<script type="text/javascript">
6464
$(function() {
6565
var _gaq = _gaq || [];

demo/main.js

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -311,29 +311,49 @@ var TerrainView = (function() {
311311

312312
})();
313313

314-
$(document).ready(function() {
315-
316-
// create slider for the size selector
317-
fdSlider.createSlider({
318-
inp:document.getElementById("opt-size"),
319-
animation:"tween",
320-
hideInput:true,
321-
callbacks: {
322-
change: [update]
323-
}
324-
});
314+
var TerrainController = (function() {
315+
325316

326317
var model = TerrainModel;
327318
var view = TerrainView;
328319

329-
view.init('#container');
330-
//view.drawCoordinate(new THREE.Vector3(0, 0, 0), 300);
331-
view.animate(30);
320+
function init() {
321+
// replace the builtin Math.random method with the one provided by RandomPool
322+
RandomPool.hook();
323+
324+
initUI();
325+
animate();
326+
bindEvents();
327+
328+
update();
329+
}
330+
331+
function initUI() {
332+
// create slider for the size selector
333+
fdSlider.createSlider({
334+
inp:document.getElementById("opt-size"),
335+
animation:"tween",
336+
hideInput:true,
337+
callbacks: {
338+
change: [update]
339+
}
340+
});
341+
342+
view.init('#container');
343+
}
332344

333-
$.subscribe('terrain-update', view.update);
345+
function animate() {
346+
view.animate(30);
347+
}
334348

335-
// replace the builtin Math.random method with the one provided by RandomPool
336-
RandomPool.hook();
349+
function bindEvents() {
350+
$.subscribe('terrain-update', view.update);
351+
352+
$('#new').on('click', function() { reset(); return false; });
353+
$('#opt-size').on('change', update);
354+
$('#opt-smoothness').on('change', update);
355+
$('#opt-z').on('change', updateZ);
356+
}
337357

338358
function reset() {
339359
RandomPool.reset();
@@ -355,11 +375,8 @@ $(document).ready(function() {
355375
model.updateZ(zScale);
356376
}
357377

358-
$('#new').on('click', function() { reset(); return false; });
359-
$('#opt-size').on('change', update);
360-
$('#opt-smoothness').on('change', update);
361-
$('#opt-z').on('change', updateZ);
378+
return { init: init };
362379

363-
update();
380+
})();
364381

365-
});
382+
TerrainController.init();

0 commit comments

Comments
 (0)