build/THREE.Terrain.js
function deposit(g, i, j, xl, displacement) {
        var currentKey = j * xl + i;
        // Pick a random neighbor.
        for (var k = 0; k < 3; k++) {
            var r = Math.floor(Math.random() * 8);
            switch (r) {
                case 0: i++; break;
                case 1: i--; break;
                case 2: j++; break;
                case 3: j--; break;
                case 4: i++; j++; break;
                case 5: i++; j--; break;
                case 6: i--; j++; break;
                case 7: i--; j--; break;
            }
            var neighborKey = j * xl + i;
            // If the neighbor is lower, move the particle to that neighbor and re-evaluate.
            if (typeof g[neighborKey] !== 'undefined') {
                if (g[neighborKey].z < g[currentKey].z) {
                    deposit(g, i, j, xl, displacement);
                    return;
                }
            }
            // Deposit some particles on the edge.
            else if (Math.random() < 0.2) {
                g[currentKey].z += displacement;
                return;
            }
        }
        g[currentKey].z += displacement;
    }
function deposit(g, i, j, xl, displacement) {
        var currentKey = j * xl + i;
        // Pick a random neighbor.
        for (var k = 0; k < 3; k++) {
            var r = Math.floor(Math.random() * 8);
            switch (r) {
                case 0: i++; break;
                case 1: i--; break;
                case 2: j++; break;
                case 3: j--; break;
                case 4: i++; j++; break;
                case 5: i++; j--; break;
                case 6: i--; j++; break;
                case 7: i--; j--; break;
            }
            var neighborKey = j * xl + i;
            // If the neighbor is lower, move the particle to that neighbor and re-evaluate.
            if (typeof g[neighborKey] !== 'undefined') {
                if (g[neighborKey].z < g[currentKey].z) {
                    deposit(g, i, j, xl, displacement);
                    return;
                }
            }
            // Deposit some particles on the edge.
            else if (Math.random() < 0.2) {
                g[currentKey].z += displacement;
                return;
            }
        }
        g[currentKey].z += displacement;
    }
function deposit ( g , i , j , xl , displacement ) { var currentKey = j * xl + i ; // Pick a random neighbor. for ( var k = 0 ; k < 3 ; k ++ ) { var r = Math . floor ( Math . random ( ) * 8 ) ; switch ( r ) { case 0 : i ++ ; break ; case 1 : i -- ; break ; case 2 : j ++ ; break ; case 3 : j -- ; break ; case 4 : i ++ ; j ++ ; break ; case 5 : i ++ ; j -- ; break ; case 6 : i -- ; j ++ ; break ; case 7 : i -- ; j -- ; break ; } var neighborKey = j * xl + i ; // If the neighbor is lower, move the particle to that neighbor and re-evaluate. if ( typeof g [ neighborKey ] !== 'undefined' ) { if ( g [ neighborKey ] . z < g [ currentKey ] . z ) { deposit ( g , i , j , xl , displacement ) ; return ; } } // Deposit some particles on the edge. else if ( Math . random ( ) < 0.2 ) { g [ currentKey ] . z += displacement ; return ; } } g [ currentKey ] . z += displacement ; }
Deposit a particle at a vertex.
Deposit a particle at a vertex .