@@ -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